是否可以 运行 多个动画,整体 rate_func?

Is it possible to run multiple animations with an overall rate_func?

以下是我目前的代码:

from manimlib.imports import *

class ClockOrganization(VGroup):
  CONFIG = {
    "numbers" : 4,
    "radius" : 3.1,
    "color" : WHITE
  }

  def __init__(self, **kwargs):
    digest_config(self, kwargs, locals())
    self.generate_nodes()
    VGroup.__init__(self, *self.node_list,**kwargs)

  def generate_nodes(self):
    self.node_list = []
    for i in range(self.numbers):
      mobject = VMobject()
      number = TexMobject(str(i+1))
      circle = Circle(radius=0.4,color=self.color)
      mobject.add(number)
      mobject.add(circle)
      mobject.move_to(
        self.radius * np.cos((-TAU / self.numbers) * i + 17*TAU / 84) * RIGHT
        + self.radius * np.sin((-TAU / self.numbers) * i + 17*TAU / 84) * UP
      )
      self.node_list.append(mobject)

  def select_node(self, node):
    selected_node = self.node_list[node]
    selected_node.scale(1.2)
    selected_node.set_color(RED)

  def deselect_node(self, selected_node):
    node = self.node_list[selected_node]
    node.scale(0.8)
    node.set_color(self.color)

class Testing3(Scene):
  def construct(self):
    test = ClockOrganization(numbers=21)
    self.play(Write(test), run_time=1.5)
    animation_steps=[]
    for i in range(10):
      thing = test.deepcopy()
      thing.select_node((19+i)%test.numbers-1)
      animation_steps.append(thing)
    self.play(Transform(test, animation_steps[0]))
    self.wait(2)
    for i in range(1,10):
      self.play(Transform(test, animation_steps[i]),run_time=0.3)
    self.wait()

如果你现在运行它,它突出显示19,然后以统一的速度循环到7。是否可以为整个过程设置一个 rate_func,因此它开始缓慢旋转,中途加速,然后减慢到 7,就像平滑的 rate_func 但应用于整个过程?

我试过把上面的场景class改成

class Testing3(Scene):
  def construct(self):
    test = ClockOrganization(numbers=21)
    self.play(Write(test), run_time=1.5)
    animation_steps=[]
    for i in range(10):
      thing = test.deepcopy()
      thing.select_node((19+i)%test.numbers-1)
      animation_steps.append(thing)
    self.play(Transform(test, animation_steps[0]))
    self.wait(2)
    for i in range(1,10):
      if i in range(1,6):
        time_to_run=(sigmoid(10*(-i/4+.75))-sigmoid(-5))/(1-2*sigmoid(-5)+3)+.1
      if i in range(6,10):
        time_to_run=(sigmoid(10*(i/4-1.75))-sigmoid(-5))/(1-2*sigmoid(-5)+3)+.1
      self.play(Transform(test, animation_steps[i]),run_time=time_to_run)
    self.wait()

它接近我想要的,但转换看起来相当不稳定。

不知道你是不是这个意思:

class Testing4(Scene):
  def construct(self):
    test = ClockOrganization(numbers=21)
    self.play(Write(test), run_time=1.5)
    animation_steps=[]
    #animation_steps.append(test)
    num_circ=15
    for i in range(num_circ):
      thing = test.deepcopy()
      thing.select_node((19+i)%test.numbers-1)
      animation_steps.append(thing)
    test_normal=test.copy()
    test.save_state()
    self.play(Transform(test, animation_steps[0]))
    self.wait(2)
    self.play(Restore(test))
    anims=[]
    for i in range(1,num_circ):
        test.node_list[(19+i)%test.numbers-1].generate_target()
        test.node_list[(19+i)%test.numbers-1].target.scale(1.2)
        test.node_list[(19+i)%test.numbers-1].target.set_color(RED)
        anims.append(MoveToTarget(test.node_list[(19+i)%test.numbers-1],rate_func=there_and_back))
    self.play(
        AnimationGroup(*anims,lag_ratio=0.1)
        )
    self.wait()

或者这样,开始慢,然后增加再慢

class Testing4(Scene):
  def construct(self):
    test = ClockOrganization(numbers=21)
    self.play(Write(test), run_time=1.5)
    animation_steps=[]
    #animation_steps.append(test)
    num_circ=15
    for i in range(num_circ):
      thing = test.deepcopy()
      thing.select_node((19+i)%test.numbers-1)
      animation_steps.append(thing)
    test_normal=test.copy()
    test.save_state()
    self.play(Transform(test, animation_steps[0]))
    self.wait(2)
    self.play(Restore(test))
    anims=[]
    theta=180*DEGREES/num_circ
    lag_constant=5
    for i in range(1,num_circ):
        test.node_list[(19+i)%test.numbers-1].generate_target()
        test.node_list[(19+i)%test.numbers-1].target.scale(1.2)
        test.node_list[(19+i)%test.numbers-1].target.set_color(RED)
        stop_smooth=lag_constant*np.sin(i*theta)
        anims.append(MoveToTarget(test.node_list[(19+i)%test.numbers-1],rate_func=there_and_back))
        anims.append(Animation(Mobject(),run_time=stop_smooth))
    self.play(
        AnimationGroup(*anims,lag_ratio=0.1)
        )
    self.wait()