-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractals_math.c
123 lines (112 loc) · 3.07 KB
/
fractals_math.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractals_math.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kprytkov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/06/10 19:12:53 by kprytkov #+# #+# */
/* Updated: 2018/06/10 19:12:54 by kprytkov ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/fractol.h"
int mandelbrot_math(t_env *e, int x, int y)
{
long double mx;
long double my;
long double c_im;
long double c_re;
long double x_temp;
e->iteration = 0;
mx = 0.0;
my = 0.0;
c_re = ft_map(x, add_params(0, WIDTH, e->min_x, e->max_x));
c_im = ft_map(y, add_params(0, HEIGHT, e->min_y, e->max_y));
while (e->iteration < e->infinity)
{
x_temp = (mx * mx - my * my) + c_re;
my = 2.0f * mx * my + c_im;
mx = x_temp;
if ((mx * mx + my * my) > 4.0f)
break ;
e->iteration++;
}
return (e->iteration);
}
int julia_math(t_env *e, int x, int y)
{
long double mx;
long double my;
long double x_temp;
e->iteration = 0;
mx = ft_map(x, add_params(0, WIDTH, e->min_x, e->max_x));
my = ft_map(y, add_params(0, HEIGHT, e->min_y, e->max_y));
while (e->iteration < e->infinity)
{
x_temp = (mx * mx - my * my) + e->c_re;
my = 2.0f * mx * my + e->c_im;
mx = x_temp;
if ((mx * mx + my * my) > 4.0f)
break ;
e->iteration++;
}
return (e->iteration);
}
int burning_ship_math(t_env *e, int x, int y)
{
long double mx;
long double my;
long double c_im;
long double c_re;
long double x_temp;
e->iteration = 0;
mx = 0.0;
my = 0.0;
c_re = ft_map(x, add_params(0, WIDTH, e->min_x, e->max_x));
c_im = ft_map(y, add_params(0, HEIGHT, e->min_y, e->max_y));
while (e->iteration < e->infinity)
{
x_temp = (mx * mx - my * my) + c_re;
my = fabsl(2.0 * mx * my + c_im);
mx = fabsl(x_temp);
if ((mx * mx + my * my) > 4.0f)
break ;
e->iteration++;
}
return (e->iteration);
}
int sierpinski_carpet(t_env *e, int x, int y)
{
int i;
i = 0;
x *= e->zoom;
y *= e->zoom;
while (i < e->infinity)
{
if ((x % 3 == 1) && (y % 3 == 1))
return (0);
x /= 3;
y /= 3;
i++;
}
return (20);
}
int douady_rabbit(t_env *e, int x, int y)
{
long double mx;
long double my;
long double x_temp;
e->iteration = 0;
mx = ft_map((long double)x, add_params(0, WIDTH, e->min_x, e->max_x));
my = ft_map((long double)y, add_params(0, HEIGHT, e->min_y, e->max_y));
while (e->iteration < e->infinity)
{
x_temp = (mx * mx - my * my) - 0.123;
my = 2.0f * mx * my + 0.745f;
mx = x_temp;
if ((mx * mx + my * my) > 4.0f)
break ;
e->iteration++;
}
return (e->iteration);
}