color scheme almost there
This commit is contained in:
@@ -8,7 +8,5 @@ quick description
|
||||
### ressources
|
||||
|
||||
- minilibx : https://harm-smits.github.io/42docs/libs/minilibx
|
||||
|
||||
- draw a line : https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
||||
|
||||
- [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
|
||||
|
||||
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.
@@ -74,7 +74,8 @@ int **parse_map(t_fdf *fdf, int fd);
|
||||
# define Z_HEIGHT 10
|
||||
|
||||
// color for altitude
|
||||
# define Z_COLOR 0xffffff;
|
||||
# define COLOR_START 0xffffff
|
||||
# define COLOR_END 0x00d700
|
||||
|
||||
# define ESCAPE 65307
|
||||
# define UP 65362
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
0 0 0 0 0 1 2 3 4 5 5 5 5 5 5 5 5 5 4 3 2 1 0 0 0 0 0
|
||||
0 0 0 0 0 1 2 3 4 5 6 6 6 6 6 6 6 5 4 3 2 1 0 0 0 0 0
|
||||
0 0 0 0 0 1 2 3 4 5 6 7 7 7 7 7 6 5 4 3 2 1 0 0 0 0 0
|
||||
0 0 0 0 0 1 2 3 4 5 6 7 8,0xFFFFFF 8,0xFFFFFF 8,0xFFFFFF 7 6 5 4 3 2 1 0 0 0 0 0
|
||||
0 0 0 0 0 1 2 3 4 5 6 7 8,0xFFFFFF 8,0xFFFFFF 8,0xFFFFFF 7 6 5 4 3 2 1 0 0 0 0 0
|
||||
0 0 0 0 0 1 2 3 4 5 6 7 8,0xFFFFFF 8,0xFFFFFF 8,0xFFFFFF 7 6 5 4 3 2 1 0 0 0 0 0
|
||||
0 0 0 0 0 1 2 3 4 5 6 7 8,0xFFFFFF 8,0xFFFFFF 8,0xFFFFFF 7 6 5 4 3 2 1 0 0 0 0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||||
|
||||
@@ -39,27 +39,108 @@ void draw_grid(t_fdf *fdf, int i, int j)
|
||||
draw_lines(fdf, point_start, point_end);
|
||||
free(point_start);
|
||||
free(point_end);
|
||||
ft_putchar_fd('\n',1);
|
||||
}
|
||||
|
||||
// return the position of the point X
|
||||
// in percentage of the total height of the map :
|
||||
// z_min---start---point---end----z_max
|
||||
// 0%--------s%-----P-------e%-----100%
|
||||
// line: -------------
|
||||
// ex. . . . . . ---e
|
||||
// --- .
|
||||
// px. . . -p- .
|
||||
// ---. .
|
||||
// s-- . .
|
||||
// py ey
|
||||
// return value is 0 <= X <= 100
|
||||
// - z_total : z_max - z_min
|
||||
// - start : start
|
||||
// - 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 z_total;
|
||||
int start;
|
||||
int line;
|
||||
int percent;
|
||||
|
||||
z_total = fdf->z_amplitude;
|
||||
line = ft_abs(p_end[2] - p_start[2]);
|
||||
line *= 100;
|
||||
if (p_start[2] < p_end[2])
|
||||
{
|
||||
start = p_start[2] - fdf->min_z;
|
||||
start *= 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = p_end[2] - fdf->min_z;
|
||||
start *= 100;
|
||||
p_numerator = p_denominator - p_numerator;
|
||||
}
|
||||
percent = (start + line * p_numerator / p_denominator) / z_total;
|
||||
|
||||
/*
|
||||
if (percent > 100)
|
||||
{
|
||||
ft_putchar_fd('[',1);
|
||||
ft_putnbr_fd(z_total,1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(start,1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(line,1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(p_numerator,1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(p_denominator,1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(percent,1);
|
||||
ft_putchar_fd(']',1);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
start end min max z_total start line p_numerator p_denominator percent
|
||||
( 1, -1, -1, 1)[ 2, 200, 200, 16, 61, 126]
|
||||
( -1, 1, -1, 1)[ 2, 0, 200, -8, -7, 114]
|
||||
|
||||
percent = (start + line * p_numerator / p_denominator) / z_total;
|
||||
*/
|
||||
|
||||
return (percent);
|
||||
}
|
||||
|
||||
void draw_lines(t_fdf *fdf, int *start, int *end)
|
||||
{
|
||||
int dx;
|
||||
int dy;
|
||||
int z;
|
||||
int i;
|
||||
int j;
|
||||
int z;
|
||||
|
||||
if (end)
|
||||
{
|
||||
dx = end[0] - start[0];
|
||||
dy = end[1] - start[1];
|
||||
|
||||
/*
|
||||
ft_putchar_fd('(',1);
|
||||
ft_putnbr_fd(start[2],1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(end[2],1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(fdf->min_z,1);
|
||||
ft_putchar_fd(',',1);
|
||||
ft_putnbr_fd(fdf->max_z,1);
|
||||
ft_putchar_fd(')',1);
|
||||
*/
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
z = start[2];
|
||||
while (ft_abs(i) <= ft_abs(dx) && ft_abs(j) <= ft_abs(dy))
|
||||
{
|
||||
if ((dx + dy) && (i + j))
|
||||
z = start[2] + (end[2] - start[2]) * (i + j) / (dx + dy);
|
||||
z = 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, z);
|
||||
if (!ft_abs(dx) || ft_abs(j) < ft_abs(i * dy / dx))
|
||||
j += ft_sign(dy);
|
||||
@@ -72,21 +153,54 @@ 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)
|
||||
{
|
||||
int color;
|
||||
|
||||
color = COLOR_START;
|
||||
/*
|
||||
int color_start;
|
||||
int color_end;
|
||||
|
||||
color_start = COLOR_START;
|
||||
color_end = COLOR_END;
|
||||
int color_r;
|
||||
int color_g;
|
||||
int color_b;
|
||||
|
||||
*/
|
||||
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 16);
|
||||
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 8);
|
||||
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 0);
|
||||
|
||||
/*
|
||||
int color;
|
||||
|
||||
color = COLOR_START;
|
||||
z -= (z * fdf->zoom) / fdf->offset;
|
||||
z /= fdf->altitude;
|
||||
if (z > fdf->min_z && fdf->z_amplitude)
|
||||
{
|
||||
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 16);
|
||||
color = color ^ (((0xff / fdf->z_amplitude) * (z - fdf->min_z)) << 0);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
int color;
|
||||
int height;
|
||||
|
||||
color = Z_COLOR;
|
||||
color = COLOR_START;
|
||||
height = z;
|
||||
if (height != 0)
|
||||
height /= fdf->altitude;
|
||||
//height -= (height * fdf->zoom) / fdf->offset;
|
||||
height -= height / fdf->offset;
|
||||
if (height > fdf->min_z && fdf->z_amplitude)
|
||||
{
|
||||
color = color ^ (((0xff) * (height - fdf->min_z)) << 16);
|
||||
color = color ^ (((0xff) * (height - fdf->min_z)) << 0);
|
||||
//color = color ^ (((0xff / fdf->z_amplitude) * (height - fdf->min_z)) << 16);
|
||||
//color = color ^ (((0xff / fdf->z_amplitude) * (height - fdf->min_z)) << 0);
|
||||
// color = color ^ (((0xff / fdf->z_amplitude) * (height - fdf->min_z)) << 16);
|
||||
// color = color ^ (((0xff / fdf->z_amplitude) * (height - fdf->min_z)) << 0);
|
||||
}
|
||||
*/
|
||||
|
||||
draw_pixel(fdf, new_x, new_y, color);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user