02-26-2025, 01:13 AM
click the image to zoom in
Code:
'color wheel
'converted to N7
'https://rosettacode.org/wiki/Color_wheel#Go
#win32
set window "Color Wheel",500,500,false
set redraw off
visible tau = 2 * PI
visible r,g,b
'--------------
' main program
'--------------
set color 0,0,0; cls
colorWheel()
redraw
while not keydown(KEY_ESCAPE) fwait 60
'-----------
' functions
'------------
function hsb2rgb(hue, sat, bri)
'convert hue,saturation,brightness to RGB value
u = int(bri*255 + 0.5)
if sat = 0 then
r = u
g = u
b = u
else
h = (hue - floor(hue)) * 6
f = h - floor(h)
p = int(bri*(1-sat)*255 + 0.5)
q = int(bri*(1-sat*f)*255 + 0.5)
t = int(bri*(1-sat*(1-f))*255 + 0.5)
select int(h)
case 0
r = u; g = t; b = p
case 1
r = q; g = u; b = p
case 2
r = p ; g = u ; b = t
case 3
r = p ; g = q ; b = u
case 4
r = t ; g = p ; b = u
case 5
r = u ; g = p ; b = q
endsel
endif
endfunc
function colorWheel()
'calculate center and radius
centerX = width()/2
centerY = height()/2
radius = centerX-20
if centerY < radius then
radius = centerY-20
endif
'draw pixels for each RGB value
for y = 0 to height()
dy = (y - centerY)
for x = 0 to width()
dx = (x - centerX)
dist = sqr(dx*dx + dy*dy)
if dist <= radius then
theta = atan2(dy, dx)
hue = (theta + PI) / tau
hsb2rgb(hue, 1, 1)
set color r,g,b
set pixel x,y
endif
next
next
endfunc