Recent Posts
None | 34 sec ago
None | 1 min ago
C# | 1 min ago
None | 2 min ago
None | 3 min ago
C# | 4 min ago
None | 4 min ago
None | 5 min ago
None | 6 min ago
None | 7 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By Mani S on the 5th of Jul 2009 01:00:11 AM
Download |
Raw |
Embed |
Report
#include<graphics.h>
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#define ROUND(a)((int)(a+0.5))
void dda(int,int,int,int);
void main( )
{
int gd=DETECT,gm;
int x1,y1,x2,y2;
initgraph(&gd,&gm,"d:\myc\bgi");
cout<<"Enter the starting and ending co-ordinate of line:";
cin>>x1>>y1>>x2>>y2;
dda(x1,y1,x2,y2);
getch( );
}
void dda(int xa,int ya,int xb,int yb)
{
int dx,dy,step,k;
float xinc,yinc,x,y;
dx=xb-xa;
dy=yb-ya;
if(abs(dx)>abs(dy))
step=abs(dx);
else
step=abs(dy);
xinc=dx/(float)step;
yinc=dy/(float)step;
x=xa;
y=ya;
putpixel(ROUND(x),ROUND(y),1);
for(k=1;k<=step;k++)
{
x=x+xinc;
y=y+yinc;
delay(10);
putpixel(ROUND(x),ROUND(y),1);
}
}
Submit a correction or amendment below.
Make A New Post