반응형
Code
from manimlib.imports import *
class MovingWave(Scene):
def construct(self):
self.draw_axis()
self.draw_sine_wave()
def draw_axis(self):
x_axis = Line(np.array([-4,0,0]), np.array([4,0,0]))
y_axis = Line(np.array([-4,2,0]), np.array([-4,-2,0]))
self.add(x_axis, y_axis)
self.x_min = -4
self.x_max = 4
def draw_sine_wave(self):
sine_wave = self.get_sine_wave()
vt = ValueTracker(0)
def update_wave(wave):
wave.become(self.get_sine_wave(dx=vt.get_value()))
sine_wave.add_updater(update_wave)
self.add(sine_wave)
self.wait(2)
# move sine wave 2PI in 4 seconds
moving_time = 4
moving_length = 2*PI
self.play(vt.set_value, moving_length, run_time=moving_time, rate_func=linear)
self.wait()
def get_sine_wave(self, dx=0):
return FunctionGraph(
# to start on sin(0)
lambda x: np.sin((x-self.x_min + dx)),
x_min=self.x_min, x_max=self.x_max
)
GIF
MP4
반응형
'Programming > Manim code' 카테고리의 다른 글
Draw moving sine-wave changing the amplitude (0) | 2020.09.19 |
---|---|
Draw moving wave by the rotating dots (0) | 2020.09.19 |
Sine/Cosine curve by rotating the dot around the circle (0) | 2020.09.19 |
Sine-curve by rotating dot around the circle (0) | 2020.09.19 |
[49] Update Animation class (0) | 2020.05.29 |