Flood Fill

BlitzMax Forums/BlitzMax Programming/Flood Fill

RetroRusty(Posted 2005) [#1]
Has anyone got any code that does Flood Fill?

By this I mean the effect where you copy the bottom row of pixels to the whole of the screen, then the next row of pixels up etc until you have the whole image on the screen.

Thanks


Tom Darby(Posted 2005) [#2]
Try this pseudocode:

For i = 0 to GraphicsHeight()
1. Cls
2. Complete all your drawing operations
3. Draw a black rectangle at 0,0,graphicsWidth, (GraphicsHeight() - i)
4. Flip

Next


fredborg(Posted 2005) [#3]
If I understand the question, then this is one way of doing it:
Graphics 640,480,0,0

img:TImage = LoadImage("tester.png")

Swoop(img)
WaitKey()
End

Function Swoop(img:TImage)

	Local height:Int 	= ImageHeight(img)
	Local width:Int		= ImageWidth(img)

	Local lineimg:TImage = CreateImage(width,1)

	For Local y = 0 Until height
		SetScale 1.0,1.0
		DrawImage img,0,0
		
		SetScale 1.0,height-y
		GrabImage lineimg,0,y
		DrawImage lineimg,0,y

		Flip
	Next

EndFunction



RetroRusty(Posted 2005) [#4]
Yea fredborg, that's it :)

Can you have it going from the bottom up though?

Thanks


Tom Darby(Posted 2005) [#5]
Ah--misread the question, there. Sorry 'bout that.


ImaginaryHuman(Posted 2005) [#6]
Do you want ALL pixels of a certain color on the entire screen to be changed to the new color, as in a `re-map` of the color, or do you just want the pixels that are TOUCHING EACH OTHER to become the new color?


fredborg(Posted 2005) [#7]
Sure bottom up, is just as easy:
Graphics 640,480,0,60

img:TImage = LoadImage("tester.png")

Swoop(img,1)
WaitKey()
End

Function Swoop(img:TImage,direction=0)

	Local height:Int 	= ImageHeight(img)
	Local width:Int		= ImageWidth(img)

	Local lineimg:TImage = CreateImage(width,1)

	For Local y = 0 Until height
		SetScale 1.0,1.0
		DrawImage img,0,0

		SetScale 1.0,height-y	
			
		If direction = 0
			GrabImage lineimg,0,y
			DrawImage lineimg,0,y
		Else
			GrabImage lineimg,0,height-y
			DrawImage lineimg,0,0
		EndIf

		Flip
	Next

EndFunction