3

以下是我当前的代码:

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为整个过程设置 a,使其开始缓慢旋转,中途加速,然后减慢至 7,就像平滑rate_func但应用于整个过程?

我尝试将上面的 Scene 类更改为

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()

它接近我想要的,但变换似乎相当波涛汹涌。

4

2 回答 2

2

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

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()
于 2019-05-27T00:59:06.347 回答
1

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

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()
于 2019-05-27T00:36:49.320 回答