Archived

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

cozman

color fills

Recommended Posts

cozman    583
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 this post


Link to post
Share on other sites
RajanSky    100
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 this post


Link to post
Share on other sites
cozman    583
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

Share this post


Link to post
Share on other sites