Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!blake!wiml From: wiml@blake.acs.washington.edu (William Lewis) Newsgroups: comp.graphics Subject: Re: Looking for simple fill algorithm Summary: Seed fill algorithm Message-ID: <1718@blake.acs.washington.edu> Date: 23 Apr 89 05:37:40 GMT References: <390030@hpfcdq.HP.COM> Reply-To: wiml@blake.acs.washington.edu (William Lewis) Organization: University of Washington, Seattle Lines: 27 In article <390030@hpfcdq.HP.COM> benji@hpfcdq.HP.COM (Jeff Benjamin) writes: >Does anyone know if there is a simple algorithm for filling a closed path? >The path may have several loops. >Data structures available: an array of the screen [166x199], a list >containing all the points in the path, or whatever you wish. The following is called a 'seed fill'. Given a point, and some way of determining boundaries, it fills all points connected with the first. seedfill(x,y) { plot(x,y) if((x+1,y) is not a 'border' point) seedfill(x+1,y) if((x-1,y) is not a 'border' point) seedfill(x-1,y) and so on with all points adjacent to (x,y) } Note this is recursive. You can include diagonals as adjacent, or not, as you wish. Oops: when testing to see whether an adjacent point should be also seedfilled, you MUST double check to see if said point has been seedfilled already. IE, if borders are of color A, and you are filling with color B, the condition for calling seedfill() on point(x+h,y+k) is ((color_of(x+h,y+k) != A) and (color_of(x+h,y+k) != B)) hope this helps. ~~~~~~~~~~~~~~~~~sigless~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~