Spinning 3D Shapes
Run the Spinning 3D Shapes MicroSim Fullscreen
About This MicroSim
This MicroSim demonstrates p5.js's powerful WebGL capabilities for creating 3D graphics directly in the browser. It features a central rotating torus (donut shape) with multiple orbiting shapes including spheres, boxes, and cones, creating a visually engaging "solar system" or "atom" effect.
Interactive Controls
- Mouse X Position: Controls rotation speed (move left for slower, right for faster)
- Mouse Y Position: Controls lighting intensity (move up for brighter, down for dimmer)
- Click: Cycles through different color schemes (Teal, Purple, Orange, Green, Pink)
- Drag: Orbits the camera around the scene to view from different angles
3D Concepts Demonstrated
- WEBGL Rendering Mode: Uses GPU-accelerated 3D rendering
- 3D Transformations:
rotateX(),rotateY(),rotateZ()for rotation - 3D Translation:
translate()to position objects in 3D space - 3D Primitives:
sphere(),box(),torus(),cone() - Lighting:
ambientLight(),directionalLight(),pointLight() - Camera Control:
orbitControl()for interactive viewing
Embed This MicroSim
You can include this MicroSim on your website using the following iframe:
1 2 3 4 5 | |
Description
This simulation creates an immersive 3D scene with:
- A central torus (donut shape) that rotates smoothly on multiple axes
- Five orbiting shapes (spheres, boxes, and cones) that follow circular paths at different speeds and orbital inclinations
- Background stars scattered in 3D space for a cosmic atmosphere
- Dynamic lighting that responds to mouse position
- HSB color mode for vibrant, easily manipulable colors
The animation demonstrates how p5.js handles 3D graphics as elegantly as 2D, using the same familiar setup() and draw() pattern. Students can see that 3D programming is simply an extension of 2D concepts with an additional Z-axis dimension.
How It Works
The core animation loop updates a rotation angle each frame:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Each shape uses push() and pop() to isolate its transformations, allowing independent rotation and positioning.
Lesson Plan
Grade Level
Middle School to High School (Grades 6-12)
Learning Objectives
By the end of this lesson, students will be able to:
- Understand how WebGL enables 3D graphics in web browsers
- Identify the three axes (X, Y, Z) in 3D coordinate systems
- Apply rotation and translation transformations to 3D objects
- Recognize how lighting affects the perception of 3D shapes
- Experiment with parameters to observe cause-and-effect relationships
Suggested Activities
- Exploration Phase (5 minutes)
- Have students interact with the simulation using mouse controls
- Ask: "What happens when you move the mouse left to right? Up and down?"
-
Click to cycle through color schemes
-
Observation Questions (5 minutes)
- How many different types of 3D shapes can you identify?
- Which shapes orbit faster? Which orbit slower?
-
How does the lighting change the appearance of the shapes?
-
3D Concepts Discussion (10 minutes)
- Introduce the X, Y, Z coordinate system
- Explain rotation around each axis
-
Discuss how translation moves objects in 3D space
-
Code Exploration (Optional, 10 minutes)
- Open the code in p5.js editor
- Modify orbital speeds, shape sizes, or colors
- Add additional orbiting shapes
Extension Activities
- Add a slider to control the number of orbiting shapes
- Create a "pause" button to freeze the animation
- Experiment with different 3D primitives (cylinder, ellipsoid)
- Add texture mapping to shapes
Technical Notes
- Uses WEBGL mode which leverages GPU acceleration for smooth 3D rendering
- HSB color mode (Hue, Saturation, Brightness) makes it easy to create rainbow progressions
- Specular materials create shiny, reflective surfaces
- Fixed 400x400 canvas provides consistent viewing experience
- Compatible with modern browsers supporting WebGL (Chrome, Firefox, Safari, Edge)