Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Direct FTP 2.0
Opening Local HTML pages
Play different Movies For Different Game Levels
Relative Links
DirectTransition
Face Sprite-Alphamania
Arca Database Xtra
Print Any Frame from Projector
Text Drop Shadows (and a moving light)
SplashScreenX
 

 

 

Behavior Image Flood Fill (Using getPixel and setPixel)

Added on 10/6/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: JakobMadsen

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

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail