/
julia.c
66 lines (61 loc) · 2.2 KB
/
julia.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* julia.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbourdel <mbourdel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/20 20:21:59 by mbourdel #+# #+# */
/* Updated: 2016/03/22 18:44:08 by mbourdel ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static t_fract ft_fract_julia(t_fract fract, int x, int y, t_env *env)
{
fract.c_r = -0.7 * env->swag;
fract.c_i = 0.27015 * env->yolo;
fract.z_r = (x - X_SIZE / 2) /
(0.5 * env->zoom * X_SIZE) + env->movx;
fract.z_i = (y - Y_SIZE / 2) /
(0.5 * env->zoom * Y_SIZE) + env->movy;
return (fract);
}
static void ft_draw(t_env *env, int x, int y, int i)
{
if (i == IT_MAX && env->toto == 1)
ft_pixel_put_img(env, x, y, ((x * x + y * y) * 0x439054));
else if (i == IT_MAX && env->toto == 2)
ft_pixel_put_img(env, x, y, 0xFFFFFF);
else if (i == IT_MAX)
ft_pixel_put_img(env, x, y, 0);
else if (i > 10)
ft_pixel_put_img(env, x, y, ((double)i * 0xFFFFFF / IT_MAX));
else
ft_pixel_put_img(env, x, y, ((double)i * 280 * 2 / IT_MAX));
}
void ft_julia(t_env *env)
{
t_fract fract;
fract.x = 0;
while (fract.x < X_SIZE)
{
fract.y = 0;
while (fract.y < Y_SIZE)
{
fract = ft_fract_julia(fract, fract.x, fract.y, env);
fract.i = 0;
while ((((fract.z_r * fract.z_r) + (fract.z_i * fract.z_i)) < 4)
&& (fract.i < IT_MAX))
{
fract.tmp = fract.z_r;
fract.z_r = ((fract.z_r * fract.z_r) - (fract.z_i * fract.z_i)
+ fract.c_r);
fract.z_i = ((2 * fract.z_i * fract.tmp) + fract.c_i);
fract.i++;
}
ft_draw(env, fract.x, fract.y, fract.i);
fract.y++;
}
fract.x++;
}
}