Hi all,
Sharing some code I made one of my projects. It's a colour wheel maker using no media. Also included in this code is a colour picker adapted from the UCF thread (I think).
rem
rem AGK Application
rem
rem set up display
setVirtualResolution(getDeviceWidth(),getDeviceHeight())
setClearColor(50,50,50)
rem create a colorwheel image slightly smaller than the device size
img = createColorWheelImage(min(getDeviceWidth(),getDeviceHeight())-2)
rem create a sprite from this image
spr = createSprite(img)
setSpritePositionByOffset(spr,getDeviceWidth()*0.5,getDeviceHeight()*0.5)
rem A baxslash Did It!
do
rem pick a colour from the screen
if getPointerReleased()>0
col$ = pickColor(getPointerX(),getPointerY())
message(col$)
endif
Sync()
loop
function createColorWheelImage(size#)
rem set up data
w = size#
cx = w/2
cy = w/2
rem create image
clearScreen()
setScissor(0,0,w,w)
`
spr = createSprite(0)
setSpriteSize(spr,1,1)
setSpriteAngle(spr,45)
`
ang# = 0
in# = 1.0/(size#/20.0)
repeat
rem set red value
r# = 0.0
v# = abs(wrap180(360-ang#))
if v#<120
if v#<=60
r# = 255.0
else
r# = (1.0-((v#-60)/60.0))*255
endif
endif
rem set green value
g# = 0.0
v# = abs(wrap180(120-ang#))
if v#<120
if v#<=60
g# = 255.0
else
g# = (1.0-((v#-60)/60.0))*255
endif
endif
rem set blue value
b# = 0.0
v# = abs(wrap180(240-ang#))
if v#<120
if v#<=60
b# = 255.0
else
b# = (1.0-((v#-60)/60.0))*255
endif
endif
rem paint colour spoke
fw# = w
tot = w*0.5 - 2
for i=1 to tot
rem set lightness
fi# = i
f# = fi#/(fw#*0.5)
if f#>0.5
f# = 1.0 - (f#-0.5)/0.5
thisR# = f#*r#
thisG# = f#*g#
thisB# = f#*b#
else
f# = 1.0 - f#/0.5
thisR# = r# + (255.0-r#)*f#
thisG# = g# + (255.0-g#)*f#
thisB# = b# + (255.0-b#)*f#
endif
rem paint sprite
setSpriteColor(spr,thisR#,thisG#,thisB#,255)
setSpritePositionByOffset(spr,cx+1+sin(ang#)*fi#,cy+1-cos(ang#)*fi#)
drawSprite(spr)
next
ang# = ang# + in#
until ang#>360.0
`
deleteSprite(spr)
`
img = getImage(0,0,w,w)
`
setScissor(0,0,getDeviceWidth(),getDeviceHeight())
clearScreen()
endfunction img
Function pickColor(X,Y)
rem prepare image grab area
clearScreen()
setScissor(X,Y,X+1,Y+1)
render()
rem get image
img = getImage(x,y,1,1)
rem create memblock
mem = createMemblockfromImage(img)
rem get memblock data
r = getMemblockbyte(mem,12)
g = getMemblockbyte(mem,13)
b = getMemblockbyte(mem,14)
s$ = str(r)+","+str(g)+","+str(b)
rem tidy up
deletememblock(mem)
deleteimage(img)
setScissor(0,0,getDeviceWidth(),getDeviceHeight())
clearScreen()
endfunction s$
function wrap180(v#)
while v#>180.0
v# = v# - 360.0
endwhile
while v#<-180.0
v# = v# + 360.0
endwhile
endfunction v#
function min(v1#,v2#)
if v1#<v2#
v# = v1#
else
v# = v2#
endif
endfunction v#
function max(v1#,v2#)
if v1#>v2#
v# = v1#
else
v# = v2#
endif
endfunction v#
The function will create a colour wheel image that can easily be used to select a colour for whatever reason. It should contain pretty much any available colour but it might be tricky to get an exact colour, therefore you should use it in conjunction with something else if you want something more exact.
Here's an example of the image produced.
"Everything should be made as simple as possible, but not simpler."