norme check

This commit is contained in:
Gregory Tertyshny 2017-03-24 19:43:48 +02:00
parent a4097c80f8
commit b399898721
16 changed files with 207 additions and 92 deletions

View file

@ -20,7 +20,6 @@
# include <pthread.h> # include <pthread.h>
# include <time.h> # include <time.h>
# include <unistd.h> # include <unistd.h>
# include <stdio.h>
# define HEIGHT 700 # define HEIGHT 700
# define WIDTH 1300 # define WIDTH 1300
@ -115,7 +114,6 @@ void parse_input(int ac, char **av);
t_color gradient(float value, t_gradient gradient); t_color gradient(float value, t_gradient gradient);
t_gradient default_gradient(void); t_gradient default_gradient(void);
t_gradient random_gradient(void); t_gradient random_gradient(void);
int color_to_int(t_color c);
t_fractol *fractol_init(void *mlx, int frac_type); t_fractol *fractol_init(void *mlx, int frac_type);

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* burning_ship.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:36:06 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:36:26 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
int complex_ship(t_complex new, t_complex com_const, t_frac_data *data) int complex_ship(t_complex new, t_complex com_const, t_frac_data *data)

View file

@ -22,11 +22,6 @@ t_color int_to_color(int c)
return (new); return (new);
} }
int color_to_int(t_color c)
{
return ((c.red << 16) | (c.grn << 8) | c.blu);
}
t_gradient default_gradient(void) t_gradient default_gradient(void)
{ {
t_gradient grad; t_gradient grad;
@ -59,18 +54,33 @@ t_gradient random_gradient(void)
return (grad); return (grad);
} }
t_color pick_color(t_color c1, t_color c2, float frac)
{
t_color c;
c.red = (int)((c2.red - c1.red) * frac + c1.red);
c.blu = (int)((c2.blu - c1.blu) * frac + c1.blu);
c.grn = (int)((c2.grn - c1.grn) * frac + c1.grn);
return (c);
}
t_color gradient(float value, t_gradient grad) t_color gradient(float value, t_gradient grad)
{ {
int id1; int id1;
int id2; int id2;
float frac; float frac;
t_color c;
frac = 0; frac = 0;
if (value <= 0) if (value <= 0)
id1 = id2 = 0; {
id1 = 0;
id2 = 0;
}
else if (value >= 1) else if (value >= 1)
id1 = id2 = NUM_COLORS - 1; {
id1 = NUM_COLORS - 1;
id2 = NUM_COLORS - 1;
}
else else
{ {
value = value * (NUM_COLORS - 1); value = value * (NUM_COLORS - 1);
@ -78,9 +88,5 @@ t_color gradient(float value, t_gradient grad)
id2 = id1 + 1; id2 = id1 + 1;
frac = value - (float)id1; frac = value - (float)id1;
} }
c.red = (grad.grd[id2].red - grad.grd[id1].red) * frac + grad.grd[id1].red; return (pick_color(grad.grd[id1], grad.grd[id2], frac));
c.blu = (grad.grd[id2].blu - grad.grd[id1].blu) * frac + grad.grd[id1].blu;
c.grn = (grad.grd[id2].grn - grad.grd[id1].grn) * frac + grad.grd[id1].grn;
return (c);
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* complex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:36:44 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:36:47 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
void complex_equal(double real, double imag, t_complex *c) void complex_equal(double real, double imag, t_complex *c)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractal_routine.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:37:32 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:37:33 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
void *fractal_routine(void *th_data) void *fractal_routine(void *th_data)

View file

@ -5,8 +5,8 @@
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/16 18:55:39 by gtertysh #+# #+# */ /* Created: 2017/03/24 19:31:38 by gtertysh #+# #+# */
/* Updated: 2017/03/16 18:56:00 by gtertysh ### ########.fr */ /* Updated: 2017/03/24 19:31:42 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -14,7 +14,6 @@
int key_hook(int keycode, void *fr) int key_hook(int keycode, void *fr)
{ {
printf("%d\n", keycode);
if (keycode == 53) if (keycode == 53)
quit(fr); quit(fr);
if (keycode == 49) if (keycode == 49)
@ -35,7 +34,7 @@ int key_hook(int keycode, void *fr)
} }
/* /*
* beware!! shitcode on lines 48-49. ** beware!! shitcode on lines 48-49.
*/ */
int mouse_move_hook(int x, int y, void *fr) int mouse_move_hook(int x, int y, void *fr)
@ -46,7 +45,6 @@ int mouse_move_hook( int x, int y, void *fr)
to_render = 0; to_render = 0;
y = to_render; y = to_render;
printf("x = %d, y = %d\n", x, y);
to_render = y; to_render = y;
fr_p = (t_fractol *)fr; fr_p = (t_fractol *)fr;
if (fr_p->frac->com_rl_im_change == 1 && if (fr_p->frac->com_rl_im_change == 1 &&
@ -60,14 +58,12 @@ int mouse_move_hook( int x, int y, void *fr)
new_and_clear_image(fr_p); new_and_clear_image(fr_p);
parallel_fractal(fr_p); parallel_fractal(fr_p);
mlx_put_image_to_window(fr_p->mlx, fr_p->win, fr_p->img->ptr, 0, 0); mlx_put_image_to_window(fr_p->mlx, fr_p->win, fr_p->img->ptr, 0, 0);
} }
return (0); return (0);
} }
int mouse_button_hook(int btn, int x, int y, void *fr) int mouse_button_hook(int btn, int x, int y, void *fr)
{ {
printf("x = %d, y = %d, btn = %d\n", x, y, btn);
if (btn == 4) if (btn == 4)
zoom_in(fr, x, y); zoom_in(fr, x, y);
if (btn == 5) if (btn == 5)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks_funcs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:21:45 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:21:46 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
void gradient_hook(t_fractol *fr) void gradient_hook(t_fractol *fr)

View file

@ -1,8 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks_funcs_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:29:07 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:29:08 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
void move_down(t_fractol *fr) void move_down(t_fractol *fr)
{ {
printf("z %Lf\n", fr->frac->mov.z);
fr->frac->mov.y += 1.f / fr->frac->mov.z * 0.2; fr->frac->mov.y += 1.f / fr->frac->mov.z * 0.2;
new_and_clear_image(fr); new_and_clear_image(fr);
parallel_fractal(fr); parallel_fractal(fr);
@ -11,7 +22,6 @@ void move_down(t_fractol *fr)
void move_up(t_fractol *fr) void move_up(t_fractol *fr)
{ {
printf("z %Lf\n", fr->frac->mov.z);
fr->frac->mov.y -= 1.f / fr->frac->mov.z * 0.2; fr->frac->mov.y -= 1.f / fr->frac->mov.z * 0.2;
new_and_clear_image(fr); new_and_clear_image(fr);
parallel_fractal(fr); parallel_fractal(fr);

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks_funcs_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:26:53 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:28:31 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
void zoom_in(t_fractol *fr, int x, int y) void zoom_in(t_fractol *fr, int x, int y)
@ -9,11 +21,12 @@ void zoom_in(t_fractol *fr, int x, int y)
center_y = HEIGHT / 2; center_y = HEIGHT / 2;
new_and_clear_image(fr); new_and_clear_image(fr);
fr->frac->mov.z *= 1.5; fr->frac->mov.z *= 1.5;
fr->frac->mov.x += ((float)x - center_x) / (center_x * fr->frac->mov.z) * 0.8; fr->frac->mov.x += ((float)x - center_x) / (center_x * fr->frac->mov.z)
fr->frac->mov.y += ((float)y - center_y) / (center_y * fr->frac->mov.z) * 0.8; * 0.8;
fr->frac->mov.y += ((float)y - center_y) / (center_y * fr->frac->mov.z)
* 0.8;
parallel_fractal(fr); parallel_fractal(fr);
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0); mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
} }
void zoom_out(t_fractol *fr) void zoom_out(t_fractol *fr)
@ -22,12 +35,10 @@ void zoom_out(t_fractol *fr)
fr->frac->mov.z /= 2; fr->frac->mov.z /= 2;
parallel_fractal(fr); parallel_fractal(fr);
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0); mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
} }
void move_left(t_fractol *fr) void move_left(t_fractol *fr)
{ {
printf("z %Lf\n", fr->frac->mov.z);
fr->frac->mov.x -= 1.f / fr->frac->mov.z * 0.2; fr->frac->mov.x -= 1.f / fr->frac->mov.z * 0.2;
new_and_clear_image(fr); new_and_clear_image(fr);
parallel_fractal(fr); parallel_fractal(fr);
@ -36,7 +47,6 @@ void move_left(t_fractol *fr)
void move_right(t_fractol *fr) void move_right(t_fractol *fr)
{ {
printf("z %Lf\n", fr->frac->mov.z);
fr->frac->mov.x += 1.f / fr->frac->mov.z * 0.2; fr->frac->mov.x += 1.f / fr->frac->mov.z * 0.2;
new_and_clear_image(fr); new_and_clear_image(fr);
parallel_fractal(fr); parallel_fractal(fr);

View file

@ -27,10 +27,10 @@ void new_and_clear_image(t_fractol *fr)
} }
} }
void put_pixel_to_image(int x, int y, t_color col, t_fractol *fr) void put_pixel_to_image(int x, int y, t_color c, t_fractol *fr)
{ {
if (x < 0 || y < 0 || x >= fr->w_width || y >= fr->w_height) if (x < 0 || y < 0 || x >= fr->w_width || y >= fr->w_height)
return ; return ;
*(int *)((fr->img->data + x * fr->img->bpp / 8 + y * fr->img->l_size)) = *(int *)((fr->img->data + x * fr->img->bpp / 8 + y * fr->img->l_size)) =
color_to_int(col); (c.red << 16) | (c.grn << 8) | c.blu;
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* julia.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:34:44 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:34:46 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
int complex_jul(t_complex new, t_complex com_const, t_frac_data *data) int complex_jul(t_complex new, t_complex com_const, t_frac_data *data)
@ -28,4 +40,3 @@ t_color julia(t_frac_data *ju, int x, int y)
i = complex_jul(new, ju->com_const, ju); i = complex_jul(new, ju->com_const, ju);
return (gradient((float)i / ju->max_itr, ju->grd)); return (gradient((float)i / ju->max_itr, ju->grd));
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mandelbrot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:33:30 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:33:56 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
int complex_man(t_complex new, t_complex com_const, t_frac_data *data) int complex_man(t_complex new, t_complex com_const, t_frac_data *data)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:32:10 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:32:11 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include <fractol.h> #include <fractol.h>
int check_argument(char *arg) int check_argument(char *arg)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* threads_routine.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:35:25 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:35:26 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
t_thread_data *thread_data_init(t_fractol *fr, int i) t_thread_data *thread_data_init(t_fractol *fr, int i)