Last active
August 26, 2020 11:18
-
-
Save AakashCode12/6692fba92c3c51e5e646691ac2a367e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream.h> | |
#include <graphics.h> | |
#include <dos.h> | |
#include <conio.h> | |
//!Boundary Fill Algorithm with 4 points checking | |
int boundaryFill(int x, int y, int fillcolor, int backgroundcolor) | |
{ | |
int current = getpixel(x, y); | |
if (current != backgroundcolor && current != fillcolor) | |
{ | |
putpixel(x, y, fillcolor); | |
boundaryFill(x + 1, y, fillcolor, backgroundcolor); | |
boundaryFill(x, y + 1, fillcolor, backgroundcolor); | |
boundaryFill(x - 1, y, fillcolor, backgroundcolor); | |
boundaryFill(x, y - 1, fillcolor, backgroundcolor); | |
} | |
return fillcolor; //returning temp to get a reference of fill colour (Not a necessary step now) | |
} | |
//!Flood Fill Algorithm function with 4 points filling | |
int floodFill(int x, int y, int fillcolor, int oldcolor) | |
{ | |
//*flood filling starting cordinates | |
if (getpixel(x, y) == oldcolor) | |
{ | |
putpixel(x, y, fillcolor); | |
floodFill(x + 1, y, fillcolor, oldcolor); | |
floodFill(x, y + 1, fillcolor, oldcolor); | |
floodFill(x - 1, y, fillcolor, oldcolor); | |
floodFill(x, y - 1, fillcolor, oldcolor); | |
} | |
return fillcolor; | |
} | |
//!main Function | |
int main() | |
{ | |
clrscr(); | |
int gm, gd = DETECT, radius; | |
int x, y; | |
int x1, y1; | |
cout << "Enter X and Y Co-Ordinates of the Circle : "; | |
cin >> x >> y; | |
x1 = x; | |
y1 = y; | |
cout << "\nEnter the Radius of The Circle : "; | |
cin >> radius; | |
int option; | |
initgraph(&gd, &gm, "c:\\turboc3\\bgi"); | |
circle(x, y, radius); | |
do | |
{ | |
cout << "\n1) Boundary Fill\n2) Flood Fill (White)\n3) Flood Fill (Orange)\n4) Exit"; | |
cout << "\nEnter Your Option : "; | |
cin >> option; | |
switch (option) | |
{ | |
case 1: | |
cout << "\nBOUNDARY FILL ALGORITHM\n"; | |
int t; | |
t = boundaryFill(x, y, 1, 15); | |
x = x1; //to give center coordiantes for other algorithms | |
y = y1; | |
getch(); | |
break; | |
case 2: | |
cout << "\nFLOOD FILL ALGORITHM\n"; | |
t = floodFill(x, y, 15, t); | |
x = x1; //to give center coordiantes for other algorithms | |
y = y1; | |
getch(); | |
break; | |
case 3: | |
cout << "\nFLOOD FILL ALGORITHM\n"; | |
t=floodFill(x, y, 12, t); | |
x = x1; //to give center coordiantes for other algorithms | |
y = y1; | |
getch(); | |
break; | |
case 4: | |
cout << "\nThe Program ended\n"; | |
break; | |
default: | |
cout << "\nInvalid Option is pressed\n"; | |
break; | |
} | |
} while (option != 4); | |
closegraph(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream.h> | |
#include <graphics.h> | |
#include <dos.h> | |
#include <conio.h> | |
//!Boundary Fill Algorithm with 4 points checking | |
void boundaryFill(int x, int y, int fillcolor, int backgroundcolor) | |
{ | |
int current = getpixel(x, y); | |
if (current != backgroundcolor && current != fillcolor) | |
{ | |
putpixel(x, y, fillcolor); | |
boundaryFill(x + 1, y, fillcolor, backgroundcolor); | |
boundaryFill(x, y + 1, fillcolor, backgroundcolor); | |
boundaryFill(x - 1, y, fillcolor, backgroundcolor); | |
boundaryFill(x, y - 1, fillcolor, backgroundcolor); | |
} | |
} | |
//! Boundary Fill Algorithm with 8 points checking***** Uncomment to use*** | |
/* | |
void boundaryFill(int x, int y, int fill_color,int boundary_color) | |
{ | |
if(getpixel(x, y) != boundary_color && getpixel(x, y) != fill_color) | |
{ | |
putpixel(x, y, fill_color); | |
boundaryFill(x + 1, y, fill_color, boundary_color); | |
boundaryFill(x, y + 1, fill_color, boundary_color); | |
boundaryFill(x - 1, y, fill_color, boundary_color); | |
boundaryFill(x, y - 1, fill_color, boundary_color); | |
boundaryFill(x - 1, y - 1, fill_color, boundary_color); | |
boundaryFill(x - 1, y + 1, fill_color, boundary_color); | |
boundaryFill(x + 1, y - 1, fill_color, boundary_color); | |
boundaryFill(x + 1, y + 1, fill_color, boundary_color); | |
} | |
} | |
*/ | |
//!Flood Fill Algorithm function | |
void floodFill(int x, int y, int fillcolor, int oldcolor) | |
{ | |
//*flood filling starting cordinates | |
if (getpixel(x, y) == oldcolor) | |
{ | |
putpixel(x, y, fillcolor); | |
floodFill(x + 1, y, fillcolor, oldcolor); | |
floodFill(x, y + 1, fillcolor, oldcolor); | |
floodFill(x - 1, y, fillcolor, oldcolor); | |
floodFill(x, y - 1, fillcolor, oldcolor); | |
} | |
} | |
//!main Function | |
int main() | |
{ | |
clrscr(); | |
int gm, gd = DETECT, radius; | |
int x, y; | |
cout << "Enter X and Y Co-Ordinates of the Circle : "; | |
cin >> x >> y; | |
cout << "\nEnter the Radius of The Circle : "; | |
cin >> radius; | |
int option; | |
cout << "\n1) Boundary Fill Algorithm\n2) Flood Fill Algorithm\nEnter your Choice : "; | |
cin >> option; | |
switch (option) | |
{ | |
case 1: | |
initgraph(&gd, &gm, "c:\\turboc3\\bgi"); | |
circle(x, y, radius); | |
cout << "\nBOUNDARY FILL ALGORITHM\n"; | |
boundaryFill(x, y, 1, 15); | |
break; | |
case 2: | |
initgraph(&gd, &gm, "c:\\turboc3\\bgi"); | |
circle(x, y, radius); | |
cout << "\nFLOOD FILL ALGORITHM\n"; | |
floodFill(x, y, 12, 0); | |
break; | |
default: | |
cout << "\nInvalid option\n"; | |
break; | |
} | |
getch(); | |
closegraph(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment