-
Notifications
You must be signed in to change notification settings - Fork 0
/
fractol_depth_array.c
99 lines (90 loc) · 1.94 KB
/
fractol_depth_array.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol_depth_array.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpeters <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/14 00:08:41 by tpeters #+# #+# */
/* Updated: 2022/08/06 21:19:47 by tpeters ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void init_depth_array(int **in)
{
int c;
int d;
c = 0;
while (c < WIDTH)
{
d = 0;
while (d < HEIGHT)
{
in[c][d] = -1;
d++;
}
c++;
}
}
void move_array(t_vars *vars, int hor, int ver)
{
int c;
int d;
if (hor <= 0)
c = 0;
else
c = WIDTH - 1;
while (c >= 0 && c < WIDTH)
{
if (ver <= 0)
d = 0;
else
d = HEIGHT - 1;
while (d >= 0 && d < HEIGHT)
{
if (c - hor >= 0 && c - hor < WIDTH && \
d - ver >= 0 && d - ver < HEIGHT)
vars->depths[c][d] = vars->depths[c - hor][d - ver];
else
vars->depths[c][d] = -1;
d += -1 + (ver <= 0) * 2;
}
c += -1 + (hor <= 0) * 2;
}
}
int **alloc_depth(void)
{
int **tmp;
int c;
tmp = (int **)malloc(sizeof(int *) * WIDTH);
if (!tmp)
return (NULL);
c = 0;
while (c < WIDTH)
{
tmp[c] = (int *)malloc(sizeof(int) * HEIGHT);
if (!tmp)
{
while (c > 0)
{
free(tmp[c - 1]);
c--;
}
free(tmp);
return (NULL);
}
c++;
}
return (tmp);
}
void free_depth(int **in)
{
int c;
c = 0;
while (c < WIDTH)
{
free(in[c]);
c++;
}
free(in);
}