adding gfx and ui stuff

This commit is contained in:
Daniel Ledda
2026-06-04 18:22:30 +02:00
parent d676c50961
commit 4dfac3f82f
48 changed files with 26734 additions and 3 deletions

42
gfx/Color.c Normal file
View File

@@ -0,0 +1,42 @@
#include "math.h"
#include "Color.h"
real32 hueToRGB(real32 p, real32 q, real32 t) {
if (t < 0) {
t += 1;
} else if (t > 1) {
t -= 1;
}
if (t < 1.0f / 6) return p + (q - p) * 6 * t;
if (t < 1.0f / 2) return q;
if (t < 2.0f / 3) return p + (q - p) * (2.0f / 3 - t) * 6;
return p;
};
Vec4 hslToHex(real32 h, real32 s, real32 l) {
h /= 360;
s /= 100;
l /= 100;
real32 r, g, b;
if (s == 0) {
r = g = b = l;
} else {
real32 q = l < 0.5f ? l * (1 + s) : l + s - l * s;
real32 p = 2 * l - q;
r = hueToRGB(p, q, h + 1.0f / 3);
g = hueToRGB(p, q, h);
b = hueToRGB(p, q, h - 1.0f / 3);
}
return (Vec4){r, g, b, 1};
}
Vec4 colorFromIndex(int index) {
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 hslToHex(hue, saturation, lightness);
}