Forum archive
Can you solve this one Ken?
- hey
i can't figure out how to solve this flood fill problem. i'm searching for a specific flood fill which whould act like this:
http://img431.imageshack.us/img431/6562/17xe1.png
1 is starting seed of flood fill
2 is 2nd iteration of flood fill
3 is 3rd iteration, etc...
it's not hard to make this kind of flood fill to fill simple objects (ie. cricle, square, etc...). the problem is with more complex objects. check out this picture with 2 circles - one inside another, and the inner circle has a "leak" which leads to outer circle.
check out how the flow of flood fill should be going
http://img431.imageshack.us/img431/1098/21rm.png
i need this kind of flood fill for game i'm working on, so if you can make an example of this flood fill, a 2d array flood fill in qbasic will do fine
if you want to see this flood fill in action, you should download cosmo bots or water bugs demo from this page (both are small downloads) - http://www.retro64.comEdited by JonoF at - In my sleep.
WIDTH 80, 25: CLS : DIM a(80, 25), px(80 * 25), py(80 * 25)
FOR yy = 1 TO 25
READ z$: IF z$ = "" THEN EXIT FOR
PRINT z$: xx = INSTR(z$, "0"): IF xx THEN x = xx: y = yy
FOR xx = 1 TO LEN(z$): a(xx, yy) = ASC(MID$(z$, xx, 1)): NEXT
NEXT
DATA " ############ "
DATA " # # # ####"
DATA "##### # #### #"
DATA "# #### ####"
DATA "# 0 # "
DATA "################ "
DATA ""
r = 0: w = 0: d = 0: q = 0
DO
LOCATE y, x: PRINT HEX$(d); : z$ = INPUT$(1)
IF a(x - 1, y) = 32 THEN a(x - 1, y) = 1: px(w) = x - 1: py(w) = y: w = w + 1
IF a(x + 1, y) = 32 THEN a(x + 1, y) = 1: px(w) = x + 1: py(w) = y: w = w + 1
IF a(x, y - 1) = 32 THEN a(x, y - 1) = 1: px(w) = x: py(w) = y - 1: w = w + 1
IF a(x, y + 1) = 32 THEN a(x, y + 1) = 1: px(w) = x: py(w) = y + 1: w = w + 1
IF r = w THEN EXIT DO
x = px(r): y = py(r): r = r + 1: IF r > q THEN d = d + 1: q = w
LOOP - THANKS ALOT!!!
That's exactly what i needed! I'll add you to the credits, once i finish my game.