0% found this document useful (0 votes)
21 views2 pages

Bca-501 (De1) - SM29

Uploaded by

Sumit Chaudhary
Copyright
© © All Rights Reserved
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
0% found this document useful (0 votes)
21 views2 pages

Bca-501 (De1) - SM29

Uploaded by

Sumit Chaudhary
Copyright
© © All Rights Reserved
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);

// Pause to view the output


getch();

// Close the graphics window


closegraph();

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy