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?
- Boundary Fill Algorithm
- DDA Line generation Algorithm in Computer Graphics
- Point Clipping Algorithm in Computer Graphics
- Painter's Algorithm in Computer Graphics
- Creating a Rainbow using Graphics Programming in C
- Sierpinski Triangle using Graphics
- Draw a moving car using computer graphics programming in C
- Creating Butterfly themed Fractal in C++ Using Graphics
- Mandlebrot Set in C/C++ Using Graphics
- Julia Fractal set in C/C++ Using Graphics
- How to create a Heart using C Graphics
- C Program to create a House using Graphics
- Draw a Chess Board using Graphics Programming in C
- Draw a smiley face using Graphics in C language
- Represent Tree using graphics in C/C++
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
- 2D Transformation in Computer Graphics | Set 1 (Scaling of Objects)
- Translation of objects in computer graphics
- Vector vs Raster Graphics
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.