Creating Inner Planets Orbit Animation
Inner Planets Orbit - 3D Voxel Animation
This guide walks you through how to generate a looping 3D voxel animation of the inner planets orbiting the Sun using SpatialStudio.
The script creates a realistic solar system model showing Mercury, Venus, Earth, and Mars in their orbital paths around a glowing Sun inside a cubic 3D space, then saves the animation to a .splv
file.
What this script does
- Creates a 3D scene of size 128×128×128
- Spawns the Sun at the center with:
- A bright yellow-orange glowing sphere
- Subtle surface texture variations
- Radial light emission effects
- Animates 4 inner planets (Mercury, Venus, Earth, Mars) with:
- Accurate relative sizes and colors
- Elliptical orbital paths at different speeds
- Individual rotation on their axes
- Runs for 12 seconds at 24 FPS showing multiple orbital cycles
- Outputs the file
inner_planets_orbit.splv
that you can play in your viewer
How it works (simplified)
-
Voxel volume Each frame is a 3D grid filled with RGBA values (
SIZE × SIZE × SIZE × 4
). -
Central Sun The Sun is drawn as a large sphere with animated surface patterns and a bright glow effect.
-
Planet orbits Each planet follows an elliptical path calculated using trigonometric functions, with Mercury orbiting fastest and Mars slowest.
-
Planet rendering Planets are drawn as textured spheres with realistic colors (gray Mercury, bright Venus, blue-green Earth, red Mars).
-
Animation timing A normalized time variable
t
cycles from0 → 2π
, with each planet having different orbital periods for realistic motion. -
Encoding Frames are passed into
splv.Encoder
, which writes them into the.splv
video file.
Try it yourself
Install requirements first:
pip install spatialstudio numpy tqdm
Then copy this script into inner_planets_orbit.py
and run:
python inner_planets_orbit.py
Full Script
import numpy as np
from spatialstudio import splv
from tqdm import tqdm
# Scene setup
SIZE, FPS, SECONDS = 128, 24, 12
FRAMES = FPS * SECONDS
CENTER_X = CENTER_Y = CENTER_Z = SIZE // 2
OUT_PATH = "../outputs/inner_planets_orbit.splv"
# Solar system settings
SUN_RADIUS = 8
PLANET_DATA = [
{"name": "Mercury", "radius": 2, "orbit_radius": 18, "speed": 4.0, "color": (169, 169, 169)},
{"name": "Venus", "radius": 3, "orbit_radius": 25, "speed": 1.6, "color": (255, 198, 73)},
{"name": "Earth", "radius": 3, "orbit_radius": 32, "speed": 1.0, "color": (100, 149, 237)},
{"name": "Mars", "radius": 2, "orbit_radius": 40, "speed": 0.5, "color": (205, 92, 92)}
]
def add_voxel(volume, x, y, z, color):
if 0 <= x < SIZE and 0 <= y < SIZE and 0 <= z < SIZE:
volume[x, y, z, :3] = color
volume[x, y, z, 3] = 255
def generate_sun(volume, cx, cy, cz, t):
sun_color = (255, 215, 0)
glow_color = (255, 165, 0)
# Main sun body with surface texture
for dx in range(-SUN_RADIUS-2, SUN_RADIUS+3):
for dy in range(-SUN_RADIUS-2, SUN_RADIUS+3):
for dz in range(-SUN_RADIUS-2, SUN_RADIUS+3):
distance = np.sqrt(dx*dx + dy*dy + dz*dz)
# Sun core
if distance <= SUN_RADIUS:
surface_var = np.sin(dx*0.4 + t*2) * np.cos(dy*0.3 + t*1.5) * np.sin(dz*0.5 + t*1.8)
brightness = 1.0 + surface_var * 0.2
final_color = tuple(min(255, int(c * brightness)) for c in sun_color)
add_voxel(volume, cx+dx, cy+dy, cz+dz, final_color)
# Sun glow effect
elif distance <= SUN_RADIUS + 2:
glow_intensity = 1.0 - (distance - SUN_RADIUS) / 2.0
glow_final = tuple(int(c * glow_intensity * 0.6) for c in glow_color)
add_voxel(volume, cx+dx, cy+dy, cz+dz, glow_final)
def generate_planet(volume, cx, cy, cz, radius, color, t, rotation_speed=1.0):
for dx in range(-radius-1, radius+2):
for dy in range(-radius-1, radius+2):
for dz in range(-radius-1, radius+2):
distance = np.sqrt(dx*dx + dy*dy + dz*dz)
if distance <= radius:
# Add surface texture based on planet rotation
texture = np.sin(dx*0.5 + t*rotation_speed) * np.cos(dy*0.3) * np.sin(dz*0.4 + t*rotation_speed*0.7)
brightness = 0.8 + texture * 0.3
# Add some shading based on distance from center
shade = 1.0 - (distance / radius) * 0.2
brightness *= shade
final_color = tuple(max(0, min(255, int(c * brightness))) for c in color)
add_voxel(volume, cx+dx, cy+dy, cz+dz, final_color)
def generate_orbital_system(volume, t):
# Generate the Sun
generate_sun(volume, CENTER_X, CENTER_Y, CENTER_Z, t)
# Generate each planet in its orbit
for planet in PLANET_DATA:
# Calculate orbital position
angle = t * planet["speed"]
# Add slight elliptical orbit variation
orbit_variation = planet["orbit_radius"] + np.sin(angle * 2) * 2
# Calculate 3D position (orbiting in XZ plane with slight Y variation)
px = CENTER_X + int(orbit_variation * np.cos(angle))
py = CENTER_Y + int(np.sin(angle * 0.3) * 3) # Slight vertical variation
pz = CENTER_Z + int(orbit_variation * np.sin(angle))
# Generate the planet with its own rotation
generate_planet(volume, px, py, pz, planet["radius"], planet["color"], t, planet["speed"]*2)
def add_orbit_trails(volume, t):
trail_color = (50, 50, 50)
# Draw faint orbital paths
for planet in PLANET_DATA:
radius = planet["orbit_radius"]
for i in range(0, 360, 8): # Every 8 degrees
angle = np.radians(i)
x = CENTER_X + int(radius * np.cos(angle))
z = CENTER_Z + int(radius * np.sin(angle))
# Only show trail occasionally for visual clarity
if (int(t*10) + i) % 32 < 4:
add_voxel(volume, x, CENTER_Y, z, trail_color)
def generate_scene(volume, t):
add_orbit_trails(volume, t)
generate_orbital_system(volume, t)
# Initialize encoder
enc = splv.Encoder(SIZE, SIZE, SIZE, framerate=FPS, outputPath=OUT_PATH, motionVectors="off")
# Generate animation frames
for frame in tqdm(range(FRAMES), desc="Generating inner planets orbit"):
volume = np.zeros((SIZE, SIZE, SIZE, 4), dtype=np.uint8)
t = (frame / FRAMES) * 2*np.pi
generate_scene(volume, t)
enc.encode(splv.Frame(volume, lrAxis="x", udAxis="y", fbAxis="z"))
enc.finish()
print(f"Created {OUT_PATH}")
Next steps
- Adjust
PLANET_DATA
to modify orbital speeds, sizes, or colors - Add asteroid belt by creating small rocks between Mars and Jupiter's orbit
- Include planet moons (like Earth's Moon) with their own sub-orbits
- Experiment with different orbital inclinations by modifying the Y-axis calculations
- Add starfield background by sprinkling white pixels in the distant volume
- Increase
SECONDS
to show longer orbital periods and planet alignments
Educational notes
This animation demonstrates several astronomical concepts:
- Orbital mechanics: Inner planets orbit faster than outer ones (Kepler's laws)
- Relative sizes: Planets are scaled proportionally to show size differences
- Rotation periods: Each planet spins on its axis while orbiting
- Solar dominance: The Sun's size and brightness show its gravitational influence
The animation completes multiple Mercury orbits while Mars barely completes one, accurately representing the relative orbital periods of our solar system's inner planets.