There is no name on this code snippet, I don't recall where I grabbed it from.
You can simply call the function and it will display a colour picker.
Function ColorPick(x as integer, y as integer)
` feel free to load any image you want here
//imgBackdrop = LoadImage("colourBand.png")
yMin = y + 17
yMax = y + 17 + 255
cAlpha = 255
cRed = 255
cGreen = 255
cBlue = 255
sprBackground = CreateSprite(0)
SetSpritePosition(sprBackground, x, y)
SetSpriteSize(sprBackground, 294, 300)
SetSpriteColor(sprBackground, 128, 128, 128, 255)
sprMixerBackground = CreateSprite(0)
SetSpriteSize(sprMixerBackground, 100, 100)
SetSpritePosition(sprMixerBackground, x + 175, y + 12)
sprMixer = CreateSprite(0)
SetSpriteSize(sprMixer, 100, 100)
SetSpriteColor(sprMixer, cRed, cGreen, cBlue, cAlpha)
SetSpritePosition(sprMixer, x + 175, y + 12)
sprAccept = CreateSprite(0)
SetSpriteSize(sprAccept, 48, 20)
SetSpriteColor(sprAccept, 0, 255, 0, 255)
SetSpritePosition(sprAccept, x + 175, y + 262)
sprCancel = CreateSprite(0)
SetSpriteSize(sprCancel, 48, 20)
SetSpriteColor(sprCancel, 255, 0, 0, 255)
SetSpritePosition(sprCancel, x + 227, y + 262)
txtButtons = CreateText("OKAY QUIT")
SetTextSize(txtButtons, 16)
SetTextColor(txtButtons, 0, 0, 0, 255)
SetTextPosition(txtButtons, x + 180, y + 264)
sprTrack1 = CreateSprite(0)
SetSpriteSize(sprTrack1, 3, 256)
SetSpriteColor(sprTrack1, 200, 200, 200, 255)
SetSpritePosition(sprTrack1, x + 30, y + 22)
sprTrack2 = CloneSprite(sprTrack1)
SetSpritePosition(sprTrack2, x + 65, y + 22)
sprTrack3 = CloneSprite(sprTrack1)
SetSpritePosition(sprTrack3, x + 100, y + 22)
sprTrack4 = CloneSprite(sprTrack1)
SetSpritePosition(sprTrack4, x + 135, y + 22)
txtAlpha = CreateText("Alpha: " + str(cAlpha))
SetTextSize(txtAlpha, 16)
SetTextPosition(txtAlpha, x + 175, y + 120)
txtRed = CreateText("Red : " + str(cRed))
SetTextSize(txtRed, 16)
SetTextPosition(txtRed, x + 175, y + 136)
txtGreen = CreateText("Green: " + str(cGreen))
SetTextSize(txtGreen, 16)
SetTextPosition(txtGreen, x + 175, y + 152)
txtBlue = CreateText("Blue : " + str(cBlue))
SetTextSize(txtBlue, 16)
SetTextPosition(txtBlue, x + 175, y + 168)
txtHexLabel = CreateText("Hex:")
SetTextSize(txtHexLabel, 16)
SetTextPosition(txtHexLabel, x + 175, y + 188)
hAlpha$ = hex(cAlpha)
if len(hAlpha$) = 1 then hAlpha$ = "0" + hAlpha$
hRed$ = Hex(cRed)
if len(hRed$) = 1 then hRed$ = "0" + hRed$
hGreen$ = Hex(cGreen)
if len(hGreen$) = 1 then hGreen$ = "0" + hGreen$
hBlue$ = Hex(cBlue)
if len(hBlue$) = 1 then hBlue$ = "0" + hBlue$
hColor$ = hAlpha$ + hRed$ + hGreen$ + hBlue$
txtHex = CreateText(hColor$)
SetTextSize(txtHex, 16)
SetTextPosition(txtHex, x + 175, y + 204)
sprSliderA = CreateSprite(0)
SetSpriteSize(sprSliderA, 20, 10)
SetSpritePosition(sprSliderA, x + 22, y + 17)
sprSliderR = CloneSprite(sprSliderA)
SetSpritePosition(sprSliderR, x + 57, y + 17)
SetSpriteColor(sprSliderR, 255, 0, 0, 255)
sprSliderG = CloneSprite(sprSliderA)
SetSpritePosition(sprSliderG, x + 92, y + 17)
SetSpriteColor(sprSliderG, 0, 255, 0, 255)
sprSliderB = CloneSprite(sprSliderA)
SetSpritePosition(sprSliderB, x + 127, y + 17)
SetSpriteColor(sprSliderB, 0, 0, 255, 255)
`*** function input loop ***
do
if GetPointerState() = 1 AND GetSpriteHit(GetPointerX(), GetPointerY()) = sprSliderA
repeat
y# = GetPointerY()
if y# < yMin then y# = yMin
if y# > yMax then y# = yMax
SetSpritePosition(sprSliderA, x + 22, y#)
cAlpha = 255 - (y# - yMin)
hAlpha$ = hex(cAlpha)
if len(hAlpha$) = 1 then hAlpha$ = "0" + hAlpha$
hColor$ = hAlpha$ + hRed$ + hGreen$ + hBlue$
SetTextString(txtHex, hColor$)
SetSpriteColorAlpha(sprMixer, cAlpha)
SetTextString(txtAlpha, "Alpha: " + str(cAlpha))
sync()
until GetPointerState() = 0
endif
if GetPointerState() = 1 AND GetSpriteHit(GetPointerX(), GetPointerY()) = sprSliderR
repeat
y# = GetPointerY()
if y# < yMin then y# = yMin
if y# > yMax then y# = yMax
SetSpritePosition(sprSliderR, x + 57, y#)
cRed = 255 - (y# - yMin)
hRed$ = Hex(cRed)
if len(hRed$) = 1 then hRed$ = "0" + hRed$
hColor$ = hAlpha$ + hRed$ + hGreen$ + hBlue$
SetTextString(txtHex, hColor$)
SetSpriteColorRed(sprMixer, cRed)
SetTextString(txtRed, "Red : " + str(cRed))
sync()
until GetPointerState() = 0
endif
if GetPointerState() = 1 AND GetSpriteHit(GetPointerX(), GetPointerY()) = sprSliderG
repeat
y# = GetPointerY()
if y# < yMin then y# = yMin
if y# > yMax then y# = yMax
SetSpritePosition(sprSliderG, x + 92, y#)
cGreen = 255 - (y# - yMin)
hGreen$ = Hex(cGreen)
if len(hGreen$) = 1 then hGreen$ = "0" + hGreen$
hColor$ = hAlpha$ + hRed$ + hGreen$ + hBlue$
SetTextString(txtHex, hColor$)
SetSpriteColorGreen(sprMixer, cGreen)
SetTextString(txtGreen, "Green: " + str(cGreen))
sync()
until GetPointerState() = 0
endif
if GetPointerState() = 1 AND GetSpriteHit(GetPointerX(), GetPointerY()) = sprSliderB
repeat
y# = GetPointerY()
if y# < yMin then y# = yMin
if y# > yMax then y# = yMax
SetSpritePosition(sprSliderB, x + 127, y#)
cBlue = 255 - (y# - yMin)
hBlue$ = Hex(cBlue)
if len(hBlue$) = 1 then hBlue$ = "0" + hBlue$
hColor$ = hAlpha$ + hRed$ + hGreen$ + hBlue$
SetTextString(txtHex, hColor$)
SetSpriteColorBlue(sprMixer, cBlue)
SetTextString(txtBlue, "Blue : " + str(cBlue))
sync()
until GetPointerState() = 0
endif
if GetPointerReleased() = 1 AND GetSpriteHit(GetPointerX(), GetPointerY()) = sprAccept
hColor$ = hAlpha$ + hRed$ + hGreen$ + hBlue$
return$ = hColor$
exit
endif
if GetPointerReleased() = 1 AND GetSpriteHit(GetPointerX(), GetPointerY()) = sprCancel
return$ = "CANCELLED"
exit
endif
sync()
loop
`*** cleanup ***
//DeleteImage(imgBackdrop)
DeleteSprite(sprBackground)
DeleteSprite(sprMixerBackground)
DeleteSprite(sprTrack1)
DeleteSprite(sprTrack2)
DeleteSprite(sprTrack3)
DeleteSprite(sprTrack4)
DeleteSprite(sprMixer)
DeleteSprite(sprSliderA)
DeleteSprite(sprSliderR)
DeleteSprite(sprSliderG)
DeleteSprite(sprSliderB)
DeleteSprite(sprAccept)
DeleteSprite(sprCancel)
DeleteText(txtAlpha)
DeleteText(txtRed)
DeleteText(txtGreen)
DeleteText(txtBlue)
DeleteText(txtHexLabel)
DeleteText(txtHex)
DeleteText(txtButtons)
EndFunction return$
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt