-
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.
zoom in & out but does not expand fractol
- Loading branch information
Showing
9 changed files
with
214 additions
and
154 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* argv_check.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gkrusta <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/21 11:19:14 by gkrusta #+# #+# */ | ||
/* Updated: 2023/08/21 11:20:14 by gkrusta ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "fractol.h" | ||
|
||
int check_argv(const char *set) | ||
{ | ||
int selection; | ||
|
||
selection = ft_atoi(set); | ||
if (selection == 1 || selection == 2) | ||
return (selection); | ||
else | ||
return (0); | ||
} | ||
|
||
void calculate_set(t_fractol *f) | ||
{ | ||
if (f->set == 1) | ||
mandelbrot(f); | ||
else if (f->set == 2) | ||
julia(f); | ||
/* else if (f->set = 3) | ||
burning_ship(f); */ | ||
} | ||
|
||
char *choose_set(int set) | ||
{ | ||
if (set == 1) | ||
return ("Mandelbrot"); | ||
else if (set == 2) | ||
return ("Julia"); | ||
else | ||
return ("Not found"); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* colors.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gkrusta <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/21 09:58:00 by gkrusta #+# #+# */ | ||
/* Updated: 2023/08/21 11:54:58 by gkrusta ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "fractol.h" | ||
|
||
int get_rgba(int r, int g, int b, int a) | ||
{ | ||
return (r << 24 | g << 16 | b << 8 | a); | ||
} | ||
|
||
uint32_t calculate_color(int iter) | ||
{ | ||
double t; | ||
int r; | ||
int g; | ||
int b; | ||
|
||
if (iter == MAX_ITER) | ||
return (get_rgba(0, 0, 0, 255)); // Black for points in the set | ||
t = (double)iter / MAX_ITER; // Calculate a value between 0 and 1 | ||
r = (int)(255 * (1 - t)); // Red component based on t | ||
g = (int)(255 * (1 - t)); // Green component based on (1 - t) | ||
b = (int)(255); // Blue component based on t= | ||
return (get_rgba(r, g, b, 255)); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* fractol.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: gkrusta <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/08/21 10:01:09 by gkrusta #+# #+# */ | ||
/* Updated: 2023/08/21 12:25:44 by gkrusta ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "fractol.h" | ||
|
||
void mandelbrot(t_fractol *f) | ||
{ | ||
uint32_t color; | ||
|
||
f->y = 0; | ||
while (f->y < HEIGHT) | ||
{ | ||
f->x = 0; | ||
while (f->x < WIDTH) | ||
{ | ||
f->c_real = calculate_real_part(f); // coresponding c number: c_real | ||
//printf("c real is %f\n", f->c_real); | ||
f->c_imag = calculate_imag_part(f); // coresponding c number: c_imag * i | ||
//printf("c imag is %f\n", f->c_imag); | ||
f->iter = ft_calculate_iter(f); // calculate iter | ||
//printf ("iterations: %d\n", f->iter); | ||
color = calculate_color(f->iter); | ||
mlx_put_pixel(f->g_img, f->x, f->y, color); | ||
f->x++; | ||
} | ||
f->y++; | ||
} | ||
} | ||
|
||
void julia(t_fractol *f) | ||
{ | ||
uint32_t color; | ||
|
||
f->y = 0; | ||
while (f->y < HEIGHT) | ||
{ | ||
f->x = 0; | ||
while (f->x < WIDTH) | ||
{ | ||
f->z_real = calculate_real_part(f); // coresponding c number: c_real | ||
f->z_imag = calculate_imag_part(f); // coresponding c number: c_imag * i | ||
f->iter = ft_calculate_iter(f); // calculate iter | ||
color = calculate_color(f->iter); | ||
mlx_put_pixel(f->g_img, f->x, f->y, color); | ||
f->x++; | ||
} | ||
f->y++; | ||
} | ||
} |
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 09:10:25 by gkrusta ### ########.fr */ | ||
/* Updated: 2023/08/21 11:58:39 by gkrusta ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -48,16 +48,29 @@ typedef struct s_fractol { | |
double c_imag; | ||
double y; | ||
double x; | ||
double lim_x; | ||
double lim_y; | ||
double zoom; | ||
int iter; | ||
} t_fractol; | ||
|
||
|
||
//uint32_t calculate_color(t_fractol *f); | ||
uint32_t calculate_color(int iter); | ||
int get_rgba(int r, int g, int b, int a); | ||
/* void hook(void *param); | ||
double ft_calculate_c_real(double x); | ||
double ft_calculate_c_imag(double y); | ||
int ft_calculate_iterations(double c_real, double c_imag); */ | ||
/* sets color based on number of iterations */ | ||
uint32_t calculate_color(int iter); | ||
int get_rgba(int r, int g, int b, int a); | ||
|
||
/* fractol sets */ | ||
void mandelbrot(t_fractol *f); | ||
void julia(t_fractol *f); | ||
|
||
/* calculations */ | ||
double calculate_real_part(t_fractol *f); | ||
double calculate_imag_part(t_fractol *f); | ||
int ft_calculate_iter(t_fractol *f); | ||
|
||
/* set */ | ||
int check_argv(const char *set); | ||
void calculate_set(t_fractol *f); | ||
char *choose_set(int set); | ||
|
||
#endif |
Oops, something went wrong.