Given a rectangle, your task to fill this rectangle using flood fill algorithm.
Input : rectangle(left = 50, top = 50, right= 100, bottom = 100) flood( x = 55, y = 55, new_color = 12, old_color = 0) Output : Input : rectangle(left = 50, top = 50, right= 200, bottom = 400) flood( x = 51, y = 51, new_color = 6, old_color = 0) Output :
Flood fill algorithm fills new color until the
old color match.
Flood fill algorithm:-
// A recursive function to replace previous // color 'oldcolor' at '(x, y)' and all // surrounding pixels of (x, y) with new // color 'newcolor' and floodfill(x, y, newcolor, oldcolor) 1) If x or y is outside the screen, then return. 2) If color of getpixel(x, y) is same as oldcolor, then 3) Recur for top, bottom, right and left. floodFill(x+1, y, newcolor, oldcolor); floodFill(x-1, y, newcolor, oldcolor); floodFill(x, y+1, newcolor, oldcolor); floodFill(x, y-1, newcolor, oldcolor);
- Flood fill Algorithm - how to implement fill() in paint?
- DDA Line generation Algorithm in Computer Graphics
- Point Clipping Algorithm in Computer Graphics
- Boundary Fill Algorithm
- Mandlebrot Set in C/C++ Using Graphics
- bar() function in C graphics
- Segments in Computer Graphics
- Draw Rectangle in C graphics
- Draw circle in C graphics
- Draw a line in C++ graphics
- Applications of Computer Graphics
- Vector vs Raster Graphics
- Draw ellipse in C graphics
- Sierpinski Triangle using Graphics
- How to include graphics.h in CodeBlocks?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.