编辑代码

from manim import *

class CubeUnfolding(ThreeDScene):
    def construct(self):
        # 创建立方体
        cube = Cube(side_length=2, fill_opacity=0.8, fill_color=BLUE)
        cube.set_stroke(WHITE, width=2)

        # 展开动画
        self.set_camera_orientation(phi=75*DEGREES, theta=-45*DEGREES)
        self.play(Create(cube))
        self.wait(1)
        
        # 分解面片
        faces = VGroup(*[cube[i].copy() for i in range(6)])
        self.play(
            cube.animate.set_opacity(0.2),
            *[face.animate.move_to(ORIGIN) for face in faces]
        )
        
        # 展开布局
        cross = VGroup(
            faces[0].move_to(UP*2),
            faces[1].move_to(DOWN*2),
            faces[2].move_to(LEFT*2),
            faces[3].move_to(RIGHT*2),
            faces[4].move_to(LEFT*4),
            faces[5].move_to(RIGHT*4)
        )
        
        self.play(
            Transform(faces, cross, run_time=3),
            self.camera.frame.animate.set_width(14)
        )
        self.wait(2)