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/mat4.c
src/color.c
src/fdf_init.c
src/fractol_init.c
src/hooks.c
src/image_routine.c
src/map_routine.c

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf.h :+: :+: :+: */
/* fractol.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
@ -10,16 +10,16 @@
/* */
/* ************************************************************************** */
#ifndef FDF_H
# define FDF_H
#ifndef FRACTOL_H
# define FRACTOL_H
# include "libft.h"
# include <mlx.h>
# include "mlx.h"
# include <math.h>
# include <fcntl.h>
# define HEIGHT 700
# define WIDTH 700
# define WIDTH 1300
# define COLOR1 0
# define COLOR2 16777215
# define INIT_X 30
@ -105,9 +105,8 @@ typedef struct s_map
float scale[3];
} t_map;
typedef struct s_fdf
typedef struct s_fractol
{
t_map *map;
t_mw *mw;
int w_height;
int w_width;
@ -116,9 +115,9 @@ typedef struct s_fdf
void *image;
char *image_data;
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);
void wrong_map(void);
@ -132,7 +131,7 @@ t_trnsf *trnsf_mat_init();
t_mat4 *viewport_mat_init(int x, int y);
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_translate(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);
void free_tab(char **tab);
void quit(t_fdf *fdf);
void quit(t_fractol *fractol);
void swap_init(t_swap *s);
void print_help(void);
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);
t_color choose_color(t_line *line, t_swap *s);
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);
void line(t_pnt p1, t_pnt p2, t_fdf *fdf);
void render(t_fdf *fdf);
void put_pixel_to_image(t_line *line, t_swap *s, t_fdf *fdf);
void line(t_pnt p1, t_pnt p2, t_fractol *fractol);
void render(t_fractol *fractol);
void put_pixel_to_image(int x, int y, t_color *col, t_fractol *fr);
void left_rot(t_fdf *fdf);
void right_rot(t_fdf *fdf);
void forw_rot(t_fdf *fdf);
void back_rot(t_fdf *fdf);
void clock_rot(t_fdf *fdf);
void aclock_rot(t_fdf *fdf);
void scale_up_z(t_fdf *fdf);
void scale_down_z(t_fdf *fdf);
void zoom_in(t_fdf *fdf);
void zoom_out(t_fdf *fdf);
void reset(t_fdf *fdf);
void move(t_fdf *fdf);
void left_rot(t_fractol *fractol);
void right_rot(t_fractol *fractol);
void forw_rot(t_fractol *fractol);
void back_rot(t_fractol *fractol);
void clock_rot(t_fractol *fractol);
void aclock_rot(t_fractol *fractol);
void scale_up_z(t_fractol *fractol);
void scale_down_z(t_fractol *fractol);
void zoom_in(t_fractol *fractol);
void zoom_out(t_fractol *fractol);
void reset(t_fractol *fractol);
void move(t_fractol *fractol);
#endif

View file

@ -12,6 +12,16 @@
#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 new;

View file

@ -1,7 +1,7 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf_init.c :+: :+: :+: */
/* fractol_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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))))
{
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);
}
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);
fdf->map->low = low;
fdf->map->high = high;
pnt_init(fdf->map);
fdf->w_height = HEIGHT;
fdf->w_width = WIDTH;
fdf->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT);
fdf->image = mlx_new_image(fdf->mw->mlx, WIDTH, HEIGHT);
fdf->image_data = mlx_get_data_addr(
fdf->image,
&fdf->bpp,
&fdf->line_size,
&fdf->endian);
fractol->w_height = HEIGHT;
fractol->w_width = WIDTH;
fractol->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT);
fractol->image = mlx_new_image(fractol->mw->mlx, WIDTH, HEIGHT);
fractol->image_data = mlx_get_data_addr(
fractol->image,
&fractol->bpp,
&fractol->line_size,
&fractol->endian);
}
return (fdf);
return (fractol);
}

View file

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

View file

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

View file

@ -12,20 +12,10 @@
#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;
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)
if (x < 0 || y < 0 || x >= fr->w_width || y >= fr->w_height)
return ;
*(int *)((fdf->image_data + x * fdf->bpp / 8 + y * fdf->line_size)) =
color_to_int(choose_color(line, s));
*(int *)((fr->image_data + x * fr->bpp / 8 + y * fr->line_size)) =
color_to_int(*col);
}

View file

@ -46,20 +46,22 @@ static void swap_points(t_pnt *p1, t_pnt *p2)
*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 dy;
int derr;
double dz;
t_color col;
col = int_to_color(COLOR2);
dx = abs(line->p2.x - line->p1.x);
dy = abs(line->p2.y - line->p1.y);
dz = fabs(line->p2.z - line->p1.z);
derr = 2 * dy - dx;
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)
{
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 dy;

View file

@ -11,19 +11,100 @@
/* ************************************************************************** */
#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)
{
t_fdf *fdf;
t_fractol *fr;
t_pnt pnt;
// int i;
fdf = NULL;
parse_input(argc, argv, &fdf);
center(fdf->map);
initial_trnsf_mats(fdf);
mat4_mult_chain(fdf->map->trnsf);
transform(fdf->map->trnsf->fin, fdf->map);
render(fdf);
mlx_hook(fdf->mw->win, 2, 5, key_hook, fdf);
mlx_loop(fdf->mw->mlx);
srand(time(NULL));
fr = NULL;
argc = argc;
argv = argv;
fr = fractol_init();
// while (pnt.y < fr->w_height)
// {
// pnt.x = 0;
// 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);
}

View file

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

View file

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

View file

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

View file

@ -22,45 +22,45 @@ void recalculate_trnsf_matrs(t_map *map)
INIT_Y_SCALE * map->scale[1],
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)
{
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);
}
void initial_trnsf_mats(t_fdf *fdf)
{
t_trnsf *tf;
tf = trnsf_mat_init();
tf->vp = viewport_mat_init(fdf->w_width, fdf->w_height);
tf->pr = orth_mat_init(
(fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
fdf->map->x_max + 2,
(fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
fdf->map->x_max + 2,
fdf->map->z_max + 2);
mat4_translate(
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 initial_trnsf_mats(t_fdf *fdf)
//{
// t_trnsf *tf;
//
// tf = trnsf_mat_init();
// tf->vp = viewport_mat_init(fdf->w_width, fdf->w_height);
// tf->pr = orth_mat_init(
// (fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
// fdf->map->x_max + 2,
// (fdf->map->y_max > fdf->map->x_max) ? fdf->map->y_max :
// fdf->map->x_max + 2,
// fdf->map->z_max + 2);
// mat4_translate(
// 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)
{

View file

@ -12,84 +12,84 @@
#include "fractol.h"
static int tab_to_color(t_color **color, char **tab)
{
int red;
int green;
int blue;
//static int tab_to_color(t_color **color, char **tab)
//{
// int red;
// int green;
// 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]);
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);
}
static void wrong_heatmap(t_color **low, t_color **high)
{
ft_putstr("wrong heatmap! Type \"fdf --help\" for heatmap example\n");
free(*low);
free(*high);
*low = NULL;
*high = NULL;
}
static void parse_heatmap(char *hm, t_color **low, t_color **high)
{
char **hm_tab;
char **low_tab;
char **high_tab;
*low = malloc(sizeof(t_color));
*high = malloc(sizeof(t_color));
hm_tab = ft_strsplit(hm, '-');
if ((tab_length(hm_tab) != 2))
{
wrong_heatmap(low, high);
return ;
}
low_tab = ft_strsplit(hm_tab[0], ',');
high_tab = ft_strsplit(hm_tab[1], ',');
if (tab_length(low_tab) != 3 || tab_length(high_tab) != 3)
{
wrong_heatmap(low, high);
return ;
}
if (!tab_to_color(low, low_tab) || !tab_to_color(high, high_tab))
{
wrong_heatmap(low, high);
return ;
}
}
void parse_input(int ac, char **av, t_fdf **fdf)
{
t_color *low;
t_color *high;
low = NULL;
high = NULL;
if ((ac < 2 || ac > 4) || (ac == 2 && ft_strstr(av[1], "--help")))
{
print_help();
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);
}
}
//static void wrong_heatmap(t_color **low, t_color **high)
//{
// ft_putstr("wrong heatmap! Type \"fdf --help\" for heatmap example\n");
// free(*low);
// free(*high);
// *low = NULL;
// *high = NULL;
//}
//
//static void parse_heatmap(char *hm, t_color **low, t_color **high)
//{
// char **hm_tab;
// char **low_tab;
// char **high_tab;
//
// *low = malloc(sizeof(t_color));
// *high = malloc(sizeof(t_color));
// hm_tab = ft_strsplit(hm, '-');
// if ((tab_length(hm_tab) != 2))
// {
// wrong_heatmap(low, high);
// return ;
// }
// low_tab = ft_strsplit(hm_tab[0], ',');
// high_tab = ft_strsplit(hm_tab[1], ',');
// if (tab_length(low_tab) != 3 || tab_length(high_tab) != 3)
// {
// wrong_heatmap(low, high);
// return ;
// }
// if (!tab_to_color(low, low_tab) || !tab_to_color(high, high_tab))
// {
// wrong_heatmap(low, high);
// return ;
// }
//}
//
//void parse_input(int ac, char **av, t_fdf **fdf)
//{
// t_color *low;
// t_color *high;
//
// low = NULL;
// high = NULL;
// if ((ac < 2 || ac > 4) || (ac == 2 && ft_strstr(av[1], "--help")))
// {
// print_help();
// 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"
void render(t_fdf *fdf)
{
int i;
int j;
t_map *map;
map = fdf->map;
i = 0;
while (i < map->y_max)
{
j = 0;
while (j < map->x_max)
{
if (i == map->y_max - 1 && j < map->x_max - 1)
line(map->arr_pnt[i][j], map->arr_pnt[i][j + 1], fdf);
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);
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][j + 1], fdf);
}
j++;
}
i++;
}
mlx_put_image_to_window(fdf->mw->mlx, fdf->mw->win, fdf->image, 0, 0);
}
//void render(t_fractol *fr)
//{
// int i;
// int j;
// t_map *map;
//
// map = fr->map;
// i = 0;
// while (i < map->y_max)
// {
// j = 0;
// while (j < map->x_max)
// {
// if (i == map->y_max - 1 && j < map->x_max - 1)
// 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)
// 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)
// {
// 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], fr);
// }
// j++;
// }
// i++;
// }
// mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
//}