KEMBAR78
Program To Draw A Line Using Bresenham Algorithm | PDF
0% found this document useful (0 votes)
19 views2 pages

Program To Draw A Line Using Bresenham Algorithm

graphics

Uploaded by

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

Program To Draw A Line Using Bresenham Algorithm

graphics

Uploaded by

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

www.eazynotes.com Gursharan Singh Tatla Page No.

1


/*** Program to Draw a Line using Bresenham's Algorithm ***/

#include <stdio.h>
#include <dos.h>
#include <graphics.h>

void lineBres(int, int, int, int);

void main()
{
int x1, y1, xn, yn;

int gd = DETECT, gm;
initgraph(&gd, &gm, "");

printf("Enter starting coordinates of line: ");
scanf("%d %d", &x1, &y1);
printf("Enter 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, RED);



www.eazynotes.com Gursharan Singh Tatla Page No. 2


while (x1 < xn)
{
x1++;
if (di < 0)
di = di + ds;
else
{
y1++;
di = di + dt;
}

putpixel(x1, y1, RED);
delay(20);
}
}

You might also like