-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_mandelbrot.c
executable file
·51 lines (47 loc) · 1.65 KB
/
ft_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_mandelbrot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mvelluet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/04 22:07:17 by mvelluet #+# #+# */
/* Updated: 2017/05/05 05:04:28 by mvelluet ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void ft_mandelbrot_next(t_mlx *ap)
{
double zoom;
while (++ap->y2 < HEIGHT)
{
zoom = HEIGHT / ap->z;
ap->c_x = ap->x2 / zoom + ap->x;
ap->c_y = ap->y2 / zoom + ap->y;
ap->z_x = 0;
ap->z_y = 0;
ap->i = 0;
ap->tmp = ap->z_x;
ap->z_x = (ap->z_x * ap->z_x) - (ap->z_y * ap->z_y) + ap->c_x;
ap->z_y = ((2 * ap->z_y) * ap->tmp) + ap->c_y;
ap->i++;
while ((ap->z_x * ap->z_x + ap->z_y * ap->z_y < 4)
&& (ap->i < ap->ite_max))
{
ap->tmp = ap->z_x;
ap->z_x = (ap->z_x * ap->z_x) - (ap->z_y * ap->z_y) + ap->c_x;
ap->z_y = ((2 * ap->z_y) * ap->tmp) + ap->c_y;
ap->i++;
}
ft_put_pixel(ap, ap->y2, ap->x2);
}
}
void ft_mandelbrot(t_mlx *ap)
{
ap->x2 = -1;
while (++ap->x2 < WIDTH)
{
ap->y2 = -1;
ft_mandelbrot_next(ap);
}
}