如何使用Manim在数字行上动画点动画?
我想使用Manim在数字线上对参数的位置进行动画动画。我想出了如何使用parametricfunction将参数的终端位置作为线的动画:
from manim import *
import numpy as np
import math
class line( Scene ):
def construct( self ):
tline = NumberLine(
x_range=[ 0, 1 ],
length=4,
color=BLUE,
include_numbers=False )
t1 = ParametricFunction( lambda t: tline.number_to_point(np.sin(t * PI)),
t_range=[0, 1],
scaling=tline.scaling, color=YELLOW )
self.play( DrawBorderThenFill( VGroup( tline ) ), run_time = 2 )
self.play( AnimationGroup(Create(t1)), run_time = 6 )
这对单调增加值可以奏效,但是如果终点重新倍增本身,则不太好,因为动画在该阶段变得不可见。
有没有办法更改线图来动画动画动画,而不是跟踪线路?
I'd like to use Manim to animate the position of a parameter on a number line. I figured out how to animate the end position of the parameter as a line using ParametricFunction:
from manim import *
import numpy as np
import math
class line( Scene ):
def construct( self ):
tline = NumberLine(
x_range=[ 0, 1 ],
length=4,
color=BLUE,
include_numbers=False )
t1 = ParametricFunction( lambda t: tline.number_to_point(np.sin(t * PI)),
t_range=[0, 1],
scaling=tline.scaling, color=YELLOW )
self.play( DrawBorderThenFill( VGroup( tline ) ), run_time = 2 )
self.play( AnimationGroup(Create(t1)), run_time = 6 )
This works okay for monotonically increasing values, but is no good if the end point doubles back on itself, as the animation becomes invisible at that stage.
Is there a way to change the line plot to animate a moving point instead of tracing out a line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的参数只是在某些固定值之间移动,则可以按照文档中的示例。
如果您想对标记在数字行中移动的确切方式进行更多控制,我建议您复制与
valueTracker
和updatefromalphafunc
动画相似的内容,例如:If your parameter simply moves between certain fixed values, you could follow a simple approach as in this example in the documentation.
If you want more control over the exact way the marker moves across the number line, I'd recommend replicating something similar with a
ValueTracker
and theUpdateFromAlphaFunc
animation, like this: