-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfloodFill.cpp
47 lines (40 loc) · 1.06 KB
/
floodFill.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<graphics.h>
using namespace std;
void floodfill(int x, int y, int bgColor, int fillColor)
{
int current = getpixel(x, y);
if(current==bgColor)
{
putpixel(x, y, fillColor);
floodfill(x+1, y, 0, fillColor);
floodfill(x, y+1, 0, fillColor);
floodfill(x-1, y, 0, fillColor);
floodfill(x, y-1, 0, fillColor);
}
}
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
int fillColor, x[10], y[10], i, a, b, n;
cout<<"Enter n: ";
cin>>n;
cout<<"Enter co-ordinates of "<<n<<"-sided polygon: ";
cout<<"\nEnter x: ";
for(i=0; i<n; i++)
cin>>x[i];
cout<<"Enter y: ";
for(i=0; i<n; i++)
cin>>y[i];
line(x[n-1], y[n-1], x[0], y[0]);
for(i=0; i<n-1; i++)
line(x[i], y[i], x[i+1], y[i+1]);
cout<<"Enter fill color(0-15): ";
cin>>fillColor;
cout<<"Enter starting point(x, y): ";
cin>>a>>b;
floodfill(a, b, 0, fillColor);
getch();
closegraph();
}