fractol/src/julia.c
Gregory Tertyshny 8e9693a2be pthread
2017-03-21 20:50:44 +02:00

84 lines
No EOL
1.7 KiB
C

#include "fractol.h"
int complex_parallel(t_complex new, t_complex com_const)
{
int i;
t_complex old;
i = 0;
while (i < JUL_MAX_ITER)
{
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)
break ;
i++;
}
return (i);
}
void *julia_computation(void *fr)
{
t_complex new;
t_julia *ju;
int i;
int x;
int y;
ju = ((t_fractol *)fr)->fractals->jul;
x = ju->x;
y = ju->y;
new.rl = 1.5 * (x - WIDTH / 2) / (0.5 * ju->mov.z * WIDTH) + ju->mov.x;
new.im = (y - HEIGHT / 2) / (0.5 * ju->mov.z * HEIGHT) + ju->mov.y;
i = complex_parallel(new, ju->jul_const);
ju->color = int_to_color(rainbow(i, ju->max_itr));
put_pixel_to_image(x, y, &((t_fractol *)fr)->fractals->jul->color, fr);
return (0);
}
//void julia_parralel(t_fractol *fr)
//{
// pthread_t threads[NUM_THREADS];
// t_fractol *fr_tmp;
// int rc;
// int i;
//
// i = 0;
// while (i < NUM_THREADS && fr->fractals->jul->y < fr->w_width)
// {
// fr_tmp = malloc(sizeof(t_fractol));
// *fr_tmp = *fr;
//// printf("In main: creating thread %d\n", i);
// rc = pthread_create(&threads[i], NULL, julia_computation, (void *)fr_tmp);
// if (rc){
// printf("ERROR; return code from pthread_create() is %d\n", rc);
// exit(-1);
// }
// free(fr_tmp);
// fr->fractals->jul->y++;
// i++;
// }
//}
void draw_julia(t_fractol *fr)
{
int x;
int y;
new_and_clear_image(fr);
y = 0;
while (y < fr->w_height)
{
x = 0;
while(x < fr->w_width)
{
fr->fractals->jul->x = x;
fr->fractals->jul->y = y;
julia_computation(fr);
x++;
}
y++;
}
mlx_put_image_to_window(fr->mw->mlx, fr->mw->win, fr->image, 0, 0);
}