-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
max_iter is now a part of struct. add of MLX_KEY_U & MLX_KEY_D for it…
…eration count durning execution
- Loading branch information
Showing
3 changed files
with
30 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: gkrusta <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/21 09:58:00 by gkrusta #+# #+# */ | ||
/* Updated: 2023/08/21 17:37:48 by gkrusta ### ########.fr */ | ||
/* Updated: 2023/08/22 09:24:04 by gkrusta ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -21,9 +21,9 @@ uint32_t calculate_color_default(t_fractol *f) | |
{ | ||
double t; | ||
|
||
if (f->iter == MAX_ITER) | ||
if (f->iter == f->max_iter) | ||
return (get_rgba(0, 0, 0, 255)); // Black for points in the set | ||
t = (double)f->iter / MAX_ITER; // Calculate a value between 0 and 1 | ||
t = (double)f->iter / f->max_iter; // Calculate a value between 0 and 1 | ||
f->r = (int)(255 * (1 - t)); // Red component based on t | ||
f->g = (int)(255 * (1 - t)); // Green component based on (1 - t) | ||
f->b = (int)(255); // Blue component based on t | ||
|
@@ -34,9 +34,9 @@ uint32_t calculate_color_pink(t_fractol *f) | |
{ | ||
double t; | ||
|
||
if (f->iter == MAX_ITER) | ||
if (f->iter == f->max_iter) | ||
return (get_rgba(0, 0, 0, 255)); | ||
t = (double)f->iter / MAX_ITER; | ||
t = (double)f->iter / f->max_iter; | ||
f->r = (int)(255 * t); | ||
f->g = (int)(255 * (1 - t)); | ||
f->b = (int)(255); | ||
|
@@ -47,9 +47,9 @@ uint32_t calculate_color_black(t_fractol *f) | |
{ | ||
double t; | ||
|
||
if (f->iter == MAX_ITER) | ||
if (f->iter == f->max_iter) | ||
return (get_rgba(0, 0, 0, 255)); | ||
t = (double)f->iter / MAX_ITER; | ||
t = (double)f->iter / f->max_iter; | ||
f->r = (int)(255 * t); | ||
f->g = (int)(255 * t); | ||
f->b = (int)(255 * t); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: gkrusta <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/07/28 12:45:05 by gkrusta #+# #+# */ | ||
/* Updated: 2023/08/21 18:36:35 by gkrusta ### ########.fr */ | ||
/* Updated: 2023/08/22 09:22:31 by gkrusta ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -26,15 +26,15 @@ | |
|
||
#define WIDTH 1100 | ||
#define HEIGHT 1100 | ||
#define MAX_ITER 24 | ||
/* #define MAX_ITER 24 */ | ||
|
||
typedef struct s_colors { | ||
/* typedef struct s_colors { | ||
int r; | ||
int g; | ||
int b; | ||
uint32_t final; | ||
double gradient; | ||
} t_colors; | ||
} t_colors; */ | ||
|
||
typedef struct s_fractol { | ||
mlx_t *mlx; | ||
|
@@ -52,6 +52,7 @@ typedef struct s_fractol { | |
double lim_y; | ||
double zoom; | ||
int iter; | ||
int max_iter; | ||
int color_set; | ||
int r; | ||
int g; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: gkrusta <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/18 15:08:35 by gkrusta #+# #+# */ | ||
/* Updated: 2023/08/21 18:42:37 by gkrusta ### ########.fr */ | ||
/* Updated: 2023/08/22 09:25:01 by gkrusta ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -32,6 +32,10 @@ void hook(void *param) | |
f->zoom *= 1.1; // increase zoom by 10% | ||
if (mlx_is_key_down(f->mlx, MLX_KEY_O)) | ||
f->zoom /= 1.1; // Decrease zoom by 10% | ||
if (mlx_is_key_down(f->mlx, MLX_KEY_U)) | ||
f->max_iter += 1; | ||
if (mlx_is_key_down(f->mlx, MLX_KEY_D)) | ||
f->max_iter -= 1; | ||
if (mlx_is_key_down(f->mlx, MLX_KEY_1)) | ||
f->color_set = 1; | ||
if (mlx_is_key_down(f->mlx, MLX_KEY_2)) | ||
|
@@ -44,6 +48,7 @@ void hook(void *param) | |
void start_initialization(t_fractol *f) | ||
{ | ||
f->iter = 0; | ||
f->max_iter = 25; | ||
f->x = 0; | ||
f->y = 0; | ||
f->lim_x = 4; // adjust later | ||
|
@@ -66,29 +71,29 @@ void start_initialization(t_fractol *f) | |
|
||
double calculate_real_part(t_fractol *f) | ||
{ | ||
if (f->set == 1 || f->set == 3) | ||
if (f->set == 2) | ||
{ | ||
f->c_real = 3.7 * f->x / (WIDTH - 1) ; | ||
return ((-2.0 + f->c_real) / f->zoom); | ||
f->z_real = 3.4 * f->x / (WIDTH - 1); | ||
return ((-1.7 + f->z_real) / f->zoom); | ||
} | ||
else | ||
{ | ||
f->z_real = 3.4 * f->x / (WIDTH - 1); | ||
return ((-1.7 + f->z_real) / f->zoom); | ||
f->c_real = 3.7 * f->x / (WIDTH - 1); | ||
return ((-2.0 + f->c_real) / f->zoom); | ||
} | ||
} | ||
|
||
double calculate_imag_part(t_fractol *f) | ||
{ | ||
if (f->set == 1 || f->set == 3) | ||
if (f->set == 2) | ||
{ | ||
f->c_imag = 3.7 * f->y / (HEIGHT - 1) ; | ||
return ((-1.9 + f->c_imag) / f->zoom); | ||
f->z_imag = 3.4 * f->y / (HEIGHT - 1); | ||
return ((-1.7 + f->z_imag) / f->zoom); | ||
} | ||
else | ||
{ | ||
f->z_imag = 3.4 * f->y / (HEIGHT - 1); | ||
return ((-1.7 + f->z_imag) / f->zoom); | ||
f->c_imag = 3.7 * f->y / (HEIGHT - 1) ; | ||
return ((-1.9 + f->c_imag) / f->zoom); | ||
} | ||
} | ||
|
||
|
@@ -102,11 +107,11 @@ int ft_calculate_iter(t_fractol *f) | |
f->z_real = 0; | ||
f->z_imag = 0; | ||
} | ||
while (f->iter < MAX_ITER) | ||
while (f->iter < f->max_iter) | ||
{ | ||
z_real_temp = f->z_real; | ||
f->z_real = ((f->z_real - f->z_imag) * (f->z_real + f->z_imag) + f->c_real); // the real part: x^2 - y^2 + c_imag | ||
if (f->set == 3) // julia calculates the absolute value | ||
if (f->set == 3) // burning ship calculates the absolute value | ||
f->z_imag = 2 * fabs(z_real_temp * f->z_imag) + f->c_imag; | ||
else | ||
f->z_imag = (2 * z_real_temp * f->z_imag + f->c_imag); // the imaginary part: 2xyi + c_real | ||
|