Lab.1_Computer Graphics
Lab.1_Computer Graphics
Graphics
Lab.1
Note: Always delete the default cube in the scene to clearly view your code creation.
Right-click on
the cube and
then select
"Delete."
Blender has a built-in Python API (Application Programming Interface) called bpy, that allows
users to interact with and control Blender programmatically. It provides access to Blender's
internal functions for modeling, animation, rendering, scene management, and UI scripting.
Module Purpose
bpy.ops Operators (perform actions like adding, deleting, modifying objects).
bpy.context Get information about the current selection, mode, and active objects.
bpy.types Define new classes and UI elements (useful for add-ons).
1. Creating a 3D Object in Blender
First, Create a new file to write the code
import bpy
import bpy
bpy.ops.mesh.primitive_cube_add()
What is a Frame?
A frame is a single moment in an animation.
Blender plays animations frame by frame, just like a movie.
• If an animation runs at 24 FPS (frames per second), it means 24 frames will be shown
every second.
• If an animation runs at 60 FPS, it means 60 frames are shown per second.
Example:
• Frame 1 = Start of the animation.
• Frame 100 = Later in the animation (depends on FPS, at 24 FPS, frame 100 ≈ 4
seconds).
What is a Keyframe?
A keyframe is a marker that saves an object's property (like position, rotation, scale) at a
specific frame.
Blender automatically generates smooth transitions between keyframes.
Example:
• At frame 1, the object is at (0,0,0).
• At frame 100, the object moves to (5,5,5).
• Blender automatically interpolates (fills in) the movement between these
frames.
Solution:
Frame 1
Frame 100
Frame 200
Lab.1
Animating Two Spheres Moving in Opposite Directions While
Staying Parallel
Task Description
Create an animation in Blender where:
Solution:
import bpy