-
Notifications
You must be signed in to change notification settings - Fork 0
/
BLA1.C
52 lines (45 loc) · 930 Bytes
/
BLA1.C
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
// A program to print a line using Bressenhem's Line Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void bla(int, int, int, int);
main()
{
int x1,x2,y1,y2;
clrscr();
{
printf("Enter the value of x1 and y1 :\n");
scanf("%d%d",&x1,&y1);
printf("\n\nEnter the value of x2 and y2 : \n");
scanf("%d%d",&x2,&y2);
bla(x1,y1,x2,y2);
}
}
void bla(int x1, int y1, int x2, int y2)
{
int gd=DETECT,gm;
int dx,dy,dp;
dy=y2-y1; //difference in y-coordinates
dx=x2-x1; //difference in x-coordinates
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
//line(x1,y1,x2,y2);
outtext("Line drawn using Bressenhem's Line Algorithm.");
dp=2*dy-dx; //decision parameter
while(x1<x2)
{
if(dp>=0)
{
putpixel(x1,y1,RED);
y1=y1+1;
dp=dp+2*dy-2*dx;
}
else
{
putpixel(x1,y1,RED);
dp=dp+2*dy;
}
x1=x1+1;
}
getch();
closegraph();
}