-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractol.h
174 lines (146 loc) · 3.69 KB
/
fractol.h
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#ifndef FRACTOL_H
# define FRACTOL_H
# define WIN_W 1200
# define WIN_H 800
# define FRAME_RATE 10
# define FRAME_TIME 1./FRAME_RATE
# define ZOOM_STEP 1
# define MAX_ITER 4096
# define DEFAULT_LOD 3
# define FRACTOL_MAND 0
# define FRACTOL_JULIA 1
# define FRACTOL_Z2 0
# define FRACTOL_SIN 2
# define FRACTOL_MAND_Z2 (FRACTOL_MAND | FRACTOL_Z2)
# define FRACTOL_MAND_SIN (FRACTOL_MAND | FRACTOL_SIN)
# define FRACTOL_JULIA_Z2 (FRACTOL_JULIA | FRACTOL_Z2)
# define FRACTOL_JULIA_SIN (FRACTOL_JULIA | FRACTOL_SIN)
# define HELP1 "Usage: ./fractol TYPE\n\twhere TYPE is one of following:\n"
# define HELP2 "\t- mandelbrot\n\t- julia\n\t- mandelbrot_sin\n\t- julia_sin"
# define HELP HELP1 HELP2
#include <time.h>
#include "libft.h"
#include "libft_linalg.h"
#include "threading.h"
#include "mlx_consts.h"
typedef struct
{
double re;
double im;
} t_complex;
typedef struct
{
int w;
int h;
void *image;
uint *data;
int bpp;
int endian;
int row_len;
} t_framebuffer;
typedef struct
{
void *p;
void (*f)(void *c, void *p);
} t_control_callback;
typedef struct
{
int buttons[8];
t_point pos;
t_point click_pos[8];
t_point release_pos[8];
t_control_callback bindings[8];
t_control_callback move_bind;
} t_mouse;
typedef struct
{
char keyboard[128];
t_control_callback keyboard_bindings[128];
t_mouse mouse;
int dx;
int dy;
int du;
int dv;
int dz;
int d_yaw;
} t_controller;
typedef struct
{
uint is_changed;
t_vec julia_offset;
double zoom;
double rot_angle;
t_mat m; //model-view for re axis
t_vec click_pos; //used for mouse movement
clock_t clock;
t_mat d; //display
} t_cam;
typedef struct
{
t_complex z;
t_complex c;
uint i;
int stop;
} t_fractol_pix;
typedef struct
{
int size;
int *data;
} t_it_estimator;
typedef struct
{
int w;
int h;
uint *color_cache;
int lod;
uint stop_count;
int (*func_iter)(t_fractol_pix *p);
void (*func_reset)(t_fractol_pix *p, t_complex z, t_complex c);
t_it_estimator ies;
t_fractol_pix *data;
} t_fractol;
typedef struct s_app
{
int w;
int h;
int sidebar_w;
void *M;
void *win;
t_framebuffer framebuffer;
time_t time;
time_t frame_time;
t_controller controller;
t_cam cam;
t_fractol fractol;
void (*update)(struct s_app *app, double dt);
int shutdown;
} t_app;
void t_app_init(t_app *app, void (*update)(t_app *app, double dt));
void t_app_up(t_app *app);
void t_app_run(t_app *app);
void bind_keys(void *win, t_controller *c);
void t_ctrl_bind(t_controller *c, int key_code, void (*f)(), void *p);
void t_ctrl_mouse_bind(t_controller *c, int key_code, void (*f)(), void *p);
void t_framebuffer_init(t_framebuffer *fb, void *mlx, int w, int h);
void t_framebuffer_clear(t_framebuffer *fb);
void fb_put_pixel(t_framebuffer *fb, int x, int y, uint color);
void t_cam_init(t_cam *cam, int w, int h);
void t_cam_move(t_cam *cam, t_controller *c, double dt);
uint hue_spiral(int iteration);
void t_fractol_pix_reset_julia(t_fractol_pix *pix, t_complex z, t_complex c);
void t_fractol_pix_reset_mand(t_fractol_pix *pix, t_complex z, t_complex c);
int t_fractol_pix_z2(t_fractol_pix *p);
int t_fractol_pix_sin(t_fractol_pix *p);
void t_fractol_init(t_fractol *f, int w, int h, int fractol_type);
void t_fractol_reset(t_fractol *f, t_cam *cam, t_thread_id ti);
void t_fractol_draw(t_fractol *f, t_framebuffer *fb);
void t_fractol_iteration(t_fractol *f, t_thread_id ti);
void t_ies_init(t_it_estimator *ies);
void t_ies_add(t_it_estimator *ies, int i);
int t_ies_estimate(t_it_estimator *ies);
void t_ies_reset(t_it_estimator *ies);
void fractol_mouse_lmbc(t_controller *c, t_cam *cam);
void fractol_mouse_move(t_cam *cam, t_controller *c);
void fractol_mouse_wheel_up(t_controller *c, t_cam *cam);
void fractol_mouse_wheel_down(t_controller *c, t_cam *cam);
#endif