-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbresenhams.cpp
More file actions
62 lines (60 loc) · 1.25 KB
/
bresenhams.cpp
File metadata and controls
62 lines (60 loc) · 1.25 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
#include<iostream>
#include<cmath>
#include<graphics.h>
using namespace std;
int main()
{ float x0,y0,x1,y1,length,dx,dy,absDx,absDy;
float xinc,yinc,d;
cout<<"Enter the first coordinate:";
cin>>x0>>y0;
cout<<"Enter the last coordinate:";
cin>>x1>>y1;
dx=x1-x0;
dy=y1-y0;
absDx=abs(dx);
absDy=abs(dy);
initwindow(800,600);
if(x0<x1) //variable declaration
xinc=1;
else
xinc=-1;
if(y0<y1)
yinc=1;
else
yinc=-1;
if(absDx>absDy)
{
d=2*absDy-absDx;
while(x0!=x1)
{
if(d>0)
{
d=d+2*absDy-2*absDx;
y0+=yinc;
}
else
d=d+2*absDy;
x0+=xinc;
putpixel(x0,y0,RED);
delay(10);
}
}
else
{
d=2*absDx-absDy;
while(y0!=y1)
{
if(d>0) // x changes
{
d=d+2*absDx-2*absDy;
x0+=xinc;
}
else // x remains same
d=d+2*absDx;
y0+=yinc;
delay(10);
putpixel(x0,y0,RED);
}
}
getch();
}