-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractol.c
106 lines (95 loc) · 2.41 KB
/
fractol.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
#include <mlx.h>
#include <stdio.h>
#include <stdlib.h>
#include "fractol.h"
#include <X11/keysym.h> // ESC key defintion
#include <X11/Xlib.h> // XColor
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
int deal_click(int pressed_click, void *param)
{
(void)param;
(void)pressed_click;
printf("click %d %c\n", pressed_click, pressed_click);
printf("%f\n", M_PI);
return (0);
}
int deal_key(int pressed_key, void *param)
{
(void)param;
(void)pressed_key;
printf("key %d %c\n", pressed_key, pressed_key);
if (pressed_key == XK_Escape)
exit(1);
return (0);
}
int continue_function(void *param)
{
(void)param;
puts("continue");
return (0);
}
int main(void)
{
void *mlx_ptr;
void *win_ptr;
int x, y;
//int c;
//char buffer;
double MinRe = -2.0;
double MaxRe = 1.0;
double MinIm = -1.2;
double MaxIm = MinIm+(MaxRe-MinRe)*HEIGHT/WIDTH;
double Re_factor = (MaxRe-MinRe)/(WIDTH-1);
double Im_factor = (MaxIm-MinIm)/(HEIGHT-1);
unsigned MaxIterations = 100;
x = -2;
read(x, 0, 0);
//buffer = strerror(-1);
//puts(buffer);
mlx_ptr = mlx_init();
if (!mlx_ptr)
return (1);
win_ptr = mlx_new_window(mlx_ptr, WIDTH, HEIGHT, "Hello World!");
if (!win_ptr)
return (2);
y = 0;
//c = HEIGHT;
while (y < HEIGHT)
{
double c_im = MaxIm - y*Im_factor;
x = 0;
while (x < WIDTH)
{
double c_re = MinRe + x*Re_factor;
double Z_re = c_re, Z_im = c_im;
bool isInside = true;
for(unsigned n=0; n<MaxIterations; ++n)
{
double Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im;
if(Z_re2 + Z_im2 > 4)
{
isInside = false;
break;
}
Z_im = 2*Z_re*Z_im + c_im;
Z_re = Z_re2 - Z_im2 + c_re;
}
if(isInside) { mlx_pixel_put(mlx_ptr, win_ptr, x, y, 0xFF0000); }
// z = 0 ; c = 0
// z_n+1 = zn * zn + c
//if ()
//if ((x - WIDTH / 2) * (x - WIDTH / 2) + (y - HEIGHT / 2) * (y - HEIGHT / 2) == 500)
x++;
}
y++;
}
mlx_key_hook(win_ptr, deal_key, NULL);
mlx_mouse_hook(win_ptr, deal_click, NULL);
//mlx_loop_hook(mlx_ptr, continue_function, NULL);
mlx_loop(mlx_ptr);
return (0);
}