circle factorial

This commit is contained in:
Gregory 2017-03-19 00:24:14 +02:00
parent 59b95cf57b
commit ef7158830e
15 changed files with 412 additions and 333 deletions

View file

@ -15,7 +15,7 @@ set(SOURCE_FILES
src/render.c src/render.c
src/mat4.c src/mat4.c
src/color.c src/color.c
src/fdf_init.c src/fractol_init.c
src/hooks.c src/hooks.c
src/image_routine.c src/image_routine.c
src/map_routine.c src/map_routine.c

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* fdf.h :+: :+: :+: */ /* fractol.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
@ -10,16 +10,16 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef FDF_H #ifndef FRACTOL_H
# define FDF_H # define FRACTOL_H
# include "libft.h" # include "libft.h"
# include <mlx.h> # include "mlx.h"
# include <math.h> # include <math.h>
# include <fcntl.h> # include <fcntl.h>
# define HEIGHT 700 # define HEIGHT 700
# define WIDTH 700 # define WIDTH 1300
# define COLOR1 0 # define COLOR1 0
# define COLOR2 16777215 # define COLOR2 16777215
# define INIT_X 30 # define INIT_X 30
@ -105,9 +105,8 @@ typedef struct s_map
float scale[3]; float scale[3];
} t_map; } t_map;
typedef struct s_fdf typedef struct s_fractol
{ {
t_map *map;
t_mw *mw; t_mw *mw;
int w_height; int w_height;
int w_width; int w_width;
@ -116,9 +115,9 @@ typedef struct s_fdf
void *image; void *image;
char *image_data; char *image_data;
int endian; int endian;
} t_fdf; } t_fractol;
void parse_input(int ac, char **av, t_fdf **fdf); void parse_input(int ac, char **av, t_fractol **fractol);
int wrong_symbols(char **line); int wrong_symbols(char **line);
void wrong_map(void); void wrong_map(void);
@ -132,7 +131,7 @@ t_trnsf *trnsf_mat_init();
t_mat4 *viewport_mat_init(int x, int y); t_mat4 *viewport_mat_init(int x, int y);
t_mat4 *orth_mat_init(float r, float t, float f); t_mat4 *orth_mat_init(float r, float t, float f);
void initial_trnsf_mats(t_fdf *fdf); void initial_trnsf_mats(t_fractol *fractol);
void mat4_mult_chain(t_trnsf *tf); void mat4_mult_chain(t_trnsf *tf);
void mat4_translate(t_mat4 *m, double x, double y, double z); void mat4_translate(t_mat4 *m, double x, double y, double z);
void mat4_scale(t_mat4 *m, double x, double y, double z); void mat4_scale(t_mat4 *m, double x, double y, double z);
@ -151,7 +150,7 @@ void center(t_map *map);
int tab_length(char **tab); int tab_length(char **tab);
void free_tab(char **tab); void free_tab(char **tab);
void quit(t_fdf *fdf); void quit(t_fractol *fractol);
void swap_init(t_swap *s); void swap_init(t_swap *s);
void print_help(void); void print_help(void);
t_color color_init(int red, int green, int blue); t_color color_init(int red, int green, int blue);
@ -161,25 +160,25 @@ t_color int_to_color(int c);
int color_to_int(t_color c); int color_to_int(t_color c);
t_color choose_color(t_line *line, t_swap *s); t_color choose_color(t_line *line, t_swap *s);
void first_color(t_pnt *pnt, float z, t_map *map); void first_color(t_pnt *pnt, float z, t_map *map);
t_fdf *fdf_init(char *path, t_color *low, t_color *high); t_fractol *fractol_init(void);
int key_hook(int keycode, void *m); int key_hook(int keycode, void *m);
void line(t_pnt p1, t_pnt p2, t_fdf *fdf); void line(t_pnt p1, t_pnt p2, t_fractol *fractol);
void render(t_fdf *fdf); void render(t_fractol *fractol);
void put_pixel_to_image(t_line *line, t_swap *s, t_fdf *fdf); void put_pixel_to_image(int x, int y, t_color *col, t_fractol *fr);
void left_rot(t_fdf *fdf); void left_rot(t_fractol *fractol);
void right_rot(t_fdf *fdf); void right_rot(t_fractol *fractol);
void forw_rot(t_fdf *fdf); void forw_rot(t_fractol *fractol);
void back_rot(t_fdf *fdf); void back_rot(t_fractol *fractol);
void clock_rot(t_fdf *fdf); void clock_rot(t_fractol *fractol);
void aclock_rot(t_fdf *fdf); void aclock_rot(t_fractol *fractol);
void scale_up_z(t_fdf *fdf); void scale_up_z(t_fractol *fractol);
void scale_down_z(t_fdf *fdf); void scale_down_z(t_fractol *fractol);
void zoom_in(t_fdf *fdf); void zoom_in(t_fractol *fractol);
void zoom_out(t_fdf *fdf); void zoom_out(t_fractol *fractol);
void reset(t_fdf *fdf); void reset(t_fractol *fractol);
void move(t_fdf *fdf); void move(t_fractol *fractol);
#endif #endif

View file

@ -12,6 +12,16 @@
#include "fractol.h" #include "fractol.h"
t_color color_init(int red, int green, int blue)
{
t_color c;
c.red = red;
c.green = green;
c.blue = blue;
return (c);
}
t_color color_lerp(t_color c1, t_color c2, double step) t_color color_lerp(t_color c1, t_color c2, double step)
{ {
t_color new; t_color new;

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* fdf_init.c :+: :+: :+: */ /* fractol_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
@ -19,30 +19,26 @@ static t_mw *mlx_and_win_ptr_init(int x, int y)
if ((mw = malloc(sizeof(t_mw)))) if ((mw = malloc(sizeof(t_mw))))
{ {
mw->mlx = mlx_init(); mw->mlx = mlx_init();
mw->win = mlx_new_window(mw->mlx, x, y, "FDF"); mw->win = mlx_new_window(mw->mlx, x, y, "FRCTL");
} }
return (mw); return (mw);
} }
t_fdf *fdf_init(char *path, t_color *low, t_color *high) t_fractol *fractol_init(void)
{ {
t_fdf *fdf; t_fractol *fractol;
if ((fdf = malloc(sizeof(t_fdf)))) if ((fractol = malloc(sizeof(t_fractol))))
{ {
fdf->map = map_init(path); fractol->w_height = HEIGHT;
fdf->map->low = low; fractol->w_width = WIDTH;
fdf->map->high = high; fractol->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT);
pnt_init(fdf->map); fractol->image = mlx_new_image(fractol->mw->mlx, WIDTH, HEIGHT);
fdf->w_height = HEIGHT; fractol->image_data = mlx_get_data_addr(
fdf->w_width = WIDTH; fractol->image,
fdf->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT); &fractol->bpp,
fdf->image = mlx_new_image(fdf->mw->mlx, WIDTH, HEIGHT); &fractol->line_size,
fdf->image_data = mlx_get_data_addr( &fractol->endian);
fdf->image,
&fdf->bpp,
&fdf->line_size,
&fdf->endian);
} }
return (fdf); return (fractol);
} }

View file

@ -19,10 +19,10 @@ void free_tab(char **tab)
free(*tab); free(*tab);
} }
void quit(t_fdf *fdf) void quit(t_fractol *fr)
{ {
if (fdf && fdf->mw->mlx && fdf->mw->win) if (fr && fr->mw->mlx && fr->mw->win)
mlx_destroy_window(fdf->mw->mlx, fdf->mw->win); mlx_destroy_window(fr->mw->mlx, fr->mw->win);
exit(0); exit(0);
} }

View file

@ -14,29 +14,30 @@
int key_hook(int keycode, void *fdf) int key_hook(int keycode, void *fdf)
{ {
if (keycode == 53) ft_putnbr(keycode);
if (keycode == 65307)
quit(fdf); quit(fdf);
if (keycode == 89) // if (keycode == 89)
aclock_rot(fdf); // aclock_rot(fdf);
if (keycode == 86) // if (keycode == 86)
left_rot(fdf); // left_rot(fdf);
if (keycode == 88) // if (keycode == 88)
right_rot(fdf); // right_rot(fdf);
if (keycode == 87) // if (keycode == 87)
back_rot(fdf); // back_rot(fdf);
if (keycode == 91) // if (keycode == 91)
forw_rot(fdf); // forw_rot(fdf);
if (keycode == 92) // if (keycode == 92)
clock_rot(fdf); // clock_rot(fdf);
if (keycode == 83) // if (keycode == 83)
scale_up_z(fdf); // scale_up_z(fdf);
if (keycode == 84) // if (keycode == 84)
scale_down_z(fdf); // scale_down_z(fdf);
if (keycode == 69) // if (keycode == 69)
zoom_in(fdf); // zoom_in(fdf);
if (keycode == 78) // if (keycode == 78)
zoom_out(fdf); // zoom_out(fdf);
if (keycode == 82) // if (keycode == 82)
reset(fdf); // reset(fdf);
return (0); return (0);
} }

View file

@ -12,20 +12,10 @@
#include "fractol.h" #include "fractol.h"
void put_pixel_to_image(t_line *line, t_swap *s, t_fdf *fdf) void put_pixel_to_image(int x, int y, t_color *col, t_fractol *fr)
{ {
int x; if (x < 0 || y < 0 || x >= fr->w_width || y >= fr->w_height)
int y;
x = line->p1.x;
y = line->p1.y;
if (s->swap_coord)
{
y = line->p1.x;
x = line->p1.y;
}
if (x < 0 || y < 0 || x >= fdf->w_width || y >= fdf->w_height)
return ; return ;
*(int *)((fdf->image_data + x * fdf->bpp / 8 + y * fdf->line_size)) = *(int *)((fr->image_data + x * fr->bpp / 8 + y * fr->line_size)) =
color_to_int(choose_color(line, s)); color_to_int(*col);
} }

View file

@ -46,20 +46,22 @@ static void swap_points(t_pnt *p1, t_pnt *p2)
*p2 = temp; *p2 = temp;
} }
static void draw_line(t_line *line, t_swap *s, t_fdf *fdf) static void draw_line(t_line *line, t_swap *s, t_fractol *fr)
{ {
int dx; int dx;
int dy; int dy;
int derr; int derr;
double dz; double dz;
t_color col;
col = int_to_color(COLOR2);
dx = abs(line->p2.x - line->p1.x); dx = abs(line->p2.x - line->p1.x);
dy = abs(line->p2.y - line->p1.y); dy = abs(line->p2.y - line->p1.y);
dz = fabs(line->p2.z - line->p1.z); dz = fabs(line->p2.z - line->p1.z);
derr = 2 * dy - dx; derr = 2 * dy - dx;
while (line->p1.x < line->p2.x) while (line->p1.x < line->p2.x)
{ {
put_pixel_to_image(line, s, fdf); put_pixel_to_image(line->p1.x, line->p1.y, &col, fr);
if (derr > 0) if (derr > 0)
{ {
line->p1.y += s->swap_x; line->p1.y += s->swap_x;
@ -71,7 +73,7 @@ static void draw_line(t_line *line, t_swap *s, t_fdf *fdf)
} }
} }
void line(t_pnt p1, t_pnt p2, t_fdf *fdf) void line(t_pnt p1, t_pnt p2, t_fractol *fdf)
{ {
int dx; int dx;
int dy; int dy;

View file

@ -11,19 +11,100 @@
/* ************************************************************************** */ /* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
#include <time.h>
void drawcircle(t_pnt pnt, float radius, t_fractol *fr)
{
int x = (int)radius;
int y = 0;
int err = 0;
while (x >= y)
{
put_pixel_to_image(pnt.x + x, pnt.y + y, &pnt.color, fr);
put_pixel_to_image(pnt.x + y, pnt.y + x, &pnt.color, fr);
put_pixel_to_image(pnt.x - y, pnt.y + x, &pnt.color, fr);
put_pixel_to_image(pnt.x - x, pnt.y + y, &pnt.color, fr);
put_pixel_to_image(pnt.x - x, pnt.y - y, &pnt.color, fr);
put_pixel_to_image(pnt.x - y, pnt.y - x, &pnt.color, fr);
put_pixel_to_image(pnt.x + y, pnt.y - x, &pnt.color, fr);
put_pixel_to_image(pnt.x + x, pnt.y - y, &pnt.color, fr);
if (err <= 0)
{
y += 1;
err += 2*y + 1;
}
if (err > 0)
{
x -= 1;
err -= 2*x + 1;
}
}
}
void recursive_circles(t_pnt pnt, float radius, t_fractol *fr)
{
int tmp;
drawcircle(pnt, radius, fr);
pnt.color = color_lerp(pnt.color, color_lerp(pnt.color, color_init(0, 97, 255), 0.4), 0.3);
if (radius > 2)
{
tmp = pnt.x;
pnt.x = tmp + (int)radius / 2;
recursive_circles(pnt, radius / 2, fr);
pnt.x = tmp - (int)radius / 2;
recursive_circles(pnt, radius / 2, fr);
tmp = pnt.y;
pnt.y = tmp + (int)radius / 2;
recursive_circles(pnt, radius / 2, fr);
pnt.y = tmp - (int)radius / 2;
recursive_circles(pnt, radius / 2, fr);
}
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
t_fdf *fdf; t_fractol *fr;
t_pnt pnt;
// int i;
fdf = NULL; srand(time(NULL));
parse_input(argc, argv, &fdf); fr = NULL;
center(fdf->map); argc = argc;
initial_trnsf_mats(fdf); argv = argv;
mat4_mult_chain(fdf->map->trnsf); fr = fractol_init();
transform(fdf->map->trnsf->fin, fdf->map); // while (pnt.y < fr->w_height)
render(fdf); // {
mlx_hook(fdf->mw->win, 2, 5, key_hook, fdf); // pnt.x = 0;
mlx_loop(fdf->mw->mlx); // pnt.color = color_lerp(int_to_color(COLOR2), int_to_color(COLOR1), (float)pnt.y / (float)fr->w_height);
// while (pnt.x < fr->w_width)
// {
// drawcircle(pnt, 100, fr);
// pnt.x += 30;
// }
// pnt.y += 30;
// }
pnt.y = fr->w_height / 2;
pnt.x = fr->w_width / 2;
// i = 0;
pnt.color = color_init(255, 0, 0);
recursive_circles(pnt, 1000, fr);
// while (i < 10000)
// {
// usleep(150000);
// recursive_circles(pnt, i, fr);
// mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
// mlx_destroy_image(fr->mw->mlx, fr->image);
// fr->image = mlx_new_image(fr->mw->mlx, WIDTH, HEIGHT);
// fr->image_data = mlx_get_data_addr(
// fr->image,
// &fr->bpp,
// &fr->line_size,
// &fr->endian);
// i +=10;
// }
mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
mlx_hook(fr->mw->win, 2, 5, key_hook, fr);
mlx_loop(fr->mw->mlx);
return (0); return (0);
} }

View file

@ -11,42 +11,42 @@
/* ************************************************************************** */ /* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
//
void move(t_fdf *fdf) //void move(t_fdf *fdf)
{ //{
recalculate_trnsf_matrs(fdf->map); // recalculate_trnsf_matrs(fdf->map);
mat4_mult_chain(fdf->map->trnsf); // mat4_mult_chain(fdf->map->trnsf);
transform(fdf->map->trnsf->fin, fdf->map); // transform(fdf->map->trnsf->fin, fdf->map);
mlx_destroy_image(fdf->mw->mlx, fdf->image); // mlx_destroy_image(fdf->mw->mlx, fdf->image);
fdf->image = mlx_new_image(fdf->mw->mlx, WIDTH, HEIGHT); // fdf->image = mlx_new_image(fdf->mw->mlx, WIDTH, HEIGHT);
fdf->image_data = mlx_get_data_addr( // fdf->image_data = mlx_get_data_addr(
fdf->image, // fdf->image,
&fdf->bpp, // &fdf->bpp,
&fdf->line_size, // &fdf->line_size,
&fdf->endian); // &fdf->endian);
render(fdf); // render(fdf);
} //}
//
void left_rot(t_fdf *fdf) //void left_rot(t_fdf *fdf)
{ //{
fdf->map->y_rot -= 1; // fdf->map->y_rot -= 1;
move(fdf); // move(fdf);
} //}
//
void right_rot(t_fdf *fdf) //void right_rot(t_fdf *fdf)
{ //{
fdf->map->y_rot += 1; // fdf->map->y_rot += 1;
move(fdf); // move(fdf);
} //}
//
void forw_rot(t_fdf *fdf) //void forw_rot(t_fdf *fdf)
{ //{
fdf->map->x_rot += 1; // fdf->map->x_rot += 1;
move(fdf); // move(fdf);
} //}
//
void back_rot(t_fdf *fdf) //void back_rot(t_fdf *fdf)
{ //{
fdf->map->x_rot -= 1; // fdf->map->x_rot -= 1;
move(fdf); // move(fdf);
} //}

View file

@ -12,39 +12,39 @@
#include "fractol.h" #include "fractol.h"
void scale_up_z(t_fdf *fdf) //void scale_up_z(t_fdf *fdf)
{ //{
fdf->map->scale[2] += 1.0f / 100 * 20; // fdf->map->scale[2] += 1.0f / 100 * 20;
move(fdf); // move(fdf);
} //}
//
void scale_down_z(t_fdf *fdf) //void scale_down_z(t_fdf *fdf)
{ //{
fdf->map->scale[2] -= 1.0f / 100 * 20; // fdf->map->scale[2] -= 1.0f / 100 * 20;
move(fdf); // move(fdf);
} //}
//
void zoom_in(t_fdf *fdf) //void zoom_in(t_fdf *fdf)
{ //{
fdf->map->scale[0] += 1.0f / 100 * 20; // fdf->map->scale[0] += 1.0f / 100 * 20;
fdf->map->scale[1] += 1.0f / 100 * 20; // fdf->map->scale[1] += 1.0f / 100 * 20;
move(fdf); // move(fdf);
} //}
//
void zoom_out(t_fdf *fdf) //void zoom_out(t_fdf *fdf)
{ //{
fdf->map->scale[0] -= 1.0f / 100 * 20; // fdf->map->scale[0] -= 1.0f / 100 * 20;
fdf->map->scale[1] -= 1.0f / 100 * 20; // fdf->map->scale[1] -= 1.0f / 100 * 20;
move(fdf); // move(fdf);
} //}
//
void reset(t_fdf *fdf) //void reset(t_fdf *fdf)
{ //{
fdf->map->z_rot = 0; // fdf->map->z_rot = 0;
fdf->map->y_rot = 0; // fdf->map->y_rot = 0;
fdf->map->x_rot = 0; // fdf->map->x_rot = 0;
fdf->map->scale[0] = 1; // fdf->map->scale[0] = 1;
fdf->map->scale[1] = 1; // fdf->map->scale[1] = 1;
fdf->map->scale[2] = 1; // fdf->map->scale[2] = 1;
move(fdf); // move(fdf);
} //}

View file

@ -11,15 +11,15 @@
/* ************************************************************************** */ /* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
//
void clock_rot(t_fdf *fdf) //void clock_rot(t_fdf *fdf)
{ //{
fdf->map->z_rot -= 1; // fdf->map->z_rot -= 1;
move(fdf); // move(fdf);
} //}
//
void aclock_rot(t_fdf *fdf) //void aclock_rot(t_fdf *fdf)
{ //{
fdf->map->z_rot += 1; // fdf->map->z_rot += 1;
move(fdf); // move(fdf);
} //}

View file

@ -22,45 +22,45 @@ void recalculate_trnsf_matrs(t_map *map)
INIT_Y_SCALE * map->scale[1], INIT_Y_SCALE * map->scale[1],
INIT_Z_SCALE * map->scale[2]); INIT_Z_SCALE * map->scale[2]);
} }
//
//static void viewport_projection_translate(t_trnsf *tf)
//{
// t_mat4 *tmp;
//
// tmp = tf->vp_pr_tr;
// tf->vp_pr_tr = mat4_mult(tf->vp, tf->pr);
// free(tmp);
// tmp = tf->vp_pr_tr;
// tf->vp_pr_tr = mat4_mult(tf->tr, tf->vp_pr_tr);
// free(tmp);
//}
static void viewport_projection_translate(t_trnsf *tf) //void initial_trnsf_mats(t_fdf *fdf)
{ //{
t_mat4 *tmp; // t_trnsf *tf;
//
tmp = tf->vp_pr_tr; // tf = trnsf_mat_init();
tf->vp_pr_tr = mat4_mult(tf->vp, tf->pr); // tf->vp = viewport_mat_init(fdf->w_width, fdf->w_height);
free(tmp); // tf->pr = orth_mat_init(
tmp = tf->vp_pr_tr; // (fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
tf->vp_pr_tr = mat4_mult(tf->tr, tf->vp_pr_tr); // fdf->map->x_max + 2,
free(tmp); // (fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
} // fdf->map->x_max + 2,
// fdf->map->z_max + 2);
void initial_trnsf_mats(t_fdf *fdf) // mat4_translate(
{ // tf->tr,
t_trnsf *tf; // (float)((fdf->map->y_max > fdf->map->x_max) ?
// fdf->map->y_max : fdf->map->x_max) / 2.0f,
tf = trnsf_mat_init(); // (float)((fdf->map->y_max > fdf->map->x_max) ?
tf->vp = viewport_mat_init(fdf->w_width, fdf->w_height); // fdf->map->y_max : fdf->map->x_max) / 2.0f,
tf->pr = orth_mat_init( // (float)fdf->map->z_max / 2.0f);
(fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max : // mat4_x_rot(tf->xr, INIT_X);
fdf->map->x_max + 2, // mat4_z_rot(tf->zr, INIT_Z);
(fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max : // mat4_y_rot(tf->yr, INIT_Y);
fdf->map->x_max + 2, // mat4_scale(tf->sc, INIT_X_SCALE, INIT_Y_SCALE, INIT_Z_SCALE);
fdf->map->z_max + 2); // viewport_projection_translate(tf);
mat4_translate( // fdf->map->trnsf = tf;
tf->tr, //}
(float)((fdf->map->y_max > fdf->map->x_max) ?
fdf->map->y_max : fdf->map->x_max) / 2.0f,
(float)((fdf->map->y_max > fdf->map->x_max) ?
fdf->map->y_max : fdf->map->x_max) / 2.0f,
(float)fdf->map->z_max / 2.0f);
mat4_x_rot(tf->xr, INIT_X);
mat4_z_rot(tf->zr, INIT_Z);
mat4_y_rot(tf->yr, INIT_Y);
mat4_scale(tf->sc, INIT_X_SCALE, INIT_Y_SCALE, INIT_Z_SCALE);
viewport_projection_translate(tf);
fdf->map->trnsf = tf;
}
void mat4_mult_chain(t_trnsf *tf) void mat4_mult_chain(t_trnsf *tf)
{ {

View file

@ -12,84 +12,84 @@
#include "fractol.h" #include "fractol.h"
static int tab_to_color(t_color **color, char **tab) //static int tab_to_color(t_color **color, char **tab)
{ //{
int red; // int red;
int green; // int green;
int blue; // int blue;
//
// red = ft_atoi(tab[0]);
// green = ft_atoi(tab[1]);
// blue = ft_atoi(tab[2]);
// if (red > 255 || red < 0 ||
// green > 255 || green < 0 ||
// blue > 255 || blue < 0)
// return (0);
// (*color)->red = red;
// (*color)->green = green;
// (*color)->blue = blue;
// return (1);
//}
red = ft_atoi(tab[0]); //static void wrong_heatmap(t_color **low, t_color **high)
green = ft_atoi(tab[1]); //{
blue = ft_atoi(tab[2]); // ft_putstr("wrong heatmap! Type \"fdf --help\" for heatmap example\n");
if (red > 255 || red < 0 || // free(*low);
green > 255 || green < 0 || // free(*high);
blue > 255 || blue < 0) // *low = NULL;
return (0); // *high = NULL;
(*color)->red = red; //}
(*color)->green = green; //
(*color)->blue = blue; //static void parse_heatmap(char *hm, t_color **low, t_color **high)
return (1); //{
} // char **hm_tab;
// char **low_tab;
static void wrong_heatmap(t_color **low, t_color **high) // char **high_tab;
{ //
ft_putstr("wrong heatmap! Type \"fdf --help\" for heatmap example\n"); // *low = malloc(sizeof(t_color));
free(*low); // *high = malloc(sizeof(t_color));
free(*high); // hm_tab = ft_strsplit(hm, '-');
*low = NULL; // if ((tab_length(hm_tab) != 2))
*high = NULL; // {
} // wrong_heatmap(low, high);
// return ;
static void parse_heatmap(char *hm, t_color **low, t_color **high) // }
{ // low_tab = ft_strsplit(hm_tab[0], ',');
char **hm_tab; // high_tab = ft_strsplit(hm_tab[1], ',');
char **low_tab; // if (tab_length(low_tab) != 3 || tab_length(high_tab) != 3)
char **high_tab; // {
// wrong_heatmap(low, high);
*low = malloc(sizeof(t_color)); // return ;
*high = malloc(sizeof(t_color)); // }
hm_tab = ft_strsplit(hm, '-'); // if (!tab_to_color(low, low_tab) || !tab_to_color(high, high_tab))
if ((tab_length(hm_tab) != 2)) // {
{ // wrong_heatmap(low, high);
wrong_heatmap(low, high); // return ;
return ; // }
} //}
low_tab = ft_strsplit(hm_tab[0], ','); //
high_tab = ft_strsplit(hm_tab[1], ','); //void parse_input(int ac, char **av, t_fdf **fdf)
if (tab_length(low_tab) != 3 || tab_length(high_tab) != 3) //{
{ // t_color *low;
wrong_heatmap(low, high); // t_color *high;
return ; //
} // low = NULL;
if (!tab_to_color(low, low_tab) || !tab_to_color(high, high_tab)) // high = NULL;
{ // if ((ac < 2 || ac > 4) || (ac == 2 && ft_strstr(av[1], "--help")))
wrong_heatmap(low, high); // {
return ; // print_help();
} // quit(*fdf);
} // }
// else if (ac == 2)
void parse_input(int ac, char **av, t_fdf **fdf) // *fdf = fdf_init(av[1], low, high);
{ // else if (ac == 4 && ft_strstr(av[1], "--heatmap"))
t_color *low; // {
t_color *high; // parse_heatmap(av[2], &low, &high);
// *fdf = fdf_init(av[3], low, high);
low = NULL; // }
high = NULL; // else
if ((ac < 2 || ac > 4) || (ac == 2 && ft_strstr(av[1], "--help"))) // {
{ // print_help();
print_help(); // quit(*fdf);
quit(*fdf); // }
} //}
else if (ac == 2)
*fdf = fdf_init(av[1], low, high);
else if (ac == 4 && ft_strstr(av[1], "--heatmap"))
{
parse_heatmap(av[2], &low, &high);
*fdf = fdf_init(av[3], low, high);
}
else
{
print_help();
quit(*fdf);
}
}

View file

@ -12,31 +12,31 @@
#include "fractol.h" #include "fractol.h"
void render(t_fdf *fdf) //void render(t_fractol *fr)
{ //{
int i; // int i;
int j; // int j;
t_map *map; // t_map *map;
//
map = fdf->map; // map = fr->map;
i = 0; // i = 0;
while (i < map->y_max) // while (i < map->y_max)
{ // {
j = 0; // j = 0;
while (j < map->x_max) // while (j < map->x_max)
{ // {
if (i == map->y_max - 1 && j < map->x_max - 1) // if (i == map->y_max - 1 && j < map->x_max - 1)
line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], fdf); // line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], fr);
else if (i < map->y_max - 1 && j == map->x_max - 1) // else if (i < map->y_max - 1 && j == map->x_max - 1)
line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], fdf); // line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], fr);
else if (i < map->y_max - 1 && j < map->x_max - 1) // else if (i < map->y_max - 1 && j < map->x_max - 1)
{ // {
line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], fdf); // line(map->arr_pnt[i][j], map->arr_pnt[i + 1][j], fr);
line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], fdf); // line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], fr);
} // }
j++; // j++;
} // }
i++; // i++;
} // }
mlx_put_image_to_window(fdf->mw->mlx, fdf->mw->win, fdf->image, 0, 0); // mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
} //}