#include< stdio.h> #include< graphics.h> #include< conio.h> #define ROUND(a) ((int)(a+0.5)) void DDA_LINE(int x1,int y1,int x2,int y2); void main() { int x1,y1,x2,y2,gdriver=DETECT,gmode; clrscr(); initgraph(&gdriver,&gmode,""); printf("\nEnter point1(x1,y1):"); scanf("%d %d",&x1,&y1); printf("\nEnter point2(x2,y2):"); scanf("%d %d",&x2,&y2); DDA_LINE(x1,y1,x2,y2); getch(); } void DDA_LINE(int x1,int y1,int x2,int y2) { int dx=x2-x1,dy=y2-y1,steps,i; float xInc,yInc,x=x1,y=y1; if(abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xInc=dx/(float)steps; yInc=dy/(float)steps; putpixel(ROUND(x),ROUND(y),BLACK); for(i=0;i< steps;i++) { x+=xInc; y+=yInc; putpixel(ROUND(x),ROUND(y),BLACK); } }
Output of Program
Comments
Post a Comment