python - 如何在manim中为扇区的角度和旋转同时变化设置动画
问题描述
是否可以同时在同一个扇区上设置旋转和大小变化的动画?
我知道它可以被欺骗,Transform
把它变成一个不同的部门。但这没有我想要的动画。Transform
收缩然后膨胀。我希望扇区在改变大小的同时旋转。
我可以得到我想要的两种效果,但不能同时得到。
我已尝试但未能找到manim
. 我看过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,
stroke_width=0,
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,
stroke_width=0,
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,
stroke_width=0,
fill_color=interpolate_color(RED,GREEN,alpha)
)
)
self.play(
UpdateFromAlphaFunc(red_sector,update_sector)
)
self.wait()
作为一个任务,尝试做一个自定义动画,教程在这里
推荐阅读
- ide - 我可以有 CLion 项目窗格着色的图例吗?
- java - Univocity - 解析 CSV 时检测缺失的列
- html - 如何在 CSS 中使用 ::before 和 ::after 将形状(变换)相互叠加?边缘不会在背景上显示形状
- javascript - 如何使用 D3 和 javascript 从 csv 创建交互式可折叠树图?
- python - 在 Windows 上通过 Apache Lounge 部署烧瓶应用程序时出现内部服务器错误
- excel - 从另一个单元格复制数据(如果语句,也许?)
- typescript - 检查 null / undefined 的打字稿函数
- python - 什么样的过滤器适合在 OpenCV 中检测土壤上的裂缝?
- c# - 当 WebBrowser 完成文件下载时进行事件
- python - Pipenv 安装:没有名为“...”的模块