Skip to content

davidechiappetta/Recursive-flood-fill-with-4-directions-VB6

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flood Filler in VB6

From Wikipedia https://en.wikipedia.org/wiki/Flood_fill:
Flood fill, also called seed fill, is a flooding algorithm that determines and alters the area connected to a given node in a multi-dimensional array with some matching attribute. It is used in the "bucket" fill tool of paint programs to fill connected, similarly-colored areas with a different color, and in games such as Go and Minesweeper for determining which pieces are cleared. A variant called boundary fill uses the same algorithms but is defined as the area connected to a given node that does not have a particular attribute.

start random maze (square black/white or border/free)

image

end filling free square white with color yellow

image

start clicking on first arbitrary square white

image

step step until filling all square white with color yellow

note the rotation of the arrow red in the direction: up, left, down, righ, always looking for a free white box.

image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image image

far forward...

image

other steps...

image

end result

image

Code for the recursion, uncomment the call to viewPosition() and put the breakpoints as shown in the figure for understanding the logic of the recursion, or comment it for matter of speed.

image image

Another particular note

This recursive function limits the movement to the 4 main directions, up, left, down, righ, so when it encounters a black or yellow box the algorithm skips that box, and continues to explore new free boxes white always within the confines of the 4 directions. If you had increased the movement to 8 directions for example up, up-left, left, down-left, down etc.. in practice if you also included the diagonals then the code would have climb over the boundaries of the black boxes and filled all the white boxes (inside and outside the limits of the black boxes).
This simple algorithm can be applied to any game that implies a maze, but if you have to apply it to a paint program to fill shapes it would not be very useful because the pixels to fill would be thousands and the stack used by recursion is not so capable of storing all the states of the pixels, in this case we use other algorithms that involve a virtual stack created in the heap to replace recursion.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages