This stems from my attempts to generate random changing colours. Using (R,G,B) creates 256 x 256 x 256 possibilities, many of which didn’t suit what I wanted, which was punchy saturated colours. By looking at RGB values when Saturation & Brightness are both 100% for different Hues, I mapped it down to 256. The code is pretty self explanatory, and function Hue(0-255) will generate appropriate R, G, B, Hue values in text window and on screen.
But I’m sure there is probably a MUCH more efficient way of coding it that this… is there?
function setup()
h = 0
parameter.integer("h",0,255,125)
end
function Hue(h)
if h < 43 then
r,g = 255,0
b = 6*h
end
if h > 42 and h < 86 then
g,b = 0,255
r = 510 - 6*h
end
if h > 85 and h < 128 then
r,b = 0,255
g = 6*(h-85)
end
if h > 127 and h < 171 then
r,g= 0,255
b = 1020 - 6*h
end
if h > 170 and h < 213 then
g,b = 255,0
r = 6*h -1020
end
if h > 212 then
r,b = 255,0
g = 1530 - 6*h
end
end
function draw()
Hue(h)
print(r, g, b, h)
background(r,g,b)
end