Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active February 13, 2025 19:16
Show Gist options
  • Save uwezi/ade747431be4f01b23c5e0c01e648f5d to your computer and use it in GitHub Desktop.
Save uwezi/ade747431be4f01b23c5e0c01e648f5d to your computer and use it in GitHub Desktop.
[Three functions and some dots] Showing the plotting of functions and MoveAlongPath. #manim #animation #movealongpath #functions
# reaction to https://www.reddit.com/r/manim/comments/1iois3s/is_manim_worth_learning_for_math_visualization_or/
from manim import *
class justforfun(Scene):
def construct(self):
ax1 = Axes(
x_range = [-3,3,1],
y_range = [-1.5,+1.5,1],
x_length = 10,
y_length = 2,
tips=False
).to_edge(UP).add_coordinates()
ax2 = ax1.copy().next_to(ax1,DOWN)
ax3 = ax1.copy().next_to(ax2,DOWN)
def f(x):
return 0 if x < -2 else -2-x if x < -1 else x if x < +1 else 2-x if x < +2 else 0
def g(x):
return np.exp(-x**2)
def fg(x):
return f(x)*g(x)
plot1 = ax1.plot(f, use_smoothing=False, color=BLUE, stroke_width=2)
plot2 = ax2.plot(g, use_smoothing=False, color=YELLOW, stroke_width=2)
plot3 = ax3.plot(fg, use_smoothing=False, color=GREEN, stroke_width=2)
self.add(ax1,ax2,ax3)
self.add(plot1,plot2,plot3)
dot1 = Dot(color=BLUE).move_to(plot1.get_start())
dot2 = Dot(color=YELLOW).move_to(plot2.get_start())
dot3 = Dot(color=GREEN).move_to(plot3.get_start())
self.add(dot1,dot2,dot3)
self.wait()
self.play(
MoveAlongPath(dot1,plot1),
MoveAlongPath(dot2,plot2),
MoveAlongPath(dot3,plot3),
rate_func=rate_functions.linear,
run_time=4
)
self.wait()

ManimCE output as GIF

justforfun_ManimCE_v0 19 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment