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

Program For Bresenham'S Line Drawing Algorithm

This document contains code for implementing Bresenham's line drawing algorithm in C. It defines functions to get user input for start and end points of a line, and then calls a line drawing function to plot the line pixel by pixel on a graph using a loop. The line drawing function implements the core logic of Bresenham's algorithm to determine the next pixel to plot while incrementing along the x-axis, accounting for whether to also increment y using decision variables to track error.

Uploaded by

Mithun Kiruthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views2 pages

Program For Bresenham'S Line Drawing Algorithm

This document contains code for implementing Bresenham's line drawing algorithm in C. It defines functions to get user input for start and end points of a line, and then calls a line drawing function to plot the line pixel by pixel on a graph using a loop. The line drawing function implements the core logic of Bresenham's algorithm to determine the next pixel to plot while incrementing along the x-axis, accounting for whether to also increment y using decision variables to track error.

Uploaded by

Mithun Kiruthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*PROGRAM FOR BRESENHAMS LINE DRAWING ALGORITHM*/

#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
void lineBres(int x1,int y1,int x2,int y2);
void main()
{
int x1,y1,xn,yn;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\Turboc3\BGI");
printf("Enter starting coordinates of line:");
scanf("%d%d",&x1,&y1);
printf("Enter the ending coordinates of line:");
scanf("%d%d",&xn,&yn);
lineBres(x1,y1,xn,yn);
getch();
}
void lineBres(int x1,int y1,int xn,int yn)
{
int dx=xn-x1,dy=yn-y1;
int di=2*dy-dx;
int ds=2*dy,dt=2*(dy-dx);
putpixel(x1,y1,5);
while(x1<xn)
{
x1++;
if(di<0)
di=di+ds;
else
{
y1++;
di=di+dt;
}
putpixel(x1,y1,5);
delay(20);
}
}

OUTPUT:

You might also like