0% found this document useful (0 votes)
40 views2 pages

BLA Algorithm

This C program uses the graphics library to implement the Bresenham's line drawing algorithm. It prompts the user to input the coordinates of two points and then draws a line between them on the screen. The program handles both steep and shallow lines by determining the differences in x and y coordinates and adjusting the pixel placement accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

BLA Algorithm

This C program uses the graphics library to implement the Bresenham's line drawing algorithm. It prompts the user to input the coordinates of two points and then draws a line between them on the screen. The program handles both steep and shallow lines by determining the differences in x and y coordinates and adjusting the pixel placement accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include<stdio.

h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int main ()
{
int gd = DETECT,gm,x1,y1,x2,y2,lx,ly,dy,dx,pk,i;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("put the values of x1 and y1 :\n");
scanf("%d%d",&x1,&y1);
printf("put the values of x2 and y2 :\n");
scanf("%d%d",&x2,&y2);
dx = abs(x2-x1);
dy = abs(y2-y1);
if(x2>x1)
{
lx = 1;
}
else
{
lx = -1;
}
if(y2>y1)
{
ly = 1;
}
else
{
ly = -1;
}
putpixel(x1,y1,BLUE);
if(dx>dy)
{
pk = 2*dy-dx;
for(i=0;i<dx;i++)
{
if(pk<0)
{
x1 = x1+lx;
y1 = y1;
pk = pk+2*dy;
}
else
{
x1 = x1+lx;
y1 = y1+ly;
pk = pk+2*dy-2*dx;
}
putpixel(x1,y1,BLUE);
}
}
else
{
pk = 2*dx-dy;
for(i=0;i<dy;i++)
{
if(pk<0)
{
x1 = x1;
y1 = y1+ly;
pk = pk+2*dx;
}
else
{
x1 = x1+lx;
y1 = y1+ly;
pk = pk+2*dx-2*dy;
}
putpixel(x1,y1,BLUE);
}
}
getch();
closegraph();
return 0;
}

You might also like