computer graphics program using C to implement Bressenham's line drawing algorithm
#include"stdio.h"
#include"conio.h"
#include"graphics.h"
#include"math.h"
void swap(int &x,int &y)
{
int k=x;
x=y;
y=k;
}
void main()
{
int gd=DETECT,gm=DETECT,x1,x2,y1,y2,dx,dy,p,k;
float m=0;
clrscr();
printf(“Enter the sarting point x1 & y1n”);
scanf(“%d%d”,&x1,&y1);
printf(“Enter the end point x2 & y2n”);
scanf(“%d%d”,&x2,&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
m=(float)(y2-y1)/(x2-x1);
initgraph(&gd,&gm,”");
cleardevice();
if(fabs(m)>1)
{
swap(x1,y1);
swap(x2,y2);
swap(dx,dy);
}
if((x1>x2))
{
x1=x2;
y1=y2;
}
p=2*dy-dx;
for(k=0;k
getch();
}
0 comments:
Post a Comment
speak out... itz your time !!!