Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active March 19, 2023 12:41
Show Gist options
  • Save uwezi/f27ce0a577286adb008b8f766beb32b3 to your computer and use it in GitHub Desktop.
Save uwezi/f27ce0a577286adb008b8f766beb32b3 to your computer and use it in GitHub Desktop.
[x/y lines to point on curve animated] How to animate .get_lines_to_point() #manim #valuetracker #animate #plot #get_lines_to_point
# https://discord.com/channels/581738731934056449/1020966805923188736/1020992408529416254
from manim import *
class axes(Scene):
def construct(self):
plane = NumberPlane(background_line_style={"stroke_opacity": 0.5})
self.play(Create(plane))
def f(x):
return x**2
splot = plane.plot(f)
self.play(Create(splot))
t = ValueTracker(0)
point = Dot()
point.add_updater(lambda x: x.move_to(plane.c2p(t.get_value(), f(t.get_value()))))
lines = plane.get_lines_to_point(plane.c2p(t.get_value(), f(t.get_value())))
lines.add_updater(lambda mobj: mobj.become(plane.get_lines_to_point(plane.c2p(t.get_value(), f(t.get_value())))))
self.play(Create(point))
self.play(Create(lines))
self.play(t.animate.set_value(2))
self.play(t.animate.set_value(-2))
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment