This commit is contained in:
Daniel Ledda
2025-01-04 19:19:01 +01:00
parent 256292c20d
commit 50f4501c86
11 changed files with 3213 additions and 1484 deletions

View File

@@ -2,7 +2,7 @@
#include <math.h>
#include "../lib/djstdlib/core.h"
real32 hue_to_rgb(float p, float q, float t) {
real32 hue_to_rgb(real32 p, real32 q, real32 t) {
if (t < 0) {
t += 1;
} else if (t > 1) {
@@ -18,12 +18,12 @@ glm::vec3 hsl_to_hex(real32 h, real32 s, real32 l) {
h /= 360;
s /= 100;
l /= 100;
float r, g, b;
real32 r, g, b;
if (s == 0) {
r = g = b = l;
} else {
auto q = l < 0.5f ? l * (1 + s) : l + s - l * s;
auto p = 2 * l - q;
real32 q = l < 0.5f ? l * (1 + s) : l + s - l * s;
real32 p = 2 * l - q;
r = hue_to_rgb(p, q, h + 1.0f / 3);
g = hue_to_rgb(p, q, h);
b = hue_to_rgb(p, q, h - 1.0f / 3);
@@ -32,12 +32,12 @@ glm::vec3 hsl_to_hex(real32 h, real32 s, real32 l) {
}
glm::vec3 color_from_index(int index) {
auto color_wheel_cycle = floorf(index / 6.0f);
auto darkness_cycle = floorf(index / 12.0f);
auto spacing = (360.0f / 6.0f);
auto offset = color_wheel_cycle == 0 ? 0 : spacing / (color_wheel_cycle + 2);
auto hue = spacing * (index % 6) + offset;
auto saturation = 100.0f;
auto lightness = 1.0f / (2 + darkness_cycle) * 100;
real32 color_wheel_cycle = floorf(index / 6.0f);
real32 darkness_cycle = floorf(index / 12.0f);
real32 spacing = (360.0f / 6.0f);
real32 offset = color_wheel_cycle == 0 ? 0 : spacing / (color_wheel_cycle + 2);
real32 hue = spacing * (index % 6) + offset;
real32 saturation = 100.0f;
real32 lightness = 1.0f / (2 + darkness_cycle) * 100;
return hsl_to_hex(hue, saturation, lightness);
}