-
Notifications
You must be signed in to change notification settings - Fork 0
/
mandel.c
71 lines (67 loc) · 2.17 KB
/
mandel.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mandel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: imarakho <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/20 18:20:44 by imarakho #+# #+# */
/* Updated: 2017/02/23 18:18:26 by imarakho ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void ft_mandel(t_fract *fr)
{
fr->cy = -1;
while (++fr->cy < fr->wsize)
{
fr->cx = -1;
while (++fr->cx < fr->wsize)
{
fr->cr = 1.5 * (fr->cx - fr->zx) /
((fr->wsize >> 1) * fr->zoom) - 0.73 + fr->movex;
fr->cim = (fr->cy - fr->zy) /
(0.5 * (fr->wsize >> 1) * fr->zoom) + fr->movey;
fr->newr = 0;
fr->newim = 0;
fr->i = -1;
while (++fr->i < fr->iter)
{
fr->oldr = fr->newr;
fr->oldim = fr->newim;
fr->newr = fr->oldr * fr->oldr - fr->oldim * fr->oldim + fr->cr;
fr->newim = 2 * fr->oldr * fr->oldim + fr->cim;
if (fr->newim * fr->newim + fr->newr * fr->newr > 4)
break ;
}
drawing(fr, fr->i, fr->cx, fr->cy);
}
}
}
void check_mandel(t_fract *fr, int key)
{
int a;
fr->img = mlx_new_image(fr->mlx, fr->wsize, fr->wsize);
key == 24 ? fr->iter += 10 : 0;
key == 27 ? fr->iter -= 10 : 0;
key == 123 ? fr->movex += 0.1 : 0;
key == 124 ? fr->movex -= 0.1 : 0;
key == 125 ? fr->movey -= 0.1 : 0;
key == 126 ? fr->movey += 0.1 : 0;
if (key == 18)
{
fr->cfl = 'g';
fr->key = key;
}
if (key == 19)
{
fr->cfl = 'r';
fr->key = key;
}
if (fr->key != 19 && fr->key != 18)
fr->cfl = 'b';
fr->key = key;
ft_mandel(fr);
a = mlx_put_image_to_window(fr->mlx, fr->win, fr->img, 0, 0);
mlx_destroy_image(fr->mlx, fr->img);
}