aboutsummaryrefslogtreecommitdiff
path: root/src/render.c
blob: a2171250fcf61c0a676c2286078b25ae8f165ca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   render.c                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/24 09:54:59 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/25 15:30:07 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "fractol.h"

/* static void	*st_render_routine(t_state *state) */
/* { */
/* 	return (NULL); */
/* } */

static void	st_render_fractal(t_state *state)
{
	int	offset;
	int	i;
	int	j;
	t_color	color;
	t_complex	z;
	/* pthread_t	threads[WINDOW_HEIGHT */
	int tmp;

	color.hexcode = 0xffffff;
	offset = 0;
	i = -1;
	while (++i < WINDOW_HEIGHT)
	{
		j = -1;
		while (++j < WINDOW_WIDTH)
		{
			z.r = ((double)j / (double)WINDOW_WIDTH)  * state->plane.r - (state->plane.r / 2.0) + state->center.r;
			z.i = ((double)i / (double)WINDOW_HEIGHT) * state->plane.i - (state->plane.i / 2.0) + state->center.i;
			tmp = state->func(state, z);
			/* if (tmp > state->iterations) */
			/* 	((t_color*)state->window.data)[offset].hexcode = 0x000000; */
			/* else */
	/* for (int i = 0; i < state->iterations; i++) */
		/* printf("%d %d %d\n", state->palette[tmp].rgb.r, state->palette[tmp].rgb.g, state->palette[tmp].rgb.b); */
				((t_color*)state->window.data)[offset] = state->palette[tmp];
			offset++;
		}
	}
}

int			render_update(t_state *state)
{
	if (!state->running)
	{
		state_destroy(state);
		exit(EXIT_SUCCESS);
	}
	if (state->updated)
		return (0);
	st_render_fractal(state);
	mlx_put_image_to_window(state->mlx_ptr, state->window_ptr, state->window.id, 0, 0);
	state->updated = true;
	return (0);
}