-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandelbrot.c
56 lines (51 loc) · 1.66 KB
/
mandelbrot.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mandelbrot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvieira <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 22:12:18 by fvieira #+# #+# */
/* Updated: 2022/12/06 22:12:21 by fvieira ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void minimandel(int x, int y, t_fractal *mandel)
{
int i;
double z0;
double z1;
double tempz0;
i = 0;
mandel->c.x = (x + mandel->xarrow) / mandel->zoom
* (0.47 + 2.0) / (mandel->width - 1) - 2.0;
mandel->c.y = (y + mandel->yarrow) / mandel->zoom
* (1.12 + 1.12) / (mandel->width - 1) - 1.12;
z0 = mandel->c.x;
z1 = mandel->c.y;
while (i++ < mandel->iterations)
{
tempz0 = z0 * z0 - z1 * z1 + mandel->c.x;
z1 = 2.0 * z0 * z1 + mandel->c.y;
z0 = tempz0;
if (z0 * z0 + z1 * z1 > 4)
{
my_mlx_pixel_put(mandel, (int) x, (int) y, (mandel->color * i));
break ;
}
}
}
void mandelbrotset(t_fractal *mandel)
{
int x;
int y;
x = -1;
while (++x <= mandel->width)
{
y = -1;
while (++y <= mandel->height)
{
minimandel(x, y, mandel);
}
}
}