-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfractal.c
More file actions
135 lines (125 loc) · 2.84 KB
/
Copy pathfractal.c
File metadata and controls
135 lines (125 loc) · 2.84 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hamalmar <hamalmar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/29 13:45:52 by h #+# #+# */
/* Updated: 2024/09/21 11:31:54 by hamalmar ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
/*
@brief This function will draw the mandelbrot fractal.
@param p The p pointer holds all of the program data that will be used.
@var ipp Iteration per pixel.
*/
void mandelbrot(t_prog *p)
{
int ipp;
init_complex(p->c, getx(p), gety(p));
init_complex(p->zn, 0, 0);
ipp = 0;
while (ipp < p->cycles)
{
square_complex(p->zn);
add_complex(p->zn, p->c);
if (has_escaped(p->zn))
break ;
ipp++;
}
if (ipp == p->cycles)
p->fc = p->fpc;
else
p->fc = p->fpc + (ipp * p->fsc);
doi(p);
}
void julia(t_prog *p)
{
int ipp;
ipp = 0;
init_complex(p->zn, getx(p), gety(p));
while (ipp < p->cycles)
{
square_complex(p->zn);
add_complex(p->zn, p->c);
if (has_escaped(p->zn))
break ;
ipp++;
}
if (ipp == p->cycles)
p->fc = p->fpc;
else
p->fc = p->fpc + (ipp * p->fsc);
doi(p);
}
void burningship(t_prog *p)
{
int ipp;
double x;
double y;
x = getx(p);
y = gety(p);
init_complex(p->c, 0, 0);
init_complex(p->zn, x, y);
ipp = 0;
while (ipp < p->cycles)
{
square_complex(p->zn);
p->zn->a += x;
p->zn->b = fabs(p->zn->b) + y;
add_complex(p->zn, p->c);
if (has_escaped(p->zn))
break ;
ipp++;
}
if (ipp == p->cycles)
p->fc = p->fpc;
else
p->fc = p->fpc + (ipp * p->fsc);
doi(p);
}
void tricon(t_prog *p)
{
int ipp;
init_complex(p->c, getx(p), gety(p));
init_complex(p->zn, 0, 0);
ipp = 0;
while (ipp < p->cycles)
{
square_complex(p->zn);
p->zn->b = -p->zn->b;
add_complex(p->zn, p->c);
if (has_escaped(p->zn))
break ;
ipp++;
}
if (ipp == p->cycles)
p->fc = p->fpc;
else
p->fc = p->fpc + (ipp * p->fsc);
doi(p);
}
void fractal(t_prog *p)
{
p->y = 0;
while (p->y < HEIGHT)
{
p->x = 0;
while (p->x < WIDTH)
{
if (p->fractal == 'm')
mandelbrot(p);
else if (p->fractal == 'j')
julia(p);
else if (p->fractal == 'b')
burningship(p);
else if (p->fractal == 't')
tricon(p);
p->x++;
}
p->y++;
}
mlx_put_image_to_window(p->mlx, p->win, p->img, 0, 0);
}