如何为manim中的一个扇形同时改变角度和旋转动画

问题描述

是否可以同时在同一扇形上设置旋转动画和尺寸变化?

我知道它可以被Transform欺骗,从而将其变成另一个部门。但这没有我想要的动画。 Transform缩小然后扩展。我希望扇区在更改大小的同时旋转。

我可以同时获得想要的两种效果

我已经尝试过但找不到manim的API。我见过readthedocs,但这不是显示每个类的所有方法和变量的API。

class Test(Scene):
    def construct(self):
        rotateGroup=VGroup(*[SmallDot()],Sector(angle=45*degrees,start_angle=25*degrees,stroke_width=0,fill_color=RED),Sector(angle=135*degrees,start_angle=185*degrees,fill_color=GREEN))\
                                  .shift(RIGHT,DOWN)
        # Start
        self.add(rotateGroup[1])
        self.wait()
        self.play(FadeOut(rotateGroup[1]),# Ideal finishing position
                  FadeIn(rotateGroup[2]))
        self.wait()
        self.remove(rotateGroup[2])
        copy1=rotateGroup[1].copy()
        copy2=rotateGroup[2].copy()
        copy3=rotateGroup[1].copy()
        self.add(copy1)
        self.wait()

        # This has the desired rotation but lacks the size change
        self.play(Rotating(copy1,axis=OUT,run_time=2,about_point=rotateGroup[0].get_center(),radians=170*degrees,rate_func=smooth))
        self.wait()
        self.remove(copy1)

        # This has the size change but lacks the correct rotation
        self.add(copy3)
        self.play(Transform(copy3,copy2))

谢谢。

解决方法

class Test(Scene):
    def construct(self):
        rotateGroup=VGroup(
            Sector(angle=45*DEGREES,start_angle=25*DEGREES,stroke_width=0,fill_color=RED
            ),Sector(angle=135*DEGREES,start_angle=185*DEGREES,fill_color=GREEN
                    )
        )
        red_sector,green_sector = rotateGroup
        # -----------------------------------------------
        red_sector.save_state()
        def update_sector(mob,alpha):
            mob.restore()
            angle = interpolate(45*DEGREES,135*DEGREES,alpha)
            start_angle = interpolate(25*DEGREES,185*DEGREES,alpha)
            mob.become(
                Sector(
                    angle=angle,start_angle=start_angle,fill_color=interpolate_color(RED,GREEN,alpha)
                )
            )
        self.play(
            UpdateFromAlphaFunc(red_sector,update_sector)
        )
        self.wait()

作为一项任务,请尝试制作custon动画,教程here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...