Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: lab manuals
Description: university notes graphical lab mnuall

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


Computer Graphics
Lab Manuals
Q1
...
pyplot as plt

def draw_line_DDA(x1, y1, x2, y2):
# Calculate the differences
dx = x2 - x1
dy = y2 - y1

# Determine the number of steps needed
steps = abs(dx) if abs(dx) > abs(dy) else abs(dy)

# Calculate the increment in x and y for each step
x_increment = dx / float(steps)
y_increment = dy / float(steps)

# Generate the points along the line
x = x1
y = y1
line_points = []
for _ in range(steps + 1):

line_points
...
plot(x_coords, y_coords, marker='o')
plt
...
ylabel('Y')
plt
...
grid(True)
plt
...
Write a program to draw a line using Bresenham algorithm
import matplotlib
...
append((x1, y1))
if x1 == x2 and y1 == y2:
break
e2 = 2 * err
if e2 > -dy:

err -= dy
x1 += sx
if e2 < dx:
err += dx
y1 += sy

return line_points

def plot_line(points):
x_coords, y_coords = zip(*points)
plt
...
xlabel('X')
plt
...
title('Line Drawing using Bresenham Algorithm')
plt
...
show()

# Define the start and end points of the line
x1, y1 = 2, 3
x2, y2 = 10, 8

# Get the points for the line

line_points = draw_line_bresenham(x1, y1, x2, y2)

# Plot the line
plot_line(line_points)

output
pip install matplotlib
Q3
...
pyplot as plt

def draw_circle_bresenham(x_center, y_center, radius):
circle_points = []
x=0
y = radius
d = 3 - 2 * radius
circle_points
...
extend(plot_circle_points(x_center, y_center, x, y))

return circle_points

def plot_circle_points(x_center, y_center, x, y):
return [
(x_center + x, y_center + y),
(x_center - x, y_center + y),
(x_center + x, y_center - y),
(x_center - x, y_center - y),
(x_center + y, y_center + x),
(x_center - y, y_center + x),
(x_center + y, y_center - x),
(x_center - y, y_center - x)
]

def plot_circle(points):
x_coords, y_coords = zip(*points)
plt
...
xlabel('X')

plt
...
title('Circle Drawing using Bresenham Algorithm')
plt
...
set_aspect('equal', adjustable='box')
plt
...
show()

# Define the center and radius of the circle
x_center, y_center = 0, 0
radius = 10

# Get the points for the circle
circle_points = draw_circle_bresenham(x_center, y_center, radius)

# Plot the circle
plot_circle(circle_points)

output
pip install matplotlib

Q5
...
pyplot as plt

def translate_2d(points, tx, ty):
"""
Translates a list of points by tx in the x direction and ty in the y direction
...


:param points: List of tuples representing the points (x, y)
:param title: Title of the plot
:param color: Color of the points and lines
"""
x_coords, y_coords = zip(*points)
plt
...
xlabel('X')
plt
...
title(title)
plt
...
gca()
...
g
...
figure()

plot_points(original_points, 'Original Object', color='b')
plot_points(translated_points, 'Translated Object', color='r')

plt
...
show()

output
pip install matplotlib

Q6
...
pyplot as plt
import math

def rotate_2d(points, angle_degrees, origin=(0, 0)):
angle_radians = math
...
cos(angle_radians)
sin_angle = math
...
append((rotated_x + origin_x, rotated_y + origin_y))
return rotated_points

def plot_points(original_points, rotated_points):
original_x, original_y = zip(*original_points)
rotated_x, rotated_y = zip(*rotated_points)

plt
...
scatter(original_x, original_y, color='blue', label='Original Points')
plt
...
xlabel('X')
plt
...
title('2D Rotation')
plt
...
grid(True)
plt
...
Write a program to perform 2D Scaling
import matplotlib
...
append((scaled_x, scaled_y))
return scaled_points

def plot_points(original_points, scaled_points):
original_x, original_y = zip(*original_points)
scaled_x, scaled_y = zip(*scaled_points)

plt
...
scatter(original_x, original_y, color='blue', label='Original Points')
plt
...
xlabel('X')
plt
...
title('2D Scaling')
plt
...
grid(True)
plt
...
5

# Get the scaled points

scaled_points = scale_2d(original_points, sx, sy)

# Plot the original and scaled points
plot_points(original_points, scaled_points)

OUTPUT
pip install matplotlib
Q8
...
locals import *
from OpenGL
...
GLU import *
import math

# Define the windmill components
def draw_windmill():
# Draw the base of the windmill
glColor3f(0
...
8, 0
...
radians(90 * i)
x = blade_length * math
...
sin(angle)
glBegin(GL_QUADS)
glVertex3f(0, 0, 0)
glVertex3f(x, y, 0)
glVertex3f(x * 0
...
2, 0)
glVertex3f(0, 0, 0)
glEnd()

def main():
pygame
...
display
...
1, 50
...
0, 0
...
event
...
type == pygame
...
quit()
return

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glPushMatrix()

glRotatef(angle, 0, 0, 1)
draw_windmill()

glPopMatrix()

pygame
...
flip()
pygame
...
wait(30)
angle += 2

if __name__ == "__main__":
main()

OUTPUT
pip install PyOpenGL PyOpenGL_accelerate pygame


Title: lab manuals
Description: university notes graphical lab mnuall