-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandelbrot.c
50 lines (46 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mandelbrot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dchristo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/01/16 16:33:59 by dchristo #+# #+# */
/* Updated: 2016/07/08 16:47:34 by dchristo ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void calculate_m(t_env *e, double x0, double y0)
{
double x;
double y;
double x2;
double y2;
double i;
x = 0.0;
y = 0.0;
x2 = e->xs;
y2 = e->ys;
i = -1.0;
while (++i < e->iter && (x2 + y2) < e->iter)
{
y = 2.0 * x * y + y0;
x = x2 - y2 + x0;
x2 = x * x;
y2 = y * y;
}
if (e->theme < 3)
i = ft_mix(i, i - log2(log2(x2 + y2)), 1.0);
e->color = palette(i, (e->theme > 2 ? e->theme - 3 : e->theme));
pixel_put(e);
}
void mandelbrot(t_env *e)
{
e->y = -1;
while ((e->y += 1) < e->img.height)
{
e->x = -1;
while ((e->x += 1) < e->img.width)
calculate_m(e, scaledx(e, e->x), scaledy(e, e->y));
}
}