#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x1,x2,y1,y2,dx,dy,steps,k;
float xi,yi,x,y;
clrscr();
initgraph (&gd,&gm,"C:\\TC\\BGI");
printf("Enter the co-ordinates of the first point \n");
printf("x1= ");
scanf("%d/n",&x1);
printf("y1= ");
scanf("%d/n",&y1);
printf("Enter the co-ordinates of the second point \n");
printf("x2= ");
scanf("%d/n",&x2);
printf("y2= ");
scanf("%d/n",&y2);
clrscr();
dx= x2-x1;
dy= y2-y1;
if (abs(dx) > abs(dy))
steps = abs(dx);
else
steps = abs(dy);
xi=(float)dx/steps;
yi=(float)dy/steps;
x=x1;
y=y1;
for(k=0;k<steps;k++)
{
putpixel (x,y,BLUE);
x=x+xi;
y=y+yi;
}
getch();
closegraph();
}
Showing posts with label Digital Differential Analyzer Line drawing algorithm. Show all posts
Showing posts with label Digital Differential Analyzer Line drawing algorithm. Show all posts
Saturday, May 2, 2009
C program to implement Digital Differential Analyzer Line drawing algorithm
Labels: Digital Differential Analyzer Line drawing algorithm
Posted by Angad at 3:06 PM 6 comments
Subscribe to:
Comments (Atom)
