-
Notifications
You must be signed in to change notification settings - Fork 5
/
scene.py
87 lines (70 loc) · 2.42 KB
/
scene.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from manim import *
import numpy as np
import os
# Disable all preview functionality
config.preview = False
config.show_in_file_browser = False
config.save_last_frame = False
config.write_to_movie = True
config.disable_caching = True
config.renderer = "cairo"
config.preview_command = ""
class ContainerScene(ThreeDScene):
def render(self, preview=None):
"""Override render to prevent preview attempts"""
self.setup()
self.construct()
self.tear_down()
# Skip any preview attempts
if hasattr(self, "renderer") and hasattr(self.renderer, "file_writer"):
self.renderer.file_writer.close_movie_pipe()
class MainScene(ContainerScene):
def construct(self):
# Set camera
self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
# Create axes
axes = ThreeDAxes(
x_range=[-3, 3],
y_range=[-3, 3],
z_range=[-2, 4],
x_length=6,
y_length=6,
z_length=4
)
# Create grid
grid = NumberPlane(
x_range=[-3, 3],
y_range=[-3, 3],
background_line_style={
"stroke_opacity": 0.4
}
)
grid.rotate(PI/2, RIGHT)
# Create geometric shapes
shapes = VGroup()
# Add different geometric objects
cube = Cube(side_length=1, fill_opacity=0.8)
sphere = Sphere(radius=0.5, fill_opacity=0.8)
torus = Torus(major_radius=0.6, minor_radius=0.2, fill_opacity=0.8)
shapes.add(cube, sphere, torus)
# Position shapes
cube.move_to(np.array([-2, 0, 1]))
sphere.move_to(np.array([0, 0, 1]))
torus.move_to(np.array([2, 0, 1]))
# Color gradient for shapes
for i, shape in enumerate(shapes):
shape.set_color(interpolate_color(RED, BLUE, i/2))
# Add everything to scene
self.begin_ambient_camera_rotation(rate=0.2)
# Create and animate axes and grid
self.play(Create(axes), Create(grid), run_time=1)
# Animate shapes
self.play(Create(shapes), run_time=2)
# Add some camera movement
self.wait(2)
# Final rotation
self.play(
Rotate(shapes, angle=PI, axis=UP),
run_time=2
)
self.wait()