Wednesday, 19 February 2014

DDA ALGORITHM FOR DRAWING LINE



/************************************************************************/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>

int main()
{
                int x1,y1,x2,y2,i,xincr,yincr,dx,dy,steps,x;
                float m;
                int gdriver=DETECT,gmode;
                initgraph(&gdriver,&gmode,"");

                printf("enter the coordinates of first point : ");
                scanf("%d%d",&x1,&y1);

                printf("enter the coordinates of second point : ");
                scanf("%d%d",&x2,&y2);

                dx=x2-x1;
                dy=y2-y1;

                if(abs(dx)>abs(dy))
                                steps=dx;
                else
                                steps=dy;

                xincr=dx/steps;
                yincr=dy/steps;


                for(i=0;i<steps;i++)
                {
                                x1+=xincr;
                                y1+=yincr;
                                putpixel(x1,y1,WHITE);
                }



                getch();
                return 0;
}
/**************************************************************************/

No comments:

Post a Comment