|
|
|
Image Flood Fill (Using getPixel and setPixel)
Added on 10/6/1999
|
This behavior uses the undocumented setPixel and getPixel functions to flood fill an image.
--------- flood fill color in bitmap to random color
--------- Jakob Hede Madsen
--------- hede@image.dk
--------- special thanks: Roy Pardi
property pPctRef
property pSprLeft
property pSprTop
property pSprScalarX
property pSprScalarY
property pPixelActorListX
property pPixelActorListY
property pSpreadListX
property pSpreadListY
---------------
on beginSprite me
mySpr = sprite me.spriteNum
pPctRef = mySpr.member
pSprLeft = mySpr.left
pSprTop = mySpr.top
pSprScalarX = float(pPctRef.width) / mySpr.width
pSprScalarY = float(pPctRef.height) / mySpr.height
pPixelActorListX = []
pPixelActorListY = []
pSpreadListX = [1, 0, -1, 0]
pSpreadListY = [0, 1, 0, -1]
end
---------------
on mouseDown me
fillColor = random(16777216)
sprX = the mouseH - pSprLeft
sprY = the mouseV - pSprTop
mbrX = integer(sprX * pSprScalarX) - 1
mbrY = integer(sprY * pSprScalarY) - 1
----
-- a = the ticks
me.mFlood(mbrX, mbrY, fillColor)
-- put the ticks - a
end
---------------
on mFlood me, aX, aY, aSourceColor
targetColor = pPctRef.getPixel(aX, aY)
pPctRef.setPixel(aX, aY, aSourceColor)
append pPixelActorListX, aX
append pPixelActorListY, aY
repeat while count(pPixelActorListX)
xCur = getAt(pPixelActorListX, 1)
yCur = getAt(pPixelActorListY, 1)
deleteAt pPixelActorListX, 1
deleteAt pPixelActorListY, 1
repeat with n = 1 to 4
xTest = xCur + getAt(pSpreadListX, n)
yTest = yCur + getAt(pSpreadListY, n)
if pPctRef.getPixel(xTest, yTest) = targetColor then
pPctRef.setPixel(xTest, yTest, aSourceColor)
-- updateStage
append pPixelActorListX, xTest
append pPixelActorListY, yTest
end if
end repeat
end repeat
end
|
|