Jump to content
  • Advertisement

Archived

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

djsteffey

how to do floodfill ?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

well how do you do it ? in my game i want to load artwork.......and then change the color of certain areas of it...like floodfill in MS-Paint. Since I dont know any vertices and the shape could be highly irregular. I can think of two different ways to do this but i dont like either one. i can either a) use recursion like color the pixel at x, y location if the pixel x-1, y is the same color as this one then call the function recrsuively if the pixel x+1, y is the same color as this one then call the fuinction recursively and so forth and so forth but i dont like that idea and dont know how well it would work............probably pretty badly i would guess or b) use 8-bit mode and change the color of the pallete entry at that index but then that would change the color off all the other things on the screen with that color. how do i do this ? "Now go away or I shall taunt you a second time" - Monty Python and the Holy Grail

Share this post


Link to post
Share on other sites
Advertisement
Well, the Computer Graphics book (i.e. a lot of algorithms) uses recursion for every flood fill algorithm they use. So, I''ll copy a basic example that they show:
  
void floodFill4(int x, int y, int fillColor, int oldColor) {
if(getPixel(x, y)==oldColor) {
setColor(fillColor);
setPixel(x, y);
floodFill4(x+1,y,fillColor,oldColor);
floodFill4(x-1,y,fillColor,oldColor);
floodFill4(x,y+1,fillColor,oldColor);
floodFill4(x,y-1,fillColor,oldColor);
}
}

Change their default functions (setPixel, setColor, getPixel) to something that applies to your API. OldColor is meant to be the color of the "origin" pixel of the floodfill. There''s probably a faster method to do this, but most of the algorithms in this book are pretty fast (some are so esoteric that I would never have thought of them, but are very fast), so I don''t know exactly how good this one is .

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/

Share this post


Link to post
Share on other sites
Better yet, take CSC 518 or 4something at NCSU. I don''t think Robbins teaches anymore though. Maybe Gehringer.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!