Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Color Wheel
#1
   
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
Reply


Messages In This Thread
Color Wheel - by 1micha.elok - 02-26-2025, 01:13 AM
RE: Color Wheel - by kevin - 02-26-2025, 02:43 PM
RE: Color Wheel - by johnno56 - 02-27-2025, 08:23 PM
RE: Color Wheel - by Marcus - 03-01-2025, 07:38 AM
RE: Color Wheel - by 1micha.elok - 03-02-2025, 11:35 PM
RE: Color Wheel - by kevin - 03-01-2025, 03:14 PM
RE: Color Wheel - by johnno56 - 03-01-2025, 08:12 PM

Forum Jump:


Users browsing this thread: 6 Guest(s)