DDA line drawing algorithm program in c | Wave the world

DDA line drawing algorithm program in c

/* DDA program
created by: Pirate */

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
void dda_line(int x1,int y1,int x2,int y2);
void main()
{
            int x1,y1,x2,y2,gd=DETECT,mode;
            clrscr();
            initgraph(&amp;gd,&amp;mode,"c:\\turboc3\\bgi");
            printf("Enter the starting point of line\n");
            scanf("%d %d",&amp;x1,&amp;y1);
            printf("\nEnter the ending point of line\n");
            scanf("%d %d",&amp;x2,&amp;y2);
            dda_line(x1,y1,x2,y2);
            getch();
}
void dda_line(int x1,int y1,int x2,int y2)
{
            float x,y,xinc,yinc,dx,dy;
            int k,length;
            dx=x2-x1;
            dy=y2-y1;
            if(abs(dx)&gt;abs(dy))
            length=abs(dx);
            else
            length=abs(dy);
            xinc=dx/length;
            yinc=dy/length;
            x=x1;
            y=y1;
            putpixel(x,y,7);
            for(k=1;k
            {
                        x=x+xinc;
                        y=y+yinc;
                        delay(10);
                        putpixel(x,y,7);
            }

}

Output




0 comments:

Post a Comment

 

Pro

About