#### Archived

This topic is now archived and is closed to further replies.

# color fills

This topic is 5863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

does anyone know of any resources on doing color fills (as in the kind seen in paint programs, usually signified by a bucket).. I am looking for a guide to writing such algorithms but so far no luck.

##### Share on other sites
Well, here''s the dumb way to do it... The reason it''s dumb is because it uses recursion. Since the recursion depth can get really high, basically this can only fill a small region or your computer runs out of memory =)

Fill(int x, int y, int color)
{
if pixel at (x,y) isn''t color then
putpixel(x, y, color)
fill(x-1, y, color)
fill(x+1, y, color)
fill(x, y-1, color)
fill(x, y+1, color)
}
This is just some rough pseudocode- you might have to do a little bit of extra error checking...
Anyway, if someone else posts a non-recursive algorithm, use that one instead, hehe =)

##### Share on other sites
yeah that was basically what i was using.. i need to find some way to write a flood fill that doesn''t use as much memory

• 10
• 16
• 14
• 18
• 15