norme check
This commit is contained in:
parent
a4097c80f8
commit
b399898721
16 changed files with 207 additions and 92 deletions
|
@ -20,7 +20,6 @@
|
|||
# include <pthread.h>
|
||||
# include <time.h>
|
||||
# include <unistd.h>
|
||||
# include <stdio.h>
|
||||
|
||||
# define HEIGHT 700
|
||||
# define WIDTH 1300
|
||||
|
@ -115,7 +114,6 @@ void parse_input(int ac, char **av);
|
|||
t_color gradient(float value, t_gradient gradient);
|
||||
t_gradient default_gradient(void);
|
||||
t_gradient random_gradient(void);
|
||||
int color_to_int(t_color c);
|
||||
|
||||
t_fractol *fractol_init(void *mlx, int frac_type);
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
int complex_ship(t_complex new, t_complex com_const, t_frac_data *data)
|
||||
|
@ -11,7 +23,7 @@ int complex_ship(t_complex new, t_complex com_const, t_frac_data *data)
|
|||
old = new;
|
||||
new.rl = fabsl(old.rl * old.rl - old.im * old.im + com_const.rl);
|
||||
new.im = fabsl(2 * old.rl * old.im + com_const.im);
|
||||
if((new.rl * new.rl + new.im * new.im) > 4)
|
||||
if ((new.rl * new.rl + new.im * new.im) > 4)
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
|
|
36
src/color.c
36
src/color.c
|
@ -22,11 +22,6 @@ t_color int_to_color(int c)
|
|||
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 grad;
|
||||
|
@ -59,18 +54,33 @@ t_gradient random_gradient(void)
|
|||
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)
|
||||
{
|
||||
int id1;
|
||||
int id2;
|
||||
float frac;
|
||||
t_color c;
|
||||
|
||||
frac = 0;
|
||||
if(value <= 0)
|
||||
id1 = id2 = 0;
|
||||
else if(value >= 1)
|
||||
id1 = id2 = NUM_COLORS - 1;
|
||||
if (value <= 0)
|
||||
{
|
||||
id1 = 0;
|
||||
id2 = 0;
|
||||
}
|
||||
else if (value >= 1)
|
||||
{
|
||||
id1 = NUM_COLORS - 1;
|
||||
id2 = NUM_COLORS - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = value * (NUM_COLORS - 1);
|
||||
|
@ -78,9 +88,5 @@ t_color gradient(float value, t_gradient grad)
|
|||
id2 = id1 + 1;
|
||||
frac = value - (float)id1;
|
||||
}
|
||||
c.red = (grad.grd[id2].red - grad.grd[id1].red) * frac + grad.grd[id1].red;
|
||||
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);
|
||||
return (pick_color(grad.grd[id1], grad.grd[id2], frac));
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
void complex_equal(double real, double imag, t_complex *c)
|
||||
|
|
|
@ -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"
|
||||
|
||||
void *fractal_routine(void *th_data)
|
||||
|
@ -10,7 +22,7 @@ void *fractal_routine(void *th_data)
|
|||
while (data->y_start < HEIGHT && data->y_start < data->y_end)
|
||||
{
|
||||
x = 0;
|
||||
while(x < data->fr.w_width)
|
||||
while (x < data->fr.w_width)
|
||||
{
|
||||
col = data->fractal_func(data->fr.frac, x, data->y_start);
|
||||
put_pixel_to_image(x, data->y_start, col, &data->fr);
|
||||
|
@ -50,7 +62,7 @@ void fractal_fork(int frac_type)
|
|||
parallel_fractal(fr);
|
||||
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
|
||||
mlx_hook(fr->win, 2, 5, key_hook, fr);
|
||||
mlx_hook(fr->win, 6, (1L<<6), mouse_move_hook, fr);
|
||||
mlx_hook(fr->win, 4, (1L<<0), mouse_button_hook, fr);
|
||||
mlx_hook(fr->win, 6, (1L << 6), mouse_move_hook, fr);
|
||||
mlx_hook(fr->win, 4, (1L << 0), mouse_button_hook, fr);
|
||||
mlx_loop(fr->mlx);
|
||||
}
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:55:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/16 18:56:00 by gtertysh ### ########.fr */
|
||||
/* Created: 2017/03/24 19:31:38 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/24 19:31:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
10
src/hooks.c
10
src/hooks.c
|
@ -14,7 +14,6 @@
|
|||
|
||||
int key_hook(int keycode, void *fr)
|
||||
{
|
||||
printf("%d\n", keycode);
|
||||
if (keycode == 53)
|
||||
quit(fr);
|
||||
if (keycode == 49)
|
||||
|
@ -35,10 +34,10 @@ 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)
|
||||
{
|
||||
static int start_x = WIDTH / 2;
|
||||
int to_render;
|
||||
|
@ -46,7 +45,6 @@ int mouse_move_hook( int x, int y, void *fr)
|
|||
|
||||
to_render = 0;
|
||||
y = to_render;
|
||||
printf("x = %d, y = %d\n", x, y);
|
||||
to_render = y;
|
||||
fr_p = (t_fractol *)fr;
|
||||
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);
|
||||
parallel_fractal(fr_p);
|
||||
mlx_put_image_to_window(fr_p->mlx, fr_p->win, fr_p->img->ptr, 0, 0);
|
||||
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
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)
|
||||
zoom_in(fr, x, y);
|
||||
if (btn == 5)
|
||||
|
|
|
@ -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"
|
||||
|
||||
void gradient_hook(t_fractol *fr)
|
||||
|
|
|
@ -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"
|
||||
|
||||
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;
|
||||
new_and_clear_image(fr);
|
||||
parallel_fractal(fr);
|
||||
|
@ -11,7 +22,6 @@ void move_down(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;
|
||||
new_and_clear_image(fr);
|
||||
parallel_fractal(fr);
|
||||
|
@ -36,7 +46,7 @@ void reset(t_fractol *fr)
|
|||
|
||||
void change_limit_up(t_fractol *fr)
|
||||
{
|
||||
fr->frac->max_itr +=50;
|
||||
fr->frac->max_itr += 50;
|
||||
new_and_clear_image(fr);
|
||||
parallel_fractal(fr);
|
||||
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
|
||||
|
|
|
@ -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"
|
||||
|
||||
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;
|
||||
new_and_clear_image(fr);
|
||||
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.y += ((float)y - center_y) / (center_y * fr->frac->mov.z) * 0.8;
|
||||
fr->frac->mov.x += ((float)x - center_x) / (center_x * fr->frac->mov.z)
|
||||
* 0.8;
|
||||
fr->frac->mov.y += ((float)y - center_y) / (center_y * fr->frac->mov.z)
|
||||
* 0.8;
|
||||
parallel_fractal(fr);
|
||||
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
void zoom_out(t_fractol *fr)
|
||||
|
@ -22,12 +35,10 @@ void zoom_out(t_fractol *fr)
|
|||
fr->frac->mov.z /= 2;
|
||||
parallel_fractal(fr);
|
||||
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
new_and_clear_image(fr);
|
||||
parallel_fractal(fr);
|
||||
|
@ -36,7 +47,6 @@ void move_left(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;
|
||||
new_and_clear_image(fr);
|
||||
parallel_fractal(fr);
|
||||
|
|
|
@ -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)
|
||||
return ;
|
||||
*(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;
|
||||
}
|
||||
|
|
15
src/julia.c
15
src/julia.c
|
@ -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"
|
||||
|
||||
int complex_jul(t_complex new, t_complex com_const, t_frac_data *data)
|
||||
|
@ -11,7 +23,7 @@ int complex_jul(t_complex new, t_complex com_const, t_frac_data *data)
|
|||
old = new;
|
||||
new.rl = old.rl * old.rl - old.im * old.im + com_const.rl;
|
||||
new.im = 2 * old.rl * old.im + com_const.im;
|
||||
if((new.rl * new.rl + new.im * new.im) > 4)
|
||||
if ((new.rl * new.rl + new.im * new.im) > 4)
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
|
@ -28,4 +40,3 @@ t_color julia(t_frac_data *ju, int x, int y)
|
|||
i = complex_jul(new, ju->com_const, ju);
|
||||
return (gradient((float)i / ju->max_itr, ju->grd));
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
int complex_man(t_complex new, t_complex com_const, t_frac_data *data)
|
||||
|
@ -11,7 +23,7 @@ int complex_man(t_complex new, t_complex com_const, t_frac_data *data)
|
|||
old = new;
|
||||
new.rl = old.rl * old.rl - old.im * old.im + com_const.rl;
|
||||
new.im = 2 * old.rl * old.im + com_const.im;
|
||||
if((new.rl * new.rl + new.im * new.im) > 4)
|
||||
if ((new.rl * new.rl + new.im * new.im) > 4)
|
||||
break ;
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
||||
int check_argument(char *arg)
|
||||
|
|
|
@ -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"
|
||||
|
||||
t_thread_data *thread_data_init(t_fractol *fr, int i)
|
||||
|
|
Loading…
Add table
Reference in a new issue