color gradient fonctionne

This commit is contained in:
hugogogo
2021-07-19 10:58:09 +02:00
parent cb655a75d5
commit 30a86a32e5
4 changed files with 29 additions and 5 deletions

Binary file not shown.

BIN
fdf

Binary file not shown.

View File

@@ -61,6 +61,7 @@ typedef struct s_fdf
double rad_y; double rad_y;
int mov_x; int mov_x;
int mov_y; int mov_y;
int max_z;
int img_bpp; int img_bpp;
int img_sizel; int img_sizel;
int img_endian; int img_endian;

View File

@@ -9,6 +9,19 @@ int keypress(int keycode, t_fdf *fdf);
void rotation_state(t_fdf *fdf); void rotation_state(t_fdf *fdf);
int **parse_map(t_fdf *fdf); int **parse_map(t_fdf *fdf);
void color_altitude_pixel(t_fdf *fdf, int new_x, int new_y, int z)
{
int color;
color = 0xffffff;
if (z)
{
color = color ^ (((0xff * z) / fdf->max_z) << 8 );
color = color ^ ((0xff * z) / fdf->max_z);
}
draw_pixel(fdf, new_x, new_y, color);
}
void draw_image(t_fdf *fdf) void draw_image(t_fdf *fdf)
{ {
int i; int i;
@@ -34,12 +47,12 @@ void draw_image(t_fdf *fdf)
x = i * fdf->offset; x = i * fdf->offset;
y = j * fdf->offset; y = j * fdf->offset;
z = fdf->map[j][i]; z = fdf->map[j][i];
new_x = x * cos(fdf->rad_y) + y * sin(fdf->rad_y); new_x = x * cos(fdf->rad_x) + y * sin(fdf->rad_x);
new_y = y * cos(fdf->rad_y) - x * sin(fdf->rad_y); new_y = y * cos(fdf->rad_x) - x * sin(fdf->rad_x);
new_y = new_y * cos(fdf->rad_x) - z * sin(fdf->rad_x); new_y = new_y * cos(fdf->rad_y) - z * sin(fdf->rad_y);
new_x += fdf->margin + fdf->mov_x; new_x += fdf->margin + fdf->mov_x;
new_y += fdf->margin + fdf->mov_y; new_y += fdf->margin + fdf->mov_y;
draw_pixel(fdf, new_x, new_y, 0xffffff); color_altitude_pixel(fdf, new_x, new_y, z);
} }
} }
// put image on screen // put image on screen
@@ -179,7 +192,17 @@ int **parse_map(t_fdf *fdf)
while(++j < 15) while(++j < 15)
map[i][j] = 0; map[i][j] = 0;
} }
map[3][6] = 10; map[0][0] = 1;
map[1][0] = 2;
map[2][0] = 3;
map[3][0] = 4;
map[4][0] = 5;
map[5][0] = 6;
map[6][0] = 7;
map[7][0] = 8;
map[8][0] = 9;
map[9][0] = 10;
fdf->max_z = 10;
// size map // size map
fdf->map_width = j; fdf->map_width = j;
fdf->map_height = i; fdf->map_height = i;