-
Notifications
You must be signed in to change notification settings - Fork 0
/
burningship.c
79 lines (72 loc) · 2.41 KB
/
burningship.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* burningship_set.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lorphan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/28 22:04:34 by lorphan #+# #+# */
/* Updated: 2021/09/30 17:45:51 by lorphan ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/fractol.h"
static int iterate_burningship(t_fractal *fractal)
{
t_complex z;
double temp;
int iteration;
iteration = 1;
z.re = fractal->c.re;
z.im = fractal->c.im;
while (z.re * z.re + z.im * z.im <= 4.0
&& iteration <= fractal->max_iteration)
{
temp = z.re;
z.re = z.re * z.re - z.im * z.im + fractal->c.re;
z.im = 2.0 * fabs(temp * z.im) + fractal->c.im;
iteration++;
}
return (iteration);
}
static void burningship_part(t_fractal *fractal)
{
int x;
int y;
int color;
int iteration;
y = fractal->min_pthread_bound;
while (y < fractal->max_pthread_bound)
{
fractal->c.im = fractal->max.im - y * fractal->factor.im;
x = 0;
while (x < WIN_WIDTH)
{
fractal->c.re = fractal->min.re + x * fractal->factor.re;
iteration = iterate_burningship(fractal);
color = get_color(fractal, iteration, fractal->max_iteration);
my_mlx_pixel_put(&fractal->image, x, WIN_HEIGHT - y - 1, color);
x++;
}
y++;
}
}
void burningship(t_fractal *fractal)
{
int i;
pthread_t threads[THREADS];
t_fractal fractals[THREADS];
fractal->factor.re = (fractal->max.re - fractal->min.re) / WIN_WIDTH;
fractal->factor.im = (fractal->max.im - fractal->min.im) / WIN_HEIGHT;
i = 0;
while (i < THREADS)
{
fractals[i] = *fractal;
fractals[i].min_pthread_bound = i * (WIN_HEIGHT / THREADS);
fractals[i].max_pthread_bound = (i + 1) * (WIN_HEIGHT / THREADS);
pthread_create(&threads[i], NULL,
(void *(*)(void *))burningship_part, (void *)&fractals[i]);
i++;
}
while (i-- > 0)
pthread_join(threads[i], NULL);
}