Tuesday, November 17, 2009

Write a program in c to Demonstrate Bresenham’s Line Drawing Algorithm

SOURCE CODE

#include
#include
#include
#include
main()
{
float x,y,x1,y1,x2,y2,dx,dy,e;
int i,gd,gm;
printf("enter the values of x1=\t");
scanf("%f",&x1);
printf("enter the values of x2=\t");
scanf("%f",&x2);
printf("enter the values of y1=\t");
scanf("%f",&y1);
printf("enter the values of y2=\t");
scanf("%f",&y2);
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
setbkcolor(15);
dx=abs(x2-x1);
dy=abs(y2-y1);
x=x1;
y=y1;
e=2*dy-dx;
i=1;
do
{
putpixel(x,y,13);
while(e>=0)
{
y=y+1;
e=e-2*dx;
}
x=x+1;
e=e+2*dy;
i=i+1;
delay(25);
}
while(i<=dx);
getch();
closegraph();
return(0);
}

No comments:

Post a Comment