IMPLEMENTATION OF DDA LINE DRAWING ALGORITHM USING C++
IMPLEMENTATION OF DDA LINE DRAWING ALGORITHM USING C++ :
CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
main()
{
//INITIALIZING THE STARTING AND ENDING POINT
int x1=100,y1=100,x2=500,y2=400,dx,dy,length,i;
float x,y,xinc,yinc;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
//CALCULATING DY AND DX
dx=x2-x1;
dy=y2-y1;
//CONDITIONS FOR CALCULATING LENGTH
if(abs(dx)>abs(dy))
length=abs(dx);
else
length=abs(dy);
//CALCULATION X AND Y VALUES FOR ITERATIONS
xinc=dx/(float)length;
yinc=dy/(float)length;
x=x1;
y=y1;
floodfill(3,5,WHITE);
putpixel(x,y,0);
for(i=0;i<length;i++)
{
putpixel(x,y,0);
x=x+xinc;
y=y+yinc;
delay(10);
}
getch();
closegraph();
}
OUTPUT:
Comments
Post a Comment