-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdda_line.c
More file actions
76 lines (57 loc) · 1.5 KB
/
dda_line.c
File metadata and controls
76 lines (57 loc) · 1.5 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
72
73
74
75
76
///////////////////////////////////////////////DDA LINE////////////////////////////////////////
//Run in TurboC
//Compile- Ctrl+F9
//libraries
#include<math.h>
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
int main()
{
//initialization & declaration
int i=1, gdriver, gmode;
float xin,yin;
float pixel,x,y, dx,dy, x1,y1,x2,y2;
gdriver=DETECT;
//Graph Initialization
//initgraph() in <graphics.h>
//Path can vary according to the system
initgraph(&gdriver, &gmode, "C:\\TurboC3\\bgi");
printf("Enter the coordinates of 1st Point:");
scanf("%f %f",&x1, &y1);
printf("Enter the coordinates of 2nd Point:");
scanf("%f %f",&x2, &y2);
dx = abs(x2 - x1);
dy = abs(y2 - y1);
if(dx > dy)
{
pixel = dx;
}
else
{
pixel = dy;
}
xin = dx / pixel;
yin = dy / pixel;
x = x1;
y = y1;
//putpixel(int x1, int y1, int x2, int y2)
putpixel(x, y, 15);
while(i <= pixel)
{
x = x + xin;
y = y + yin;
//putpixel(int x1, int y1, int x2, int y2)
putpixel(x, y, 15);
i++;
//to delaly the execution
//delay(milli-seconds)
delay(100);
}
//charater input
//getch() in <conio.h>
getch();
closegraph();
return 0;
}