You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
698 B

3 months ago
from manim import *
class MovingDots(Scene):
def construct(self):
d1, d2 = Dot(color=BLUE), Dot(color=GREEN)
dg = VGroup(d1, d2).arrange(RIGHT, buff=1)
l1 = Line(d1.get_center(), d2.get_center()).set_color(RED)
x = ValueTracker(0)
y = ValueTracker(0)
d1.add_updater(lambda z: z.set_x(x.get_value()))
d2.add_updater(lambda z: z.set_y(y.get_value()))
l1.add_updater(
lambda z: z.become(
Line(
d1.get_center(),
d2.get_center())))
self.add(d1, d2, l1)
self.play(x.animate.set_value(5))
self.play(y.animate.set_value(4))
self.wait()