-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmandelbrot.c
More file actions
69 lines (64 loc) · 2.26 KB
/
mandelbrot.c
File metadata and controls
69 lines (64 loc) · 2.26 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mandelbrot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ymassiou <ymassiou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:02:25 by ymassiou #+# #+# */
/* Updated: 2024/02/14 15:11:02 by ymassiou ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void render_to_window_mandelbrot(int x, int y, t_fractal *fractal)
{
int i;
int red;
int green;
int blue;
int color;
while (++y < WIDTH)
{
x = -1;
while (++x < HEIGHT)
{
i = mandelbrot_study(x, y, fractal);
if (i == fractal->iter_max)
my_mlx_pixel_put(fractal, x, y, 0x000000);
else
{
red = (i * 1 * fractal->iter) % 255;
green = (i * 3 * fractal->iter) % 255;
blue = (i * 5 * fractal->iter) % 255;
color = (red << 16) | (green << 8) | blue;
my_mlx_pixel_put(fractal, x, y, color);
}
}
}
mlx_put_image_to_window(fractal->init, fractal->window, fractal->img, 0, 0);
}
int mandelbrot_study(double x, double y, t_fractal *fractal)
{
double tmp_real;
int i;
i = 0;
if (fractal->iter_max > 200 || fractal->iter_max < 0)
fractal->iter_max = 200;
fractal->z.x = 0.0;
fractal->z.y = 0.0;
fractal->c.x = scale_it(x, fractal->start.x, fractal->end.x, WIDTH - 1);
fractal->c.x += fractal->offset.x;
fractal->c.y = scale_it(y, fractal->start.y, fractal->end.y, HEIGHT - 1);
fractal->c.y += fractal->offset.y;
while (i < fractal->iter_max)
{
tmp_real = fractal->z.x * fractal->z.x - fractal->z.y * fractal->z.y;
tmp_real += fractal->c.x;
fractal->z.y = 2 * fractal->z.x * fractal->z.y + fractal->c.y;
fractal->z.x = tmp_real;
if (fractal->z.x * fractal->z.x + fractal->z.y * fractal->z.y >= 4.0)
break ;
i++;
}
return (i);
}