Skip to content

Instantly share code, notes, and snippets.

@LightAtPlay
LightAtPlay / gist:24148d8be2e66d26fd11
Last active June 7, 2021 23:41
HSB/HSV to RGB converter and demo for OpenSCAD
function hsv(h, s = 1, v = 1, a = 1, p, q, t) = (p == undef || q == undef || t == undef)
? hsv(
(h%1) * 6,
s<0?0:s>1?1:s,
v<0?0:v>1?1:v,
a,
(v<0?0:v>1?1:v) * (1 - (s<0?0:s>1?1:s)),
(v<0?0:v>1?1:v) * (1 - (s<0?0:s>1?1:s) * ((h%1)*6-floor((h%1)*6))),
(v<0?0:v>1?1:v) * (1 - (s<0?0:s>1?1:s) * (1 - ((h%1)*6-floor((h%1)*6))))
)