-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfractal.c
97 lines (90 loc) · 3.22 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: srapopor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/30 18:44:06 by srapopor #+# #+# */
/* Updated: 2022/12/07 14:29:31 by srapopor ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractal.h"
#include "constants.h"
int mandelbrot(t_world_point w_point, t_fractal *fra)
{
double temp;
fra->iter = 1;
fra->cx = (w_point.x) / fra->screen.width * 5;
fra->cy = (w_point.y) / fra->screen.height * 5;
fra->z_x = 0;
fra->z_y = 0;
if (w_point.x < -fra->screen.width / 2 || w_point.x > \
fra->screen.width / 2 || w_point.y < -fra->screen.height / 2 \
|| w_point.y > fra->screen.height / 2)
return (0x000000);
while ((fra->z_x * fra->z_x + fra->z_y * fra-> z_y) < 4 && \
fra->iter <= MAX_ITER)
{
temp = fra->z_x * fra->z_x - fra-> z_y * fra->z_y + fra->cx;
fra->z_y = 2 * fra->z_x * fra->z_y + fra->cy;
fra->z_x = temp;
fra->iter++;
}
if ((fra->z_x * fra->z_x + fra-> z_y * fra->z_y) < 4)
return (0xFF0000);
else
return (get_fractal_color(fra->iter, MAX_ITER, fra));
}
int julia(t_world_point w_point, t_fractal *fra)
{
double temp;
double r;
fra->iter = 1;
fra->cx = -0.7269;
fra->cy = 0.1889;
r = 4;
fra->z_x = (w_point.x) / fra->screen.width * 5;
fra->z_y = (w_point.y) / fra->screen.height * 5;
if (w_point.x < -fra->screen.width / 2 || w_point.x > \
fra->screen.width / 2 || w_point.y < -fra->screen.height / 2 \
|| w_point.y > fra->screen.height / 2)
return (0x000000);
while ((fra->z_x * fra->z_x + fra->z_y * fra-> z_y) < r && \
fra->iter <= MAX_ITER)
{
temp = fra->z_x * fra->z_x - fra-> z_y * fra->z_y;
fra->z_y = 2 * fra->z_x * fra->z_y + fra->cy;
fra->z_x = temp + fra->cx;
fra->iter++;
}
if ((fra->z_x * fra->z_x + fra-> z_y * fra->z_y) < r)
return (0xFF0000);
else
return (get_fractal_color(fra->iter, MAX_ITER, fra));
}
int burningship(t_world_point w_point, t_fractal *fra)
{
double temp;
fra->iter = 1;
fra->cx = (w_point.x) / fra->screen.width * 5;
fra->cy = (w_point.y) / fra->screen.height * 5;
fra->z_x = 0;
fra->z_y = 0;
if (w_point.x < -fra->screen.width / 2 || w_point.x > \
fra->screen.width / 2 || w_point.y < -fra->screen.height / 2 \
|| w_point.y > fra->screen.height / 2)
return (0x000000);
while ((fra->z_x * fra->z_x + fra->z_y * fra-> z_y) < 4 && \
fra->iter <= MAX_ITER)
{
temp = (fra->z_x * fra->z_x - fra-> z_y * fra->z_y + fra->cx);
fra->z_y = fabs(2 * fra->z_x * fra->z_y) + fra->cy;
fra->z_x = temp;
fra->iter++;
}
if ((fra->z_x * fra->z_x + fra-> z_y * fra->z_y) < 4)
return (0xFF0000);
else
return (get_fractal_color(fra->iter, MAX_ITER, fra));
}