-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfractol.c
75 lines (68 loc) · 2.12 KB
/
fractol.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmouhiid <mmouhiid@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/20 03:40:33 by mmouhiid #+# #+# */
/* Updated: 2023/12/24 05:58:31 by mmouhiid ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static void render_fractor_helper(t_program *program,
long double x, long double y)
{
opt_mlx_pixel_put(program->img, x, y,
generate_color(
program,
scale(x, WIN_WIDTH, program->left_x, program->right_x),
scale(y, WIN_HEIGHT, program->top_y, program->bottom_y)));
}
int render_fractor(t_program *program)
{
long double x;
long double y;
y = 0;
while (y < WIN_HEIGHT)
{
x = 0;
while (x < WIN_WIDTH)
{
render_fractor_helper(program, x, y);
x++;
}
y++;
}
mlx_put_image_to_window(program->mlx,
program->win, program->img->img, 0, 0);
return (0);
}
void fract_handler(char **argv)
{
t_program *program;
program = (t_program *)malloc(sizeof(t_program));
if (!program)
exit_handler(program);
program->img = (t_image *)malloc(sizeof(t_image));
if (!program->img)
exit_handler(program);
fractol_init(program, argv);
render_fractor(program);
mlx_loop(program->mlx);
}
int main(int argc, char **argv)
{
if ((argc == 2 && !ft_strcmp("mandelbrot", argv[1]))
|| (argc == 4 && !ft_strcmp("julia", argv[1])
&& is_valid_double(argv[2])
&& is_valid_double(argv[3]))
|| (argc == 2 && !ft_strcmp("burningship", argv[1])))
fract_handler(argv);
else
{
ft_putstr_fd(ERROR_MSG, 2);
exit(1);
}
return (0);
}