-
Notifications
You must be signed in to change notification settings - Fork 0
/
GENERA~1.CPP
76 lines (76 loc) · 959 Bytes
/
GENERA~1.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
int sign(int x)
{
if(x>0)
return 1;
else
if(x<0)
return -1;
else
return 0;
}
void GBLA(int x0,int y0,int x1,int y1){
int sx,sy,n=1,flag=0,x=x0,y=y0,t;
int dx=abs(x1-x0);
int dy=abs(y1-y0);
sx=sign(x1-x0);
sy=sign(y1-y0);
if(dy>dx)
{
t=dx;
dx=dy;
dy=t;
flag=1;
}
else
{
flag=0;
int p=2*dy-dx;
putpixel(x,y,GREEN);
delay(20);
while(n<=dx)
{
if(p>=0)
{
x+=sx;
y+=sy;
p+=2*(dy-dx);
}
else
{
if(flag==1)
{
y+=sy;
}
else
{
x+=sx;
}
}
p+=2*dy;
putpixel(x,y,WHITE);
n+=1;
delay(20);
}
}
}
void main(){
int gd=DETECT,gm,a,b,c,d;
clrscr();
initgraph(&gd,&gm,"");
cout<<"Enter the coordinates value"<<endl;
cout<<"X1 : ";
cin>>a;
cout<<"Y1 : ";
cin>>b;
cout<<"X2 : ";
cin>>c;
cout<<"Y2 : ";
cin>>d;
GBLA(a,b,c,d);
getch();
}