Bresenhams Line Drawing Algorithm


This program is for line drawing using Bresenham's algorithm  . This is a part of Mumbai University MCA Colleges C Programs Computer Graphics MCA 


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
int xa,ya,xb,yb,dx,dy,x,y,xEnd,p;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("Enter (xa,ya) & (xb,yb)\n");
scanf("%d%d%d%d",&xa,&ya,&xb,&yb);
dx=abs(xa-xb);
dy=abs(ya-yb);
p=2*(dy-dx);
if(xa>xb)
{
x=xb;
y=yb;
xEnd=xa;
}
else
{
x=xa;
y=ya;
xEnd=xb;
}
putpixel(x,y,YELLOW);
while(x<xEnd)
{
x=x+1;
if(p<0)
{
p=p+2*dy;
}
else
{
y=y+1;
p=p+2*(dy-dx);
}
putpixel(x,y,YELLOW);
}
getch();
closegraph();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment