|
|
from manim import *
|
|
|
|
|
|
run_time = 0.8
|
|
|
|
|
|
|
|
|
class CubePrismExample(ThreeDScene):
|
|
|
def construct(self):
|
|
|
self.attr_example01()
|
|
|
self.wait()
|
|
|
self.clear()
|
|
|
|
|
|
self.attr_example02()
|
|
|
self.wait()
|
|
|
self.clear()
|
|
|
|
|
|
self.attr_example03()
|
|
|
self.wait()
|
|
|
self.clear()
|
|
|
|
|
|
self.attr_example04()
|
|
|
self.wait()
|
|
|
|
|
|
def __add_title(self, title_str):
|
|
|
title = Text(
|
|
|
f"{title_str}:",
|
|
|
font="STLiti",
|
|
|
t2g={title_str: [RED, YELLOW, GREEN]},
|
|
|
font_size=25,
|
|
|
)
|
|
|
line = Line(LEFT * 3, RIGHT * 5, color=BLUE).next_to(title, DOWN, buff=0.1)
|
|
|
vg = VGroup(title, line)
|
|
|
self.add_fixed_in_frame_mobjects(vg)
|
|
|
vg.to_corner(UP)
|
|
|
|
|
|
def attr_example01(self):
|
|
|
"""默认显示"""
|
|
|
self.__add_title("东师理想数学AI助手")
|
|
|
|
|
|
self.set_camera_orientation(phi=2 * PI / 5, theta=PI / 5)
|
|
|
|
|
|
axes = ThreeDAxes(x_length=8, y_length=6, z_length=5)
|
|
|
self.add(axes)
|
|
|
|
|
|
# 创建一个立方体
|
|
|
cube = Cube()
|
|
|
self.play(Create(cube), run_time=run_time)
|
|
|
self.wait()
|
|
|
self.play(FadeOut(cube), run_time=0.5)
|
|
|
# 创建一个棱柱
|
|
|
prism = Prism()
|
|
|
# 显示立方体和棱柱
|
|
|
self.play(Create(prism), run_time=run_time)
|
|
|
|
|
|
def attr_example02(self):
|
|
|
"""变换颜色"""
|
|
|
self.__add_title("变换颜色")
|
|
|
|
|
|
self.set_camera_orientation(PI / 3, -PI / 4)
|
|
|
|
|
|
axes = ThreeDAxes(x_length=8, y_length=6, z_length=5)
|
|
|
self.add(axes)
|
|
|
|
|
|
# 创建一个立方体
|
|
|
cube = Cube()
|
|
|
self.play(Create(cube), run_time=run_time)
|
|
|
cube2 = Cube(fill_color=RED)
|
|
|
self.play(ReplacementTransform(cube, cube2), run_time=run_time)
|
|
|
self.play(FadeOut(cube2), run_time=0.5)
|
|
|
|
|
|
# 创建一个棱柱
|
|
|
prism = Prism()
|
|
|
self.play(Create(prism), run_time=run_time)
|
|
|
prism2 = Prism(fill_color=GREEN)
|
|
|
self.play(ReplacementTransform(prism, prism2), run_time=run_time)
|
|
|
|
|
|
def attr_example03(self):
|
|
|
"""移动和旋转"""
|
|
|
self.__add_title("移动和旋转")
|
|
|
|
|
|
self.set_camera_orientation(PI / 3, -PI / 4)
|
|
|
|
|
|
axes = ThreeDAxes(x_length=8, y_length=6, z_length=5)
|
|
|
self.add(axes)
|
|
|
# 创建一个立方体
|
|
|
cube = Cube(fill_color=RED)
|
|
|
# 创建一个棱柱
|
|
|
prism = Prism(fill_color=GREEN)
|
|
|
|
|
|
self.play(Create(cube), Create(prism)) # 显示立方体和棱柱
|
|
|
self.wait()
|
|
|
|
|
|
# 移动
|
|
|
self.play(
|
|
|
cube.animate.shift(RIGHT),
|
|
|
prism.animate.shift(LEFT),
|
|
|
run_time=run_time,
|
|
|
)
|
|
|
# 旋转
|
|
|
self.play(
|
|
|
cube.animate.rotate(PI / 4, axis=UP),
|
|
|
prism.animate.rotate(-PI / 4, axis=UP),
|
|
|
run_time=run_time,
|
|
|
)
|
|
|
|
|
|
def attr_example04(self):
|
|
|
"""组合使用"""
|
|
|
self.__add_title("组合使用")
|
|
|
|
|
|
self.set_camera_orientation(PI / 3, -PI / 4)
|
|
|
|
|
|
axes = ThreeDAxes(x_length=8, y_length=6, z_length=5)
|
|
|
self.add(axes)
|
|
|
|
|
|
# 创建一个立方体
|
|
|
cube = Cube(fill_color=RED).scale(0.8)
|
|
|
# 创建一个棱柱
|
|
|
prism = Prism(fill_color=GREEN).scale(0.8)
|
|
|
# 将立方体放在棱柱的右边
|
|
|
cube.next_to(prism, RIGHT, buff=0)
|
|
|
|
|
|
# 组合使用
|
|
|
vg = VGroup(cube, prism)
|
|
|
self.play(Create(vg), run_time=run_time)
|
|
|
self.wait()
|
|
|
|
|
|
# 整体移动组合
|
|
|
self.play(vg.animate.shift(UP), run_time=run_time)
|
|
|
# 整体旋转组合
|
|
|
self.play(vg.animate.rotate(PI / 2, axis=UP), run_time=run_time)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
config = {
|
|
|
"quality": "high_quality",
|
|
|
"preview": True,
|
|
|
"media_dir": "./output",
|
|
|
"pixel_height": 1080,
|
|
|
"pixel_width": 1920,
|
|
|
"background_color": "#1E1E1E"
|
|
|
}
|
|
|
|
|
|
with tempconfig(config):
|
|
|
scene = CubePrismExample()
|
|
|
scene.render()
|