Ratefunction#
[1]:
import matplotlib.pyplot as plt
import numpy as np
from manim import *
config.media_embed = True
def figtoimg(fig):
fig.canvas.draw()
img = fig.canvas.buffer_rgba()
plt.close(fig)
return img
Manim Community v0.17.2
[2]:
def my_function(amplitude, x):
return amplitude * np.sin(x)
def make_plot(amplitude, x):
fig, ax = plt.subplots(dpi=200)
ax.plot(x, my_function(amplitude, x), lw=3)
ax.set_ylim(-1, 1)
return figtoimg(fig)
class Example(Scene):
def construct(self):
self.camera.background_color = BLUE_A
x_values = np.linspace(0, 30, 400)
amp1 = 0.5
amp2 = 1
tr_amplitude = ValueTracker(amp1)
image = ImageMobject(make_plot(amp1, x_values))
self.add(image)
def update_image(mob):
new_mob = ImageMobject(make_plot(tr_amplitude.get_value(), x_values))
mob.become(new_mob)
image.add_updater(update_image)
self.play(tr_amplitude.animate.set_value(amp2), rate_func=smooth, run_time=1.0)
self.play(tr_amplitude.animate.set_value(amp1), rate_func=smooth, run_time=1.0)
%manim -v WARNING -qh --disable_caching --progress_bar None Example