Detecting RED, GREEN & BLue in pixels

Started by kevin, January 24, 2007, 05:56:07 AM

Previous topic - Next topic

kevin

 This little example shows how you can detect if a pixel RGB colour has any RED, GREEN or BLUE in it

PlayBASIC Code: [Select]
 Do
cls 0

CircleC 100,100,50,true,Rgb(255,0,0)

CircleC 200,100,50,true,Rgb(0,255,0)

CircleC 300,100,50,true,Rgb(0,0,255)


CircleC 100,200,50,true,Rgb(155,100,0)

CircleC 200,200,50,true,Rgb(0,255,233)

CircleC 300,200,50,true,Rgb(255,255,255)


mx=mousex()
my=mousey()

if IsColourRed(mx,my)=false
Print "No RED in this pixel"
else
Print "Yep, this pixel has BLUE in it"
endif

if IsColourGreen(mx,my)=false
Print "No GREEN in this pixel"
else
Print "Yep, this pixel has GREEN in it"
endif


if IsColourBlue(mx,my)=false
Print "No BLUE in this pixel"
else
Print "Yep, this pixel has BLUE in it"
endif


Sync
loop




Function IsColourRed(Xpos,Ypos)
; Grab the Pixel
ThisPixel=Point(xpos,Ypos)

; check if it's RED level is above 0
if rgbR(ThisPixel)>0
result=true
endif

EndFunction result


Function IsColourGreen(Xpos,Ypos)
if rgbG(Point(xpos,Ypos))>0 then result=1
EndFunction result

Function IsColourBlue(Xpos,Ypos)
if rgbG(Point(xpos,Ypos))>0 then result=1
EndFunction result