Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!deimos.cis.ksu.edu!maverick.ksu.ksu.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!cs122cv From: cs122cv@ux1.cso.uiuc.edu Newsgroups: comp.graphics Subject: Re: References to Flood Fill Routines Message-ID: <5300034@ux1.cso.uiuc.edu> Date: 5 May 90 18:51:00 GMT References: <145@avatar.UUCP> Lines: 49 Nf-ID: #R:avatar.UUCP:145:ux1.cso.uiuc.edu:5300034:000:1467 Nf-From: ux1.cso.uiuc.edu!cs122cv May 5 13:51:00 1990 Here is Fortran code for a non-recursive flood-fill... c Given array dimensions x and y, some array field(x,y), c arrays xstack() and ystack() (each dimensioned to some c sufficiently large number), and seed {start_x,start_y}... c c Field should be all 0's except for the border of the area c to be filled, which should be -1. Upon exit, the area within c the border will be filled with 1's. stack_count=1 xstack(stack_count)=start_x ystack(stack_count)=start_y do while (stack_count.gt.0) xpixel=xstack(stack_count) ypixel=ystack(stack_count) stack_count=stack_count-1 rxpixel=real(xpixel) rypixel=real(ypixel) field(xpixel,ypixel)=1 if (field(xpixel+1,ypixel).eq.0) then stack_count=stack_count+1 xstack(stack_count)=xpixel+1 ystack(stack_count)=ypixel end if if (field(xpixel-1,ypixel).eq.0) then stack_count=stack_count+1 xstack(stack_count)=xpixel-1 ystack(stack_count)=ypixel end if if (field(xpixel,ypixel-1).eq.0) then stack_count=stack_count+1 xstack(stack_count)=xpixel ystack(stack_count)=ypixel-1 end if if (field(xpixel,ypixel+1).eq.0) then stack_count=stack_count+1 xstack(stack_count)=xpixel ystack(stack_count)=ypixel+1 end if end do ---Marc Andreessen Materials Research Lab, University of Illinois andreessen%uimrl.dnet@uimrl5.mrl.uiuc.edu