以下是我当前的代码:
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
但应用于整个过程?>
我尝试将上述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()
,它接近我想要的东西,但是“变形”似乎很不稳定。
答案 0 :(得分: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()
答案 1 :(得分: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=[]
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()