forked from SagarGaniga/computer-graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflood.cpp
More file actions
71 lines (70 loc) · 1.63 KB
/
flood.cpp
File metadata and controls
71 lines (70 loc) · 1.63 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void bf_4(int x , int y ,int fc , int bc)
{
if(getpixel(x,y)!=bc&& getpixel(x,y)!=fc)
{
putpixel(x,y,fc);
bf_4(x+1,y,fc,bc);
bf_4(x,y+1,fc,bc);
bf_4(x-1,y,fc,bc);
bf_4(x,y-1,fc,bc);
}
}
void plotPoints(int x,int y,int xc,int yc)
{
putpixel(x+xc,y+yc,WHITE);
putpixel(y+xc,x+yc,WHITE);
putpixel(-x+xc,y+yc,WHITE);
putpixel(-y+xc,x+yc,WHITE);
putpixel(x+xc,-y+yc,WHITE);
putpixel(y+xc,-x+yc,WHITE);
putpixel(-x+xc,-y+yc,WHITE);
putpixel(-y+xc,-x+yc,WHITE);
}
void drawCircle(int xc ,int yc , int r)
{
int po,x=0,y=r,p;
po=3-2*r;
p=po;
do
{
plotPoints(x,y,xc,yc);
if(p<0)
{
p=p+4*x+6;
x=x+1;
}
else
{
p=p+4*(x-y)+10;
x=x+1;
y=y-1;
}
}while(x<=y);
}
int main()
{
int sx, sy, gd=DETECT, gm;
float r;
initgraph(&gd , &gm , "C:\\TURBOC3\\BGI");
sx=getwindowwidth()/2;
sy=getwindowheight()/2;
r=100;
printf("%d,%d",sx,sy);
drawCircle(sx,sy-((r*2)/3),r);
drawCircle(sx+(r/sqrt(3)),sy+(r/3),r);
drawCircle(sx-(r/sqrt(3)),sy+(r/3),r);
while(1)
{
bf_4(sx,sy-((r*2)/3),LIGHTBLUE,WHITE);
bf_4(sx+(r/sqrt(3)),sy+(r/3),YELLOW,WHITE);
bf_4(sx-(r/sqrt(3)),sy+(r/3),RED,WHITE);
bf_4(sx+10,sy+10,LIGHTRED,WHITE);
bf_4(sx+50,sy,LIGHTMAGENTA,WHITE);
bf_4(sx-50,sy,LIGHTGREEN,WHITE);
bf_4(sx,sy+50,GREEN,WHITE);
}
getch();
}