-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjulia.c
More file actions
68 lines (63 loc) · 2.23 KB
/
julia.c
File metadata and controls
68 lines (63 loc) · 2.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* julia.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ymassiou <ymassiou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 11:56:03 by ymassiou #+# #+# */
/* Updated: 2024/02/14 15:11:02 by ymassiou ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void render_to_window_julia(int x, int y, t_fractal *fractal)
{
int i;
int red;
int green;
int blue;
int color;
while (++x < WIDTH)
{
y = -1;
while (++y < HEIGHT)
{
i = julia_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 julia_study(double x, double y, t_fractal *fractal)
{
double tmp_real;
int i;
if (fractal->iter_max > 250 || fractal->iter_max < 0)
fractal->iter_max = 250;
i = 0;
fractal->z.x = scale_it(x, fractal->start.x, fractal->end.x, WIDTH - 1);
fractal->z.x += fractal->offset.x;
fractal->z.y = scale_it(y, fractal->start.y, fractal->end.y, HEIGHT - 1);
fractal->z.y += fractal->offset.y;
while (i < fractal->iter_max)
{
tmp_real = fractal->z.x;
fractal->z.x = fractal->z.x * fractal->z.x;
fractal->z.x -= fractal->z.y * fractal->z.y;
fractal->z.x += fractal->c.x;
fractal->z.y = 2 * tmp_real * fractal->z.y + fractal->c.y;
if (fractal->z.x * fractal->z.x + fractal->z.y * fractal->z.y >= 4)
break ;
i++;
}
return (i);
}