aUCBLogo Demos and Tests / hsbtest
to hsbtest
cs ht setsc 0
disls
setpensize [1 1]
brightness=1
repeat 100
[ sat=repcount/100
pu lt 90 fd 360 rt 180 pd
repeat 360
[ hue=repcount*1-1
;c=hsb2 hue sat brightness
;setpc rgb c.1 c.2 c.3
setpc hsb hue sat brightness
fd 2
]
pu lt 180 fd 360 rt 90 pd
pu fd 1 pd
]
end
to hsb2 :h :s :b_
local [h2 L x y z r g b]
h=(mod :h 360)/120
h2=mod :h 1
ifelse h2 < 0.5
[ L=b_*(1+s*h2)
s=s/(1+s*h2) ;s>0, h2>0 always so never s/0
x=1+(-1-h2)*s y=1-h2*s z=1-(1-h2)*s
][ L=b_*(1+s*(1-h2))
s=s/(1+s*(1-h2))
y=1-h2*s z=1-(1-h2)*s x=1-(2-h2)*s
]
x=x*L y=y*L z=z*L
ifelse :h < 1
[ b=x r=y g=z
][ ifelse :h < 2
[ r=x g=y b=z
][ g=x b=y r=z
]
]
if r < 0 [r=0]
if g < 0 [g=0]
if b < 0 [b=0]
if r > 1 [r=1]
if g > 1 [g=1]
if b > 1 [b=1]
output (list r g b)
end