Tuesday, April 13, 2010

DDA Algorithm

#include
#include
#include
#include
#define gx getmaxx()
#define gy getmaxy()
void main()
{
 int x1,y1,x2,y2,i,chx,chy,steps,gd=DETECT,gm;
 float x,y,xinc,yinc;
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 //line(gx/2,0,gx/2,gy);
 //line(0,gy/2,gx,gy/2);
 printf("Enter the end ponits of line as x1,y1,x2,y2:\n");
 scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
 chx=x2-x1;
 chy=y2-y1;
 if(abs(chx)>abs(chy))
 steps=abs(chx);
 else
 steps=abs(chy);
 xinc=(float)chx/steps;
 yinc=(float)chy/steps;
 x=x1;
 y=y1;
 putpixel(x+gx/2,-y+gy/2,14);
 for(i=0;i
 {
  x=x+xinc;
  y=y+yinc;
  delay(50);
  putpixel(x+gx/2,-y+gy/2,i);
 }
getch();
}

0 comments:

Post a Comment

 
ShareThis

Visitor

Website counter
Copyright 2009 Code's. Powered by Blogger
Blogger Templates created by Deluxe Templates
Wordpress by Wpthemescreator
Blogger Showcase