diff --git a/builds/draw_bonus.o b/builds/draw_bonus.o index 7388d65..85b997b 100644 Binary files a/builds/draw_bonus.o and b/builds/draw_bonus.o differ diff --git a/builds/fdf.o b/builds/fdf.o index f1b6398..41892e9 100644 Binary files a/builds/fdf.o and b/builds/fdf.o differ diff --git a/builds/keypress_bonus.o b/builds/keypress_bonus.o index 3d1367a..e61f364 100644 Binary files a/builds/keypress_bonus.o and b/builds/keypress_bonus.o differ diff --git a/builds/modifs.o b/builds/modifs.o index 28c1554..5e2dc56 100644 Binary files a/builds/modifs.o and b/builds/modifs.o differ diff --git a/builds/parse.o b/builds/parse.o index d65d0ff..3e39d85 100644 Binary files a/builds/parse.o and b/builds/parse.o differ diff --git a/fdf b/fdf index 4d0f1b8..ebedeac 100755 Binary files a/fdf and b/fdf differ diff --git a/includes/fdf.h b/includes/fdf.h index 4e4f3f9..20a54db 100644 --- a/includes/fdf.h +++ b/includes/fdf.h @@ -76,6 +76,11 @@ int **parse_map(t_fdf *fdf, int fd); // color for altitude # define COLOR_START 0xffffff # define COLOR_END 0x00d700 +// R,G,B colors +// ex for col = 0x236ad0 +# define COLOR_R(col) ((col & 0xff0000) >> 16) // output 23 +# define COLOR_G(col) ((col & 0x00ff00) >> 8) // output 6a +# define COLOR_B(col) (col & 0x0000ff) // output d0 # define ESCAPE 65307 # define UP 65362 diff --git a/libft b/libft index f32d4bb..603303a 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit f32d4bbc96af281afdb5c1443a54d185bd2f16e7 +Subproject commit 603303a21bd8485961a0159f0aeefa629604cb4c diff --git a/srcs/draw_bonus.c b/srcs/draw_bonus.c index 2e46947..677d36d 100644 --- a/srcs/draw_bonus.c +++ b/srcs/draw_bonus.c @@ -39,13 +39,27 @@ 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 X +// return the position of the point p // in percentage of the total height of the map : // z_min---start---point---end----z_max -// 0%--------s%-----P-------e%-----100% +// 0%--------s%-----p-------e%-----100% // line: ------------- // ex. . . . . . ---e // --- . @@ -117,7 +131,15 @@ void draw_lines(t_fdf *fdf, int *start, int *end) int dy; int i; int j; - int z; + 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) { @@ -134,28 +156,60 @@ ft_putnbr_fd(fdf->min_z,1); ft_putchar_fd(',',1); ft_putnbr_fd(fdf->max_z,1); ft_putchar_fd(')',1); -*/ +ft_putstr("\ndraw line\n"); +*/ i = 0; j = 0; while (ft_abs(i) <= ft_abs(dx) && ft_abs(j) <= ft_abs(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); + 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); + //draw_color_pixel(fdf, start[0] + i, start[1] + j, color); if (!ft_abs(dx) || ft_abs(j) < ft_abs(i * dy / dx)) j += ft_sign(dy); else i += ft_sign(dx); } } +/* +ft_putstr("\nEND line\n"); +*/ } -void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z) +int get_primary_color(char primar, int percent) { + int start_color; + int end_color; + int new_primary_color; + int offset; + + if ((primar == 'r') | (primar == 'R')) + offset = 16; + else if ((primar == 'g') | (primar == 'G')) + offset = 8; + else if ((primar == 'b') | (primar == 'B')) + offset = 0; + + start_color = (COLOR_START & (0x000000ff << offset)) >> offset; + end_color = (COLOR_END & (0x000000ff << offset)) >> offset; + + new_primary_color = (end_color - start_color) * percent / 100; + new_primary_color = start_color + new_primary_color; + 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 = COLOR_START; /* + color = COLOR_START; + color = 0x236ad0; + int color_start; int color_end; @@ -165,10 +219,59 @@ void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z) int color_g; int color_b; +// color masks +# define R_MASK 0xff0000 +# define G_MASK 0x00ff00 +# define B_MASK 0x0000ff + +start: 245 0 | 0 | ? 0 ?=0 | ? 50 ?=70 | ? 30 ?=42 | +end : 105 100 | 105-245=-140 | 140 100 | 140 100 | 140 100 | + +start: 245 0 | 0 | ? 0 ?=0 | ? 50 ?=-70 | ? 30 ?=-42 | +end : 105 100 | 105-245=-140 | -140 100 | -140 100 | -140 100 | + +start: 105 0 | 0 | ? 0 ?=0 | ? 50 ?=70 | ? 30 ?=42 | +end : 245 100 | 245-105=140 | 140 100 | 140 100 | 140 100 | + +(end - start) * percent / 100 + + +ft_putchar('['); +ft_putnbrbase(COLOR_START, "0123456789abcdef"); +ft_putchar(','); +ft_putnbrbase(COLOR_END, "0123456789abcdef"); +ft_putchar(','); +ft_putnbrbase(get_primary_color('r', percent), "0123456789abcdef"); +ft_putchar(','); +ft_putnbrbase(get_primary_color('g', percent), "0123456789abcdef"); +ft_putchar(','); +ft_putnbrbase(get_primary_color('b', percent), "0123456789abcdef"); +ft_putchar(','); +ft_putnbrbase((get_primary_color('r', percent)<<16) + (get_primary_color('g', percent)<<8) + get_primary_color('b', percent), "0123456789abcdef"); +ft_putchar(']'); +*/ + + /* + */ + 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; + +/* +ft_putchar('['); +ft_putnbr(percent); +ft_putchar(','); +ft_putnbrbase(color, "0123456789abcdef"); +ft_putchar(']'); +*/ + +/* +01 10 01 01 +00 11 11 11 +----------- +00 10 01 01 */ - 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;