program:
#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
#include"graphics.h"
#include"dos.h"
#include"math.h"
void main()
{
int driver,mode,k;
int xa,xb,ya,yb,dx,dy,x,y,i,p,dy2,dydx2;
clrscr();
printf("\n\tEnter(xa,ya)...");
scanf("%d%d",&xa,&ya);
printf("\n\tEnter(xb,yb)...");
scanf("%d%d",&xb,&yb);
x=xa;
y=ya;
driver=DETECT;
initgraph(&driver,&mode,"");
dx=abs(xb-xa);
dy=abs(yb-ya);
p=(2*dy)-dx;
dy2=2*dy;
dydx2=2*(dy-dx);
line(100,0,100,500);
line(0,100,500,100);
putpixel(x,y,2);
for(i=0;i<=dx;i++)
{
if(p<0)
{
x=x+1;
putpixel(x,y,2);
p+=dy2;
}
else
{
x=x+1;
y=y+1;
putpixel(x,y,2);
p+=dydx2;
}
}
getch();
}
output:
Enter(xa,ya)...100 100
Enter(xb,yb)...250 252
Showing posts with label bresenhams line drawing algorithm using c. Show all posts
Showing posts with label bresenhams line drawing algorithm using c. Show all posts
Sunday, January 17, 2010
Subscribe to:
Posts
(
Atom
)