We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
#include <graphics.
h> #include <conio.h>
// Flood Fill Algorithm
void floodFill(int x, int y, int fillColor, int targetColor) { int currentColor = getpixel(x, y); // Get the current color of the pixel at (x, y)
// If the current pixel color is the target color, fill it
if (currentColor == targetColor) { putpixel(x, y, fillColor); // Set the pixel at (x, y) to the fill color
// Recursively fill the surrounding pixels
floodFill(x + 1, y, fillColor, targetColor); // Right floodFill(x - 1, y, fillColor, targetColor); // Left floodFill(x, y + 1, fillColor, targetColor); // Down floodFill(x, y - 1, fillColor, targetColor); // Up } }
int main() { // Initialize graphics int gd = DETECT, gm; initgraph(&gd, &gm,(char*)""); // Set the correct path for your system
// Draw a rectangle (or any shape)
rectangle(150, 100, 350, 300); // Rectangle with top-left (150, 100) and bottom-right (350, 300)
// Set the initial target color to the background color (black)
int targetColor = BLACK; int fillColor = RED; // Color to fill the region // Start flood fill at a point inside the rectangle (e.g., (200, 150)) floodFill(200, 150, fillColor, targetColor);