问题描述
是否可以同时在同一扇形上设置旋转动画和尺寸变化?
我知道它可以被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