Color Wheel - 1micha.elok - 02-26-2025
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
RE: Color Wheel - kevin - 02-26-2025
Very good - thanks for sharing.
RE: Color Wheel - johnno56 - 02-27-2025
Cool... Well done.
RE: Color Wheel - Marcus - 03-01-2025
Very nice!
I might add an alternative "color picker" to ngui using that for hue selection. The current one uses a rectangle where the horizontal axis represents hue and the vertical saturation. With a hue wheel you'd need two sliders to control the saturation and brightness, right? But I think it would be easier to use than the current color picker:
Code: include "ngui.n7"
set window "Color picker", 640, 480
set redraw off
root = VBox(SIZE_EXPAND, SIZE_EXPAND)
root.SetHalign(ALIGN_CENTER)
root.SetSpacing(8)
colorPicker = ColorPicker(function(wdg, r, g, b)
pln "Selected color: " + r + ", " + g + ", " + b
endfunc)
root.Add(Header("Color picker", SIZE_AUTO, SIZE_AUTO))
root.Add(colorPicker)
EnterMainLoop(root)
RE: Color Wheel - kevin - 03-01-2025
That is so user friendly, and the code is so compact. Very impressive......
RE: Color Wheel - johnno56 - 03-01-2025
Impressive. Most impressive. Obi-wan has taught you well...
RE: Color Wheel - 1micha.elok - 03-02-2025
(03-01-2025, 07:38 AM)Marcus Wrote: ...
"color picker" to ngui
...
click the image to zoom in
Oh, color picker, help me see,
The perfect shades to set games free
For NAALAA devs, you light the way
With colors bright, no more delay
|