0% found this document useful (0 votes)
6 views5 pages

LAb 2 Comp Graphics

This document presents a lab report on Bresenham's Line Algorithm (BLA) for drawing lines in computer graphics, emphasizing its efficiency over the DDA algorithm due to its use of integer arithmetic. The report includes a detailed explanation of the algorithm's steps, source code implementation, and a conclusion highlighting the successful execution and visual effects achieved during the drawing process. The lab was submitted to the Department of Electronics and Computer Engineering at Tribhuvan University on December 10, 2024.

Uploaded by

luciferparajulee
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)
6 views5 pages

LAb 2 Comp Graphics

This document presents a lab report on Bresenham's Line Algorithm (BLA) for drawing lines in computer graphics, emphasizing its efficiency over the DDA algorithm due to its use of integer arithmetic. The report includes a detailed explanation of the algorithm's steps, source code implementation, and a conclusion highlighting the successful execution and visual effects achieved during the drawing process. The lab was submitted to the Department of Electronics and Computer Engineering at Tribhuvan University on December 10, 2024.

Uploaded by

luciferparajulee
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/ 5

Tribhuvan University

Institute of Engineering
Thapathali Campus, Thapathali

Subject: Computer Graphic & Visualization


LAB 2

Submitted By:

Roll No.: THA080BEI014

Submitted To:
Department of Electronics and Computer Engineering

Submission Date: Dec 10 , 2024


Title: Bresenham’s Line Algorithm
Objective: To draw the line using BLA Algorithm
Theory:
The Bresenham’s Line Algorithm (BLA) is an efficient method for drawing straight lines in computer
graphics. Unlike the DDA algorithm, which relies on floating-point arithmetic, the BLA uses integer
arithmetic to calculate intermediate pixel positions. This makes the algorithm faster and suitable for
systems with limited computational power. The major concept of Bresenham’s algorithm is to
determine the nearest pixel position.
The algorithm evaluates the decision parameter DDA to determine which pixel to plot next. It is
particularly effective for lines with both shallow and steep slopes. The screen is treated as a grid, with
(0,0) (0, 0) (0,0) at the top-left corner. Incremental pixel plotting is used to approximate the line

BLA ALGORITHM:
Step 1: Start
Step 2: Take the coordinates of the initial point (x0, y0) and the final point (x1, y1).
Step 3: Find the difference dx = x1-x0; dy= y1-y0;
Step 4: Determine the initial decision parameter.
Case 1: If dx ≥ dy, initialize p0=2dy−dxp0 = 2dy - dxp0=2dy−dx
Case 2: If dx < dy, initialize p0=2dx−dyp0 = 2dx - dyp0=2dx−dy
Step 5: Set the starting point to (x0, y0)
Step 6: Iterate
For dx≥dy:
If pk<0: Increment x, keep y.
If pk≥0: Increment both x and y.
Update pk as:
pk=pk+2dypk = pk + 2dy (if pk < 0)
pk=pk+2dy−2dxpk = pk + 2dy - 2dx (if pk ≥ 0)

For dy > dx:


If pk < 0: Increment y, keep x.
If pk ≥ 0: Increment both x and y.
Update pk as:
pk = pk + 2dx (if pk < 0)
pk = pk + 2dx - 2dy (if pk ≥ 0)
Step 7: Repeat the process until reaching the endpoint (x1, y1)
Step 8: Stop

SOURCE CODE:
#include <stdio.h> } else {
#include <graphics.h> y--;
#include <stdlib.h> }
int main() { pk += 2 * dy - 2 * dx;
int x0, y0, x1, y1, dx, dy, pk, x, y; }
int gd = DETECT, gm; delay(50);
}
printf("Enter x1 and y1: "); } else {
scanf("%d %d", &x0, &y0); pk = 2 * dx - dy;
printf("Enter x2 and y2: "); x = x0;
scanf("%d %d", &x1, &y1); y = y0;
dx = abs(x1 - x0);
dy = abs(y1 - y0); while (x != x1 || y != y1) {
initgraph(&gd, &gm, NULL); putpixel(x, y, WHITE);
setcolor(WHITE);
outtextxy(10, 10, "Bibek "); if (y1 > y0) {
y++;
if (dx >= dy) { } else {
pk = 2 * dy - dx; y--;
x = x0; }
y = y0;
if (pk < 0) {
while (x != x1 || y != y1) { pk += 2 * dx;
putpixel(x, y, WHITE); } else {
if (x1 > x0) {
if (x1 > x0) { x++;
x++; } else {
} else { x--;
x--; }
} pk += 2 * dx - 2 * dy;
}
if (pk < 0) { delay(50);
pk += 2 * dy; }
} else { }
if (y1 > y0) { delay(5000);
y++; closegraph();
return 0; }

OUTPUT:

CONCLUSION:
The Bresenham’s Line Algorithm was successfully implemented to draw a line on the screen. Its
efficiency over the DDA algorithm was observed as it only used integer arithmetic, making it suitable
for real-time applications in computer graphics. To enhance the visual experience, we introduced a
10-millisecond delay in drawing each pixel. This delay allowed us to observe the line being
constructed step by step, creating an animation effect as the line gradually extended from (x1, y1) to
(x2, y2).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy