Lab.3_Computer Graphics
Lab.3_Computer Graphics
Graphics
Lab.3
Start
Code:
import bpy
bpy.ops.mesh.primitive_cube_add()
bpy.ops.mesh.primitive_cube_add()
c = bpy.context.active_object
Code:
import bpy
import math
𝒙 = 𝒓 ∙ 𝐜𝐨𝐬(𝜽)
𝒚 = 𝒓 ∙ 𝐬𝐢𝐧(𝜽)
where:
• 𝒓 is the radius of the circle.
• 𝜽 is the current angle in radians.
• (𝒙, 𝒚) are the coordinates of the object on the circle.
We calculate the x, y coordinates values based on the radius (which is a constant) and 𝜽
So, as angle(𝜽) increases, the x, y coordinates move smoothly around the circle.
Move the Sphere in a Circular Path: Use a while loop to update the sphere’s position in a
circle.
o Compute the new (x, y) coordinates using cosine & sine functions.
o Insert a keyframe at each step for animation.
o Increase angle to move the sphere forward in the circular path.
o Increase f to control the animation speed.
Full Code:
import bpy
import math
bpy.ops.mesh.primitive_uv_sphere_add()
planet = bpy.context.active_object
Task.1: First task is to create a moon that orbits (moves in a circular path)
around a planet
Task.2: Create multiple planets that move at different speeds, each rotating on
its axis.