如何制作周期递减的正弦波动画



我正试图制作一个周期性收缩的正弦波的动画,就好像图形从左边缘和右边缘(y=sin(ax)(被"压扁",以持续增加a(的值。我试过使用ApplyPointwiseFunction:

from manim import *
class SineWave(Scene):
def construct(self):
# self.camera.frame.save_state()
# create the axes
axes = Axes(x_range=[-1, 10], y_range=[-1, 10])
self.add(axes)
# Create the graph
graph = axes.plot(lambda x: np.sin(x), color=BLUE)
self.play(ApplyPointwiseFunction(lambda x: x*2, graph))

但这显然不是正确的做法。

我可以使用ApplyPointwiseFunction做些什么吗?还是应该找其他地方?

经过我不愿承认的几个小时后,我终于明白了!以下代码有效。可以使用run_timeset_value中的倍增因子(100(来更改动画的速度。

from manim import *
class SineWave(Scene):
def construct(self):
# The ValueTracker functions as the constant `a` in `sin(ab)`.
tracker = ValueTracker(0.1)
# Create the graph
sine_function = lambda x: np.sin(tracker.get_value() * x)
sine_graph = always_redraw(lambda: FunctionGraph(
sine_function,
color=BLUE
))
self.add(sine_graph)
# Animate the sine wave from y=sin(0.1*x) to y=sin(10*x) over the course of 6 seconds.
self.play(tracker.animate(run_time=6).set_value(tracker.get_value() * 100)),

最新更新