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

Bipul Bla

Bresenham's Line Algorithm (BLA) is an efficient method for drawing a straight line between two points in a 2D plane by determining the closest pixels to represent the line path. The algorithm uses integer calculations to minimize computational overhead and involves steps for calculating differences and decision parameters to activate the appropriate pixels. A sample C code implementation demonstrates how to use BLA to render a line on the screen using graphics functions.

Uploaded by

ratnabeepwool69
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)
1 views3 pages

Bipul Bla

Bresenham's Line Algorithm (BLA) is an efficient method for drawing a straight line between two points in a 2D plane by determining the closest pixels to represent the line path. The algorithm uses integer calculations to minimize computational overhead and involves steps for calculating differences and decision parameters to activate the appropriate pixels. A sample C code implementation demonstrates how to use BLA to render a line on the screen using graphics functions.

Uploaded by

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

Title:

Bresenham's Line Algorithm's use to draw a line between given points.

Theory:

A line segment between two points (x1, y1) and (x2, y2) in a 2D plane is traditionally a continuous
connection. However, in computer graphics, pixels are discrete units, so we cannot directly draw
a perfect continuous line between these points. Instead, we approximate the line by determining
and drawing the closest pixels that best represent the line path.
In graphics programming, the output screen acts as a coordinate system with the origin (0, 0) at
the top-left corner. The x-coordinate increases to the right, and the y-coordinate increases
downward.
Bresenham's Line Algorithm (BLA) is an efficient method to compute the intermediate pixel
coordinates that form a straight line between two points. It uses integer calculations to minimize
computational overhead and ensures smooth, visually appealing lines by deciding the optimal
pixels to activate.
Using functions like `putpixel(x, y, color)` in C, BLA allows us to render line segments by
illuminating the appropriate pixels on the screen, producing a precise and performance-friendly
line drawing.

Bresenham's Line Algorithm:


Step 1: Start
Step 2: Take the coordinates of initial point (x1,y1) and the final point (x2,y2).
Step 3: Find the difference between the points by using the formula:
dx = x2-x1;
dy = y2-y1;
Step 4: Calculate the decision parameter:
p = 2*dy-dx;
Step 5: Repeat the following for i=0 to dx:
putpixel(x1,y1,K);
x1 = x1+1;
If (p<0)
p=p+2*dy;
Else
y=y+1;
p=p+2*(dy-dx);
Step 6: Stop
Source Code:

/ Bresenham's Line Algorithm to draw a line.


#include <stdio.h>
#include <graphics.h>
#include <math.h>
int main(int argc, char const *argv[])
{
int x1, y1, x2, y2, dx, dy, p, x, y;
printf("Created by Bipul Ratna Shakya \nBLA Algorithm\n");
printf("Enter the initial point (x1 y1):\n");
scanf("%d %d", &x1, &y1);
printf("Enter the final point (x2 y2):\n");
scanf("%d %d", &x2, &y2);
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
dx = x2 - x1;
dy = y2 - y1;
x = x1;
y = y1;
p = 2 * dy - dx;
outtextxy(70, 70,"Bipul Ratna Shakya ");
for (int i = 0; i <= dx; i++)
{
putpixel(x, y, WHITE);
delay(100);
x++;
if (p < 0)
{
p = p + 2 * dy;
}
else {
y++;
p = p + 2 * (dy - dx);
}
}
delay(50000000);
closegraph();
return 0;
}
Output:

Figure 1: Inserting initial and final points

Figure 2: Drawing line using BLA

Conclusion:
Thus, as shown in the program above, we can draw a line by plotting individual pixels using
Bresenham's Line Algorithm (BLA) with the graphics functions provided in the graphics.h header
file.

You might also like