-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.c
110 lines (101 loc) · 2.45 KB
/
functions.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quadratic_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpauw <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/06 18:08:33 by mpauw #+# #+# */
/* Updated: 2018/01/02 16:47:46 by mpauw ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int in_mand(t_complex c, t_complex z, int iterations)
{
long double z_r_sq;
long double z_i_sq;
int i;
i = 0;
z_r_sq = 0;
z_i_sq = 0;
z.i = 0;
z.r = 0;
while (z_i_sq + z_r_sq <= 4.0 && i < iterations)
{
z.i = z.i * z.r;
z.i += z.i;
z.i += c.i;
z.r = z_r_sq - z_i_sq + c.r;
z_r_sq = z.r * z.r;
z_i_sq = z.i * z.i;
i++;
}
if (z_i_sq + z_r_sq > 4.0)
return (i);
return (0);
}
int in_julia(t_complex z, t_complex c, int iterations)
{
int i;
long double z_r_sq;
long double z_i_sq;
i = 0;
z_r_sq = z.r * z.r;
z_i_sq = z.i * z.i;
while (z_i_sq + z_r_sq <= 4.0 && i < iterations)
{
z.i = z.i * z.r;
z.i += z.i;
z.i += c.i;
z.r = z_r_sq - z_i_sq + c.r;
z_r_sq = z.r * z.r;
z_i_sq = z.i * z.i;
i++;
}
if (z_i_sq + z_r_sq > 4.0)
return (i);
return (0);
}
int in_sierp(t_complex z, t_complex c, int iterations)
{
int x;
int y;
(void)iterations;
(void)c;
x = (int)z.r;
y = (int)z.i;
while (x > 0 || y > 0)
{
if (x % 3 == 1 && y % 3 == 1)
return (0);
x /= 3;
y /= 3;
}
return (1);
}
t_event *add_tri_point(t_event *event, int x, int y)
{
int random;
int x_tri;
int y_tri;
random = rand() % 3;
y_tri = I_H - MARGIN_TRI;
if (random == 0)
{
x_tri = I_H / 2.0;
y_tri = MARGIN_TRI;
}
else
x_tri = (random == 1) ? 100 : I_H - MARGIN_TRI;
if (!x && !y)
{
x = 0.5 * (event->store_x + x_tri);
y = 0.5 * (event->store_y + y_tri);
}
event->cur_grain += 1;
event->store_x = x;
event->store_y = y;
((int *)((event->img)->img_arr))[x + y *
((event->img)->size_line_int)] = event->color;
return (event);
}