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
- Painter's Algorithm in Computer Graphics
- DDA Line generation Algorithm in Computer Graphics
- Point Clipping Algorithm in Computer Graphics
- bar() function in C graphics
- Reflection In 2D Graphics
- Mandlebrot Set in C/C++ Using Graphics
- Draw circle in C graphics
- Sierpinski Triangle using Graphics
- Computer Graphics | Antialiasing
- How to include graphics.h in CodeBlocks?
- Draw a line in C++ graphics
- Draw Rectangle in C graphics
- Introduction to Computer Graphics
- Draw ellipse in C graphics
- How to create a Heart using C Graphics
- Julia Fractal set in C/C++ Using Graphics
- Vector vs Raster Graphics
- Applications of Computer 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 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.