-
Notifications
You must be signed in to change notification settings - Fork 0
/
mlx_manager.c
60 lines (53 loc) · 1.89 KB
/
mlx_manager.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx_manager.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kprytkov <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/06/10 20:19:17 by kprytkov #+# #+# */
/* Updated: 2018/06/10 20:19:18 by kprytkov ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/fractol.h"
t_map add_params(long double a, long double b,
long double c, long double d)
{
t_map p;
p.min_in = a;
p.max_in = b;
p.min_out = c;
p.max_out = d;
return (p);
}
long double ft_map(long double x, t_map p)
{
long double ret;
ret = p.min_out + (p.max_out - p.min_out) * ((x - p.min_in)
/ (p.max_in - p.min_in));
return (ret);
}
void put_pixel_to_img(t_env *e, int x, int y)
{
if ((x >= 0 || x <= WIDTH) && (y >= 0 || y <= HEIGHT))
{
e->image[(x * 4) + (y * WIDTH * 4) + 2] = e->red;
e->image[(x * 4) + (y * WIDTH * 4) + 1] = e->green;
e->image[(x * 4) + (y * WIDTH * 4)] = e->blue;
}
}
int init_mlx(t_env *e)
{
if ((e->mlx_ptr = mlx_init()) == NULL)
return (0);
if ((e->win_ptr = mlx_new_window(e->mlx_ptr, WIDTH, HEIGHT,
"hello, fractal")) == NULL)
return (0);
if ((e->image_ptr = mlx_new_image(e->mlx_ptr, WIDTH, HEIGHT)) == NULL)
return (0);
if ((e->image = mlx_get_data_addr(e->image_ptr,
&e->bpp, &e->ln, &e->en)) == NULL)
return (0);
e->bpp /= 8;
return (1);
}