colors gradient is fonctionning

This commit is contained in:
asus
2024-01-11 16:53:16 +01:00
parent c54a0a1a63
commit fe23ce3f31
8 changed files with 2751 additions and 37 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
fdf

Binary file not shown.

View File

@@ -1,4 +1,5 @@
#include "fdf.h"
#include <stdio.h>
void draw_image(t_fdf *fdf)
{
@@ -39,21 +40,6 @@ void draw_grid(t_fdf *fdf, int i, int j)
draw_lines(fdf, point_start, point_end);
free(point_start);
free(point_end);
/*
const char c = 'w';
const int n = 23;
const char *s = "hello";
ft_putchar(c); ft_putchar_fd(',',1);
ft_putchar_fd(c, 1); ft_putchar_fd('\n',1);
ft_putnbr(n); ft_putchar_fd(',',1);
ft_putnbr_fd(n, 1); ft_putchar_fd('\n',1);
ft_putstr(s); ft_putchar_fd(',',1);
ft_putstr_fd(s, 1); ft_putchar_fd('\n',1);
ft_putnbrbase(n, "01"); ft_putchar_fd(',',1);
ft_putnbrbase_fd(n, "01", 1); ft_putchar_fd('\n',1);
ft_putchar_fd('\n',1);
*/
}
// return the position of the point p
@@ -80,23 +66,26 @@ int color_percent(t_fdf *fdf, int *p_start, int *p_end, int p_numerator, int p_d
int percent;
z_total = fdf->z_amplitude;
line = ft_abs(p_end[2] - p_start[2]);
line = ft_abs(p_end[3] - p_start[3]);
line *= 100;
if (p_start[2] < p_end[2])
if (p_start[3] < p_end[3])
{
start = p_start[2] - fdf->min_z;
start = p_start[3] - fdf->min_z;
start *= 100;
}
else
{
start = p_end[2] - fdf->min_z;
start = p_end[3] - fdf->min_z;
start *= 100;
p_numerator = p_denominator - p_numerator;
}
percent = (start + line * p_numerator / p_denominator) / z_total;
if (p_denominator != 0)
percent = (start + line * p_numerator / p_denominator) / z_total;
else
percent = 0;
/*
if (percent > 100)
if (ft_abs(percent) > 100)
{
ft_putchar_fd('[',1);
ft_putnbr_fd(z_total,1);
@@ -118,6 +107,7 @@ if (percent > 100)
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]
( 2, 0, -1, 1)[ 2, 100, 200, 61, 61, 150]
percent = (start + line * p_numerator / p_denominator) / z_total;
*/
@@ -133,14 +123,6 @@ void draw_lines(t_fdf *fdf, int *start, int *end)
int j;
int percent;
/*
int color_r, color_g, color_b;
color_r = rand() % 0xff + 1;
color_g = rand() % 0xff + 1;
color_b = rand() % 0xff + 1;
int color = (color_r << 16) + (color_g << 8) + color_b;
*/
if (end)
{
dx = end[0] - start[0];
@@ -258,13 +240,16 @@ ft_putchar(']');
color_b = get_primary_color('b', percent);
color = (color_r << 16) + (color_g << 8) + color_b;
/*
ft_putchar('[');
ft_putnbr(percent);
ft_putchar(',');
ft_putnbrbase(color, "0123456789abcdef");
ft_putchar(']');
*/
/*
if (ft_abs(percent) > 100)
{
ft_putchar('[');
ft_putnbr(percent);
ft_putchar(',');
ft_putnbrbase(color, "0123456789abcdef");
ft_putchar(']');
}
*/
/*
01 10 01 01

View File

@@ -24,7 +24,7 @@ int *new_coordinates(t_fdf *fdf, int i, int j)
int height;
int *point;
point = ft_calloc(3, sizeof(int));
point = ft_calloc(4, sizeof(int));
x = i * (fdf->offset + fdf->zoom);
y = j * (fdf->offset + fdf->zoom);
x -= (fdf->map_size_x + fdf->zoom * fdf->map_width) / 2;
@@ -45,6 +45,7 @@ int *new_coordinates(t_fdf *fdf, int i, int j)
point[0] += (fdf->map_size_x + fdf->zoom * fdf->map_width) / 2;
point[1] += (fdf->map_size_y + fdf->zoom * fdf->map_height) / 2;
point[2] = z;
point[3] = fdf->map[j][i];
return (point);
}

2728
tmp.txt Normal file

File diff suppressed because it is too large Load Diff