-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractol.h
187 lines (159 loc) · 5.58 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
175
176
177
178
179
180
181
182
183
184
185
186
187
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: passunca <passunca@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/31 10:20:17 by passunca #+# #+# */
/* Updated: 2024/02/14 13:33:10 by passunca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FRACTOL_H
# define FRACTOL_H
//=============================================================================/
// Variables /
//=============================================================================/
// Messages
# define MSG_KILL "Thanks for playing passunca\'s Fract\'ol!\n"
// Display Dimensions
# define HEIGHT 800
# define WIDTH 800
# define OFFSET_X 0.3
# define OFFSET_Y 0.3
# define SCALE_FACTOR 1.15
// Complex Math Inits
# define INIT_ITER 42
# define INIT_C_R -0.5
# define INIT_C_I 0.27025
# define MIN_R -2.0
# define MAX_R 2.0
# define NEWTON_ESC 0.000001
# define SETS 5
# define COLORS 0xFFFFFF
// Set IDs
# define MANDELBROT 0
# define JULIA 1
# define TRICORN 2
# define BURNING 3
# define NEWTON 4
//=============================================================================/
// Librariy Headers /
//=============================================================================/
# include <stdio.h> // EXIT_FAILURE, EXIT_SUCCESS
# include <stdlib.h> // malloc(), free(), exit()
# include <unistd.h> // write()
# include <X11/X.h> // MLX library for Event codes
# include <X11/keysym.h> // Keysym for event handling
# include <math.h> // sqrt()
# include "../lib/libft/libft/libft.h" // Libft library
# include "../lib/libft/ft_printf/ft_printf.h"
# include "../lib/mlx/mlx.h" // MLX library
//=============================================================================/
// Structures /
//=============================================================================/
/* Complex Number Structure
* r: Real part
* i: Imaginary part
* */
typedef struct s_complex
{
double r;
double i;
} t_complex;
/* Image Data Buffer Structure
* [ Stores image data coming from mlx_get_data_addr() ]
* img: Pointer to image struct
* pix: Pointer to image pixel data
* bpp: Bits per pixel
* line_len: Line length
* endian: Endian
* */
typedef struct s_img
{
void *img;
char *pix;
int bpp;
int line_len;
int endian;
} t_img;
/* Struct for passing a range into scaling function
* */
typedef struct s_range
{
double min;
double max;
} t_range;
/* t_display : X Environment Structure
* Check README.md for details
* */
typedef struct s_display
{
void *mlx_conn;
void *mlx_win;
t_img img;
int width;
int height;
t_range win_size;
double x_offset;
double y_offset;
double zoom;
char *name;
int set;
long iter;
t_complex z;
t_complex c;
t_complex c_julia;
t_complex z_newton;
t_range cc_range;
double escape;
double newton_esc;
t_range color_iter;
t_range color_range;
int color;
} t_display;
//=============================================================================/
// Function Prototypes /
//=============================================================================/
/* ft_args.c */
int ft_args(t_display *display, int argc, char **argv);
int ft_select_fractal(t_display *display, int argc, char **argv);
/* ft_help.c : Args handling & help functions */
int ft_usage(void);
int ft_no_args(void);
/* ft_mlx.c : MLX setup functions */
void ft_init_display(t_display *display, char **argv);
void ft_init_events(t_display *display);
void ft_init_data(t_display *display, char **argv);
t_complex ft_init_complex(double r, double i);
t_range ft_init_range(double min, double max);
/* ft_render.c : Rendering bitmap functions */
void ft_render(t_display *display);
void ft_select_set(t_display *d, int x, int y);
void ft_put_pixel(t_img img, int x, int y, int color);
/* ft_sets.c : Fractal set renderers */
void render_mandelbrot(t_display *display, int x, int y);
void render_julia(t_display *display, int x, int y);
void render_tricorn(t_display *d, int x, int y);
void render_burning(t_display *d, int x, int y);
/* ft_sets_newton.c : Newton's set needed its own file */
void render_newton(t_display *display, int x, int y);
/* ft_events.c */
int ft_handle_keys(int keysym, t_display *display);
int ft_handle_mouse(int button, int x, int y, t_display *display);
/* ft_kill.c : exit functions */
void ft_clean_kill(t_display *display);
int ft_kill_werror(char *str);
void ft_kill_window(t_display *display);
int ft_kill_handle(t_display *display);
void ft_error(void);
/* ft_math.c : Useful math functions */
double ft_map(double n, t_range to_scale, t_range scaled);
/* ft_utils.c : Useful utility functions */
int ft_is_argint(char *arg);
int ft_is_argdbl(char *arg);
/* ft_ui.c : UI rendering functionality */
void ft_render_ui(t_display *d);
/* ft_color.c : Color functions */
int ft_color_newton(unsigned int root);
#endif