-
Notifications
You must be signed in to change notification settings - Fork 0
/
floodFill.cpp
30 lines (29 loc) · 862 Bytes
/
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
#include<conio.h>
#include<iostream>
#include<graphics.h>
using namespace std;
floodFill(int x,int y,int oldcolor,int newcolor)
{
if( getpixel(x,y) == oldcolor )
{
putpixel(x,y,newcolor);
floodFill(x+1,y,oldcolor,newcolor);
floodFill(x+1,y+1,oldcolor,newcolor);
floodFill(x,y+1,oldcolor,newcolor);
floodFill(x-1,y+1,oldcolor,newcolor);
floodFill(x-1,y,oldcolor,newcolor);
floodFill(x-1,y-1,oldcolor,newcolor);
floodFill(x,y-1,oldcolor,newcolor);
floodFill(x+1,y-1,oldcolor,newcolor);
}
}
int main()
{
int gd = DETECT;
int gm;
initgraph(&gd , &gm , "C:\\Program Files (x86)\\CodeBlocks\\MinGW\\include");
rectangle(50,50,300,250);
floodFill(51,51,BLACK,RED);
getch();
closegraph();
}