0 votes
64 views
in Computer Graphics by (98.9k points)
retagged by
DDA Line drawing Computer Graphics

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#define ROUND(a) ((int)(a+0.5))
void lineDDA(int xa, int ya, int xb, int yb);
void main()
{
int xa, xb, ya, yb;
int gd=DETECT, gm, gerr;
clrscr();
printf("Enter the two end points [(xa, ya), (xb, yb)]:");
scanf("%d%d%d%d",&xa, &ya, &xb, &yb);
initgraph(&gd, &gm,"C:\\tc\\bgi);
gerr=graphresult();
if(gerr!=grOk)
{
printf("Error: %s",grapherrormsg(gerr));
getch();
return;
}
lineDDA(xa, ya, xb, yb);
getch();
closegraph();
}
void lineDDA(int xa, int ya, int xb, int yb);
{
int dx=xb-xa, dy=yb-ya, steps, k;
float xIncrement, yIncrement, x=xa, y=ya;
if(abs(dx)>abs(dy)
steps=abs(dx);
else
steps=abs(dy);
xIncrement=dx/(float)steps;
yIncrement=dy/(float)steps;
putpixel(ROUND(x), ROUND(y), RED);
for(k=0;k<steps;k++)
{
x+=xIncrement;
y+=yIncrement;
putpixel(ROUND(x), ROUND(y), RED);
}
}

Related questions

0 votes
1 answer 105 views
0 votes
1 answer 78 views
0 votes
1 answer 101 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

557 users

...