0% found this document useful (0 votes)
30 views3 pages

Bresenham Algorithm: Program

The document describes the Bresenham algorithm for drawing lines on a digital display. It includes the C program code to implement the algorithm, which uses incremental updating of a decision parameter to determine the next pixel to plot along the line between two given points. The main function gets the x and y coordinates of the start and end points from the user and calls the drawline function to display the line on the screen.

Uploaded by

mayank
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)
30 views3 pages

Bresenham Algorithm: Program

The document describes the Bresenham algorithm for drawing lines on a digital display. It includes the C program code to implement the algorithm, which uses incremental updating of a decision parameter to determine the next pixel to plot along the line between two given points. The main function gets the x and y coordinates of the start and end points from the user and calls the drawline function to display the line on the screen.

Uploaded by

mayank
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/ 3

Bresenham Algorithm

Program:

#include<stdio.h>

#include<graphics.h>

void drawline(int x0, int y0, int x1, int y1)

int dx, dy, p, x, y;

dx=x1-x0;

dy=y1-y0;

x=x0;

y=y0;

p=2*dy-dx;

while(x<x1)

if(p>=0)

putpixel(x,y,7);

y=y+1;

p=p+2*dy-2*dx;

else

{
putpixel(x,y,7);

p=p+2*dy;}

x=x+1;

int main()

int gdriver=DETECT, gmode, error, x0, y0, x1, y1;

initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");

printf("Enter co-ordinates of first point: ");

scanf("%d%d", &x0, &y0);

printf("Enter co-ordinates of second point: ");

scanf("%d%d", &x1, &y1);

drawline(x0, y0, x1, y1);

return 0;

Output:

You might also like