-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdf.c
158 lines (137 loc) · 4.01 KB
/
fdf.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aouloube <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/12 14:56:56 by aouloube #+# #+# */
/* Updated: 2016/02/08 18:32:17 by aouloube ### ########.fr */
/* */
/* ************************************************************************** */
#include <mlx.h>
#include <stdio.h>
#include "libft/includes/libft.h"
#include <math.h>
typedef struct s_mlx
{
void *mlx;
void *win;
char **current_l;
char **next_l;
int offset;
int x;
int y;
} t_mlx;
int mlx_key_press(int keyword, void *param)
{
t_mlx *mlx;
mlx = (t_mlx *)param;
if (keyword == 53)
exit(0);
return (0);
}
void mlx_draw_point(t_mlx *mlx, int x, int y,int color, int offset, int nb)
{
mlx_pixel_put(mlx->mlx, mlx->win, (x - y) * (offset), (y + x) * (offset / 2) - (nb), color);
}
void mlx_draw_line_x(t_mlx *mlx, int x, int y,int color, int offset, int nb, int d)
{
mlx_pixel_put(mlx->mlx, mlx->win, (x - y) * (offset) + d, (y + x) * (offset / 2) + (d / 2) - (nb), color);
}
void mlx_draw_line_y(t_mlx *mlx, int x, int y,int color, int offset, int nb, int d)
{
mlx_pixel_put(mlx->mlx, mlx->win, (x - y) * (offset) - d, (y + x) * (offset / 2) + (d / 2) - (nb), color);
}
void ft_fdf(t_mlx *mlx ,char **argv)
{
char *line;
char **current_l;
char **next_l;
int fd;
int x;
int y;
int i;
int d;
fd = open(argv[1], O_RDONLY);
y = 0;
current_l = NULL;
next_l = NULL;
if (get_next_line(fd, &line))
next_l = ft_strsplit(line, ' ');
else
next_l = NULL;
while (next_l)
{
if (next_l)
current_l = next_l;
if (get_next_line(fd, &line) > 0)
next_l = ft_strsplit(line, ' ');
else
next_l = NULL;
x = mlx->offset / 2;
i = 0;
while(current_l[i])
{
if (ft_atoi(current_l[i]) != 0)
{
mlx_draw_point(mlx, x, y , 0X00BA3733, mlx->offset, ft_atoi(current_l[i]));
d = 1;
while (d < mlx->offset)
{
if(ft_atoi(current_l[i + 1]) == 10)
mlx_draw_line_x(mlx, x , y , 0X00BA3733, mlx->offset, ft_atoi(current_l[i]), d);
if(next_l && ft_atoi(next_l[i]) == ft_atoi(current_l[i]))
mlx_draw_line_y(mlx, x , y , 0X00BA3733, mlx->offset, ft_atoi(current_l[i]), d);
d++;
}
}
else
{
mlx_draw_point(mlx, x, y , 0X00FFFFFF, mlx->offset, ft_atoi(current_l[i]));
d = 1;
while (d < mlx->offset)
{
if(current_l[i + 1])
{
if(ft_atoi(current_l[i + 1]) == 10)
mlx_pixel_put(mlx->mlx, mlx->win, (x - y) * (mlx->offset) + d, ((y + x ) * ((mlx->offset) / 2) + ft_atoi(current_l[i])), 0X00FFFFF);
else
mlx_draw_line_x(mlx, x , y , 0X00FFFFFF, mlx->offset, ft_atoi(current_l[i]), d);
}
if(next_l)
{
//if(ft_atoi(next_l[i]) == 10)
// mlx_pixel_put(mlx->mlx, mlx->win, (x - y) * (mlx->offset) - d, (y + x ) * ((mlx->offset) / 2) + ( ft_atoi(current_l[i]) / 2) - (ft_atoi(current_l[i])) , 0X00FFFFF);
mlx_draw_line_y(mlx, x , y , 0X00FFFFFF, mlx->offset, ft_atoi(current_l[i]), d);
}
d++;
}
}
x++;
i++;
}
y++;
}
}
t_mlx *ft_mlx_init()
{
t_mlx *mlx;
mlx = (t_mlx *)malloc(sizeof(t_mlx *));
mlx->mlx = mlx_init();
mlx->win = mlx_new_window(mlx->mlx, 2000, 2000, "FDF by Afxsoft");
mlx->offset = 40;
return (mlx);
}
int main (int argc, char **argv)
{
t_mlx *mlx;
mlx = ft_mlx_init();
ft_fdf(mlx, argv);
printf("Fuck tha police");
argc = 0;
printf("Fuck tha police");
mlx_key_hook(mlx->win, mlx_key_press, mlx);
mlx_loop(mlx->mlx);
return (0);
}