fractol/src/fractal_routine.c
Gregory Tertyshny b399898721 norme check
2017-03-24 19:43:48 +02:00

68 lines
2.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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)
{
int x;
t_color col;
t_thread_data *data;
data = (t_thread_data *)th_data;
while (data->y_start < HEIGHT && data->y_start < data->y_end)
{
x = 0;
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);
x++;
}
data->y_start++;
}
free(data);
pthread_exit(NULL);
}
t_frac_data *frac_init(int frac_type)
{
t_frac_data *f;
f = malloc(sizeof(t_frac_data));
f->max_itr = FRAC_MAX_ITR;
f->grd = default_gradient();
if (frac_type == 0)
complex_equal(-0.4, 0.6, &f->com_const);
else
complex_equal(0, 0, &f->com_const);
f->com_rl_im_change = 1;
f->allow_mouse_change = -1;
f->mov.x = 0;
f->mov.y = 0;
f->mov.z = 1;
f->frac_type = frac_type;
return (f);
}
void fractal_fork(int frac_type)
{
t_fractol *fr;
fr = fractol_init(mlx_init(), 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_loop(fr->mlx);
}