-
Notifications
You must be signed in to change notification settings - Fork 0
/
tricorn.c
70 lines (64 loc) · 1.97 KB
/
tricorn.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tricorn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alamy <alamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/23 13:08:52 by alamy #+# #+# */
/* Updated: 2018/03/16 13:43:32 by alamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
#include <stdlib.h>
static void init_tricorn(t_env *tmp)
{
tmp->f.n_re = 0;
tmp->f.n_im = 0;
tmp->f.o_re = 0;
tmp->f.o_im = 0;
}
static void ft_transformation(t_env *t, int max_iter, int x, int y)
{
t_colorrgb rgb;
int i;
t->f.c_re = t->f.xmin + ((t->f.xmax -
t->f.xmin) / WINDOW_L * x) + t->f.move_x;
t->f.c_im = t->f.ymin + ((t->f.ymax -
t->f.ymin) / WINDOW_H * y) + t->f.move_y;
init_tricorn(t);
i = 0;
while (i < max_iter)
{
t->f.o_re = t->f.n_re;
t->f.o_im = t->f.n_im;
t->f.n_re = t->f.o_re * t->f.o_re - t->f.o_im *
t->f.o_im + t->f.c_re;
t->f.n_im = -2 * t->f.o_re * t->f.o_im + t->f.c_im;
if ((t->f.n_re * t->f.n_re + t->f.n_im * t->f.n_im) > 4)
break ;
i++;
}
rgb = hsv_to_rgb(t, i % 256 + t->c, 1, i < max_iter);
fill_pixel(t, x, y, create_rgb(rgb.r, rgb.g, rgb.b));
}
void ft_create_tricorn(t_env *tmp)
{
int max_iter;
int x;
int y;
max_iter = 300 + tmp->f.iter;
x = 0;
if (max_iter == 50)
tmp->f.iter = 0;
while (x < WINDOW_L)
{
y = 0;
while (y < WINDOW_H)
{
ft_transformation(tmp, max_iter, x, y);
y++;
}
x++;
}
}