-
Notifications
You must be signed in to change notification settings - Fork 1
/
fractal.c
100 lines (89 loc) · 2.61 KB
/
fractal.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: znichola <znichola@student.42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/27 23:52:35 by znichola #+# #+# */
/* Updated: 2022/12/01 16:15:16 by znichola ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int mandelbrot_like(t_complex z, t_complex c, int depth)
{
t_complex ans;
double len;
int ret;
ans = c_addition(c_power2(z), c);
len = c_length(ans);
ret = -1;
if (len >= 2)
return (depth);
else if (depth > 0)
ret = mandelbrot_like(ans, c, depth - 1);
return (ret);
}
int burningship(t_complex z, t_complex c, int depth)
{
t_complex ans;
double len;
int ret;
ans = c_abs(c_addition(c_power2(z), c));
len = c_length(ans);
ret = -1;
if (len >= 2)
return (depth);
else if (depth > 0)
ret = burningship(ans, c, depth - 1);
return (ret);
}
int burningjulia(t_complex z, t_complex c, int depth)
{
t_complex ans;
double len;
int ret;
ans = c_abs(c_addition(c_power2(z), c));
len = c_length(ans);
ret = -1;
if (len >= 2)
return (depth);
else if (depth > 0)
ret = burningship(ans, c, depth - 1);
return (ret);
}
int fractal_selector(t_app *a, t_ipoint pix, int fractal, int depth)
{
t_complex test;
test = ftc(rscreen_to_world(a, pix));
if (fractal == JULIA)
return (mandelbrot_like(test, ftc(a->world_mouse_right), depth));
else if (fractal == BURNINGSHIP)
return (burningship(ftc(fpoint(0.0, 0.0)), test, depth));
else if (fractal == NONAME)
return (burningjulia(test, ftc(a->world_mouse_right), depth));
return (mandelbrot_like(ftc(fpoint(0.0, 0.0)), test, depth));
}
int generate_fractal(t_app *p)
{
int h;
int w;
int d;
int colour;
h = p->img.hight;
while (h--)
{
w = p->img.width;
while (w--)
{
d = fractal_selector(p,
ipoint(w, h), p->fractal_select, p->cf.depth);
colour = WHITE;
if (d != -1)
colour = colour_ramp(1, MAXDEPTH, p->cf.depth - d,
p->pallets.p[p->pallet_index]);
my_mlx_pixel_put(&p->img, w, h, colour);
}
}
return (0);
}