-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBresenham_LineDrawingAlgo.cpp
80 lines (71 loc) · 1.01 KB
/
Bresenham_LineDrawingAlgo.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
77
78
79
#include<iostream>
#include<cmath>
#include<graphics.h>
#include<conio.h>
using namespace std;
void BLA(int x1,int y1,int x2,int y2){
int dx,dy,p,xinc,yinc;
dx=abs(x2-x1);
dy=abs(y2-y1);
if(x2<x1){
xinc=-1;
}
else{
xinc=1;
}
if(y2<y1){
yinc=-1;
}
else{
yinc=1;
}
putpixel(x1,y1,5);
if(dx>dy){
p=2*dy-dx;
for(int k=0;k<dx;k++){
if(p>0){
x1=x1+xinc;
y1=y1+yinc;
p=p+2*dy-2*dx;
putpixel(x1,y1,5);
delay(100);
}
else{
x1=x1+xinc;
y1=y1;
p=p+2*dy;
putpixel(x1,y1,5);
delay(100);
}
}
}else{
p=2*dy-dx;
for(int k=0;k<dy;k++){
if(p>0){
x1=x1+xinc;
y1=y1+yinc;
p=p+2*dy-2*dx;
putpixel(x1,y1,5);
delay(100);
}
else{
x1=x1;
y1=y1+yinc;
p=p+2*dy;
putpixel(x1,y1,5);
delay(100);
}
}
}
}
int main(){
int x1,x2,y1,y2;
initwindow(400,400,"BLA algorithm");
cout<<"Enter the value of x1 & y1: ";
cin>>x1>>y1;
cout<<"Enter the value of x2 & y2: ";
cin>>x2>>y2;
BLA(x1,y1,x2,y2);
getch();
closegraph();
}