Compare commits
4 Commits
colors
...
draw_limit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cebfe75798 | ||
|
|
98db1cc51a | ||
|
|
70261e3ecb | ||
|
|
be343771ee |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -49,5 +49,6 @@ Thumbs.db
|
||||
*.wmv
|
||||
|
||||
# c object files
|
||||
/builds/
|
||||
*.o
|
||||
fdf
|
||||
|
||||
|
||||
Binary file not shown.
BIN
builds/fdf.o
BIN
builds/fdf.o
Binary file not shown.
Binary file not shown.
BIN
builds/modifs.o
BIN
builds/modifs.o
Binary file not shown.
BIN
builds/parse.o
BIN
builds/parse.o
Binary file not shown.
@@ -54,6 +54,9 @@ void draw_grid(t_fdf *fdf, int i, int j);
|
||||
void draw_lines(t_fdf *fdf, int *start, int *end);
|
||||
void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z);
|
||||
void draw_pixel(t_fdf *fdf, int x, int y, int color);
|
||||
int is_outise_screen(t_fdf *fdf, int x, int y);
|
||||
int get_primary_color(char primar, int percent);
|
||||
int color_percent(t_fdf *fdf, int *p_start, int *p_end, int p_numerator, int p_denominator);
|
||||
|
||||
// keypress.c
|
||||
void keypress_more(int keycode, t_fdf *fdf);
|
||||
@@ -79,9 +82,9 @@ int **parse_map(t_fdf *fdf, int fd);
|
||||
// color for altitude
|
||||
# define COLOR_START 0xffffff
|
||||
/*
|
||||
# define COLOR_END 0x1423e6 // blue
|
||||
*/
|
||||
# define COLOR_END 0x00d700 // green
|
||||
*/
|
||||
# define COLOR_END 0x1423e6 // blue
|
||||
|
||||
// minimum time in milliseconds between two keypress
|
||||
# define DEBOUNCE_TIME 40
|
||||
|
||||
@@ -32,16 +32,44 @@ void draw_grid(t_fdf *fdf, int i, int j)
|
||||
if (i + 1 < fdf->map_width)
|
||||
point_end = new_coordinates(fdf, i + 1, j);
|
||||
draw_lines(fdf, point_start, point_end);
|
||||
free(point_end);
|
||||
point_end = NULL;
|
||||
if (j + 1 < fdf->map_height)
|
||||
{
|
||||
free(point_end);
|
||||
point_end = new_coordinates(fdf, i, j + 1);
|
||||
}
|
||||
draw_lines(fdf, point_start, point_end);
|
||||
free(point_start);
|
||||
free(point_end);
|
||||
}
|
||||
|
||||
void draw_lines(t_fdf *fdf, int *start, int *end)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
int i;
|
||||
int j;
|
||||
int percent;
|
||||
|
||||
if (end)
|
||||
{
|
||||
dx = end[0] - start[0];
|
||||
dy = end[1] - start[1];
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (ft_abs(i) <= ft_abs(dx) && ft_abs(j) <= ft_abs(dy))
|
||||
{
|
||||
if (!is_outise_screen(fdf, start[0] + i, start[1] + j))
|
||||
{
|
||||
percent = color_percent(fdf, start, end, ft_abs(i) + ft_abs(j), ft_abs(dx) + ft_abs(dy));
|
||||
draw_color_pixel(fdf, start[0] + i, start[1] + j, percent);
|
||||
}
|
||||
if (!ft_abs(dx) || ft_abs(j) < ft_abs(i * dy / dx))
|
||||
j += ft_sign(dy);
|
||||
else
|
||||
i += ft_sign(dx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return the position of the point p
|
||||
// in percentage of the total height of the map :
|
||||
// z_min---start---point---end----z_max
|
||||
@@ -59,7 +87,8 @@ void draw_grid(t_fdf *fdf, int i, int j)
|
||||
// - line : end - start
|
||||
// - p_numerator : px + py
|
||||
// - p_denominator : ex + ey
|
||||
int color_percent(t_fdf *fdf, int *p_start, int *p_end, int p_numerator, int p_denominator) {
|
||||
int color_percent(t_fdf *fdf, int *p_start, int *p_end, int p_numerator, int p_denominator)
|
||||
{
|
||||
int z_total;
|
||||
int start;
|
||||
int line;
|
||||
@@ -88,30 +117,18 @@ int color_percent(t_fdf *fdf, int *p_start, int *p_end, int p_numerator, int p_d
|
||||
return (percent);
|
||||
}
|
||||
|
||||
void draw_lines(t_fdf *fdf, int *start, int *end)
|
||||
void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int percent)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
int i;
|
||||
int j;
|
||||
int percent;
|
||||
int color_r;
|
||||
int color_g;
|
||||
int color_b;
|
||||
int color;
|
||||
|
||||
if (end)
|
||||
{
|
||||
dx = end[0] - start[0];
|
||||
dy = end[1] - start[1];
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (ft_abs(i) <= ft_abs(dx) && ft_abs(j) <= ft_abs(dy))
|
||||
{
|
||||
percent = color_percent(fdf, start, end, ft_abs(i) + ft_abs(j), ft_abs(dx) + ft_abs(dy));
|
||||
draw_color_pixel(fdf, start[0] + i, start[1] + j, percent);
|
||||
if (!ft_abs(dx) || ft_abs(j) < ft_abs(i * dy / dx))
|
||||
j += ft_sign(dy);
|
||||
else
|
||||
i += ft_sign(dx);
|
||||
}
|
||||
}
|
||||
color_r = get_primary_color('r', percent);
|
||||
color_g = get_primary_color('g', percent);
|
||||
color_b = get_primary_color('b', percent);
|
||||
color = (color_r << 16) + (color_g << 8) + color_b;
|
||||
draw_pixel(fdf, new_x, new_y, color);
|
||||
}
|
||||
|
||||
int get_primary_color(char primar, int percent)
|
||||
@@ -136,30 +153,24 @@ int get_primary_color(char primar, int percent)
|
||||
return (new_primary_color);
|
||||
}
|
||||
|
||||
void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int percent)
|
||||
{
|
||||
int color_r;
|
||||
int color_g;
|
||||
int color_b;
|
||||
int color;
|
||||
|
||||
color_r = get_primary_color('r', percent);
|
||||
color_g = get_primary_color('g', percent);
|
||||
color_b = get_primary_color('b', percent);
|
||||
color = (color_r << 16) + (color_g << 8) + color_b;
|
||||
draw_pixel(fdf, new_x, new_y, color);
|
||||
}
|
||||
|
||||
void draw_pixel(t_fdf *fdf, int x, int y, int color)
|
||||
{
|
||||
int position;
|
||||
|
||||
if (is_outise_screen(fdf, x, y))
|
||||
return ;
|
||||
position = y * fdf->img_sizel + x * fdf->img_bpp / 8;
|
||||
*(unsigned int *)(fdf->img_addr + position) = color;
|
||||
}
|
||||
|
||||
int is_outise_screen(t_fdf *fdf, int x, int y)
|
||||
{
|
||||
int xmax;
|
||||
int ymax;
|
||||
|
||||
xmax = fdf->img_sizel / (fdf->img_bpp / 8);
|
||||
ymax = fdf->img_size_y;
|
||||
if (x < 0 || y < 0 || x > xmax || y > ymax)
|
||||
return ;
|
||||
position = y * fdf->img_sizel + x * fdf->img_bpp / 8;
|
||||
*(unsigned int *)(fdf->img_addr + position) = color;
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user