From c5008a4e62fb83eb71f5f94f622c01f2d8fe8b6b Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 22 Sep 2019 11:44:30 +0200 Subject: Supersampling - Random supersampling (prettier but quite slow) - WIP: bette color gradient --- helper.c | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'helper.c') diff --git a/helper.c b/helper.c index 0290563..3e02182 100644 --- a/helper.c +++ b/helper.c @@ -1,22 +1,48 @@ #include #include "header.h" +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define MIN(x, y) ((x) < (y) ? (x) : (y)) +#define MIN3(x, y, z) (MIN(x, MIN(y, z))) + double map_range(double x, double src_lo, double src_hi, double dest_lo, double dest_hi) { - double src_len = fabs(src_hi - src_lo); - double dest_len = fabs(dest_hi - dest_lo); - + double src_len = src_hi - src_lo; + double dest_len = dest_hi - dest_lo; return (x - src_lo) / src_len * dest_len + dest_lo; } -int *inclusive_range(int start, int end) +Color helper_HSL_to_RGB(int hue, double saturation, double lightness) +{ + /* double chroma = (1 - fabs(2 * lightness - 1)) * saturation; */ + /* int hue_p = hue / 60; */ + /* double x = chroma * (1 - abs(hue_p % 2 - 1)); */ + Color color; + + /* if (hue == 0) */ + /* { */ + /* color.hexcode = 0x000000; */ + /* return color; */ + /* } */ + /* */ + /* if (hue_p */ + + double a = saturation * MIN(lightness, 1 - lightness); + int kn0 = (0 + hue / 30) % 12; + int kn8 = (8 + hue / 30) % 12; + int kn4 = (4 + hue / 30) % 12; + Byte f0 = lightness - a * MAX(MIN3(kn0 - 3, 9 - kn0, 1), -1); + Byte f8 = lightness - a * MAX(MIN3(kn8 - 3, 9 - kn8, 1), -1); + Byte f4 = lightness - a * MAX(MIN3(kn4 - 3, 9 - kn4, 1), -1); + + color.rgb.r = f0; + color.rgb.g = f8; + color.rgb.b = f4; + + return color; +} + +double double_rand(void) { - if (end < start) - return NULL; - int *range = malloc(sizeof(int) * (end - start + 1)); - if (range == NULL) - return NULL; - for (int i = 0; start < end; i++) - range[i] = start++; - return range; + return (double)rand() / RAND_MAX; } -- cgit