Gyanveer University
School of computer science and application
Practical
Computer File
Graphics
BCA142P
Name: Mangesh deo
Enrollment no.: 23GUS13BCA1002 Roll no.: 230113
Class: BCA Semester: 4th
Session: 2024-25
Submitted By Submitted To
Mangesh deo Mr. Dinesh Patel Sir
Signature
Index
S. Page Topic
No. No.
1 1 Draw line using DDA Algorithm
2 4 Draw a line using Bresenham’s Algorithm
3 7 Draw a circle using Midpoint circle Algorithm
4 10 Draw a circle using DDA algorithm
5 13 Polygon fill using Boundary fill algorithm
6 15 Polygon fill using Flood fill algorithm
7 17 2D translation in computer graphics
8 19 2D scaling in computer graphics
9 21 2D rotation in computer graphics
10 23 2D shearing in computer graphics
11 25 2D reflection in computer graphics
12 27 Point clipping in computer graphics
13 30 Line clipping using Cohen-Sutherland algorithm
14 32 Composite Transformation in computer graphics
15 34 Window to viewport in computer graphics
Experiment 1
Aim: Draw a line using DDA Algorithm.
Algorithm:
Let’s assume you want to draw a line from (x1, y1) to (x2, y2) then,
Calculate the difference dx = x2 – x1 and dy = y2 – y1.
Then get the steps by max(|dx|, |dy|).
Now calculate the xinc and yinc using,
o xinc = dx / steps,
o yinc = dy / steps.
Now start from x = x1 and y = y1.
For each step:
o Plot(x, y),
o x += xinc,
o y += yinc.
End of algorithm.
1|Page
Code:
2|Page
Output:
3|Page
Experiment 2
Aim: Draw a line using Bresenham’s algorithm.
Algorithm:
Let’s assume you want to draw a line from (x1, y1) to (x2, y2) then,
Calculate the difference dx = x2 – x1 and dy = y2 – y1,
Now calculate the p using,
o P = 2dy – dx
Now start with x = x1 and y = y1,
Now for each x
o Plot(x, y),
o x = x + 1,
o if p < 0 then
p = p + 2dy,
o else
y = y + 1,
p = p + 2dy – 2dx
End of algorithm.
4|Page
Code:
5|Page
Output:
6|Page
Experiment 3
Aim: Draw a circle using midpoint circle algorithm.
Algorithm:
Let’s assume that you want to draw a circle of (xc, yc) and radius
of r.
Start from x = 0 and y = r,
Calculate p = 1 – r.
While x < y then
o Plot 8 points,
(xc + x, yc + y)
(xc – x, yc + y)
(xc + x, yc – y)
(xc – x, yc – y)
(xc + y, yc + x)
(xc – y, yc + x)
(xc + y, yc – x)
(xc – y, yc – x)
o If p < 0 then
p = p + 2x + 3
o else
y = y−1,
p = p + 2x – 2y + 5
End of algorithm.
7|Page
Code:
8|Page
Output:
9|Page
Experiment 4
Aim: Draw a circle using DDA algorithm.
Algorithm:
Let’s assume that you want to draw a circle of (xc, yc) for radius r
then,
Set center (xc, yc) and radius r,
Now for 0 from 0 to 360 or 0 to 2 π,
o Calculate x = xc + r * cos(θ),
o Calculate y = yc + r * sin(θ)
o Plot(x, y)
End of algorithm.
10 | P a g e
Code:
11 | P a g e
Output:
12 | P a g e
Experiment 5
Aim: Polygon fill using Boundary fill algorithm.
Code:
13 | P a g e
Output:
14 | P a g e
Experiment 6
Aim: Polygon fill using Flood fill algorithm.
Code:
15 | P a g e
Output:
16 | P a g e
Experiment 7
Aim: 2D translation in computer graphics.
Code:
17 | P a g e
Output:
18 | P a g e
Experiment 8
Aim: 2D scaling in computer graphics.
Code:
19 | P a g e
Output:
20 | P a g e
Experiment 9
Aim: 2D rotation in computer graphics.
Code:
21 | P a g e
Output:
22 | P a g e
Experiment 10
Aim: 2D shearing in computer graphics.
Code:
23 | P a g e
Output:
24 | P a g e
Experiment 11
Aim: 2D reflection in computer graphics.
Code:
25 | P a g e
Output:
26 | P a g e
Experiment 12
Aim: Point clipping in computer graphics.
Code:
27 | P a g e
Output:
28 | P a g e
29 | P a g e
Experiment 13
Aim: Line clipping using Cohen-Sutherland algorithm.
Code:
30 | P a g e
Output:
31 | P a g e
Experiment 14
Aim: Composite Transformation in computer graphics.
Code:
32 | P a g e
Output:
33 | P a g e
Experiment 15
Aim: Window to viewport in computer graphics.
Code:
34 | P a g e
Output:
35 | P a g e