-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfractals.c
120 lines (109 loc) · 3.17 KB
/
fractals.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractals.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cwu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/16 17:50:22 by cwu #+# #+# */
/* Updated: 2018/05/16 17:50:24 by cwu ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractal.h"
int cubeiter(int x, int y, t_input in)
{
t_cpt z;
t_cpt tmp;
int iter;
z.r = (float)(x - in.mlx.o.x) / in.mlx.unit;
z.i = (float)(y - in.mlx.o.y) / in.mlx.unit;
iter = 1;
while (iter < in.mlx.it && z.r * z.r + z.i * z.i <= in.mlx.esc)
{
tmp.r = z.r * z.r * z.r - 3 * z.r * z.i * z.i + in.mlx.c.r;
tmp.i = 3 * z.r * z.r * z.i - z.i * z.i * z.i + in.mlx.c.i;
z = tmp;
iter++;
}
if (iter == in.mlx.it)
return (0);
return (iter);
}
int jiter_dots(int x, int y, t_input in)
{
t_cpt z;
t_cpt tmp;
int iter;
z.r = (float)(x - in.mlx.o.x) / in.mlx.unit;
z.i = (float)(y - in.mlx.o.y) / in.mlx.unit;
iter = 1;
while (iter < in.mlx.it && z.r * z.r + z.i * z.i <= in.mlx.esc)
{
tmp.r = z.r * z.r - z.i * z.i + in.mlx.c.r;
tmp.i = 2 * z.r * z.i + in.mlx.c.i;
z = tmp;
iter++;
if (1.0f / (z.r * z.r + z.i * z.i) > in.mlx.esc)
break ;
}
return (iter);
}
int jiter(int x, int y, t_input in)
{
t_cpt z;
t_cpt tmp;
int iter;
z.r = (float)(x - in.mlx.o.x) / in.mlx.unit;
z.i = (float)(y - in.mlx.o.y) / in.mlx.unit;
iter = 1;
while (iter < in.mlx.it && z.r * z.r + z.i * z.i <= in.mlx.esc)
{
tmp.r = z.r * z.r - z.i * z.i + in.mlx.c.r;
tmp.i = 2 * z.r * z.i + in.mlx.c.i;
z = tmp;
iter++;
}
return (iter);
}
int rational1(int x, int y, t_input in)
{
t_cpt z;
t_cpt tmp;
int iter;
float d;
z.r = (float)(x - in.mlx.o.x) / in.mlx.unit;
z.i = (float)(y - in.mlx.o.y) / in.mlx.unit;
iter = 1;
while (iter < in.mlx.it && z.r * z.r + z.i * z.i <= in.mlx.esc)
{
d = (z.r * z.r + z.i * z.i);
tmp.r = z.r * z.r - z.i * z.i + in.mlx.c.r * z.r / d
+ in.mlx.c.i * z.i / d;
tmp.i = 2 * z.r * z.i - in.mlx.c.r * z.i / d
+ in.mlx.c.i * z.r / d;
z = tmp;
iter++;
}
return (iter);
}
int rational2(int x, int y, t_input in)
{
t_cpt z;
t_cpt tmp;
int iter;
float d;
z.r = (float)(x - in.mlx.o.x) / in.mlx.unit;
z.i = (float)(y - in.mlx.o.y) / in.mlx.unit;
iter = 1;
while (iter < in.mlx.it && z.r * z.r + z.i * z.i <= in.mlx.esc)
{
d = (pow((z.r * z.r - z.i * z.i), 2) - 4 * z.r * z.r * z.i * z.i) * 10;
tmp.r = z.r * z.r - z.i * z.i + in.mlx.c.r * (z.r * z.r - z.i * z.i) / d
+ in.mlx.c.i * 2 * z.r * z.i / d;
tmp.i = 2 * z.r * z.i - in.mlx.c.r * 2 * z.r * z.i / d
+ in.mlx.c.i * (z.r * z.r - z.i * z.i) / d;
z = tmp;
iter++;
}
return (iter);
}