Headlines
Loading...
Computer graphics program - DDA Line Drawing Algorithm

Computer graphics program - DDA Line Drawing Algorithm

DDA Line Drawing Algorithm
Code
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#define ROUND(a) (int)(a+0.5)
void linedda(int,int,int,int);
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,length,slope,temp;
int i,gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("DDA LINE DRAWING ALGORITHM\n");
printf("Enter the value of x1 :");
scanf("%f",&x1);
printf("Enter the value of y1 :");
scanf("%f",&y1);
printf("Enter the value of x2 :");
scanf("%f",&x2);
printf("Enter the value of y2 :");
scanf("%f",&y2);
cleardevice();
linedda(x1,y1,x2,y2);
getch();
closegraph();
restorecrtmode();
}
void linedda(int x1, int y1, int x2, int y2)
{
int dx = x2 - x1, dy = y2 - y1, steps, k;
float xinc, yinc, x= x1,y=y1,a,b;
a=abs(dx);
b=abs(dy);
if(a>b)
{
steps = abs(dx);
}
else
{
steps = abs(dy);
}
xinc = dx/(float) steps;
yinc = dy/(float) steps;
putpixel(ROUND(x),ROUND(y),15);
do
{
x += xinc;
y += yinc;
putpixel(ROUND(x), ROUND(y),15);
k++;
}
while(k<steps);
}
 

*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***