-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfractol_pixel_utils.c
100 lines (91 loc) · 2.59 KB
/
fractol_pixel_utils.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol_pixel_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpeters <tpeters@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/10 20:01:47 by tpeters #+# #+# */
/* Updated: 2022/08/06 22:14:35 by tpeters ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int coord_to_offset(int x, int y, int line_length, int bits_per_pixel)
{
return (y * line_length + x * (bits_per_pixel / 8));
}
void put_pixels(t_vars *vars, int x, int y, int i)
{
if (vars->depths[x][y] < vars->max_depth)
{
if (vars->depths[x][y] >= 0)
{
put_pixel(&vars->img, x, y,
depth_to_col(vars, (double)vars->depths[x][y], i));
}
else
{
put_pixel(&vars->img, x, y,
new_color(255, 255, 255, vars->img.endi));
}
}
else
put_pixel(&vars->img, x, y, new_color(0, 0, 0, vars->img.endi));
}
static void bf_pixl(struct s_for_each_pixel *s, int *dep, double xt, double yt)
{
struct s_fract_arguments fs;
if (*dep == -1)
{
fs.depth_max = s->vars->max_depth;
fs.x = xt;
fs.y = yt;
fs.xn = s->vars->xn;
fs.yn = s->vars->yn;
if (s->f == mandel)
{
fs.xn = 0;
fs.yn = 0;
}
*dep = s->f(&fs);
}
}
static int bf_and_put_all_pixels(struct s_for_each_pixel *stuff, int i)
{
int x;
int y;
double xtrans;
double ytrans;
xtrans = stuff->vars->xmin;
ytrans = stuff->vars->ymax;
x = 0;
while (x < WIDTH)
{
y = 0;
ytrans = stuff->vars->ymax;
while (y < HEIGHT)
{
bf_pixl(stuff, &(stuff->vars->depths[x][y]), xtrans, ytrans);
put_pixels(stuff->vars, x, y, i);
ytrans -= stuff->vars->y_len / HEIGHT;
y++;
}
xtrans += stuff->vars->x_len / WIDTH;
x++;
}
return (mlx_put_image_to_window(stuff->vars->mlx, stuff->vars->win,
stuff->vars->img.img, 0, 0));
}
int for_each_pixel(struct s_for_each_pixel *stuff)
{
static int i;
struct s_rect_args s_args;
i++;
s_args.stuff = stuff;
s_args.x1 = 0;
s_args.y1 = 0;
s_args.x2 = WIDTH - 1;
s_args.y2 = HEIGHT - 1;
rec_box(&s_args);
return (bf_and_put_all_pixels(stuff, i));
}