반응형
code
from manimlib.imports import *
class ConnectObjects_ByLine(Scene):
def construct(self):
#1. Creates dots and display them
dot1, dot2 = Dot(), Dot()
dot1.shift(UP)
connected_line = VGroup(Line(dot1.get_center(), dot2.get_center()))
self.add(dot1, dot2, connected_line)
#2. makes update function to draw the line between the dots
def update_line(mob):
x1, y1 = dot1.get_center()[0], dot1.get_center()[1]
x2, y2 = dot2.get_center()[0], dot2.get_center()[1]
h_line = Line(np.array([x1,y1,0]),np.array([x1,y2,0]) )
v_line = Line(np.array([x1, y2, 0]), np.array([x2, y2, 0]))
line_group = VGroup(h_line, v_line)
mob.become(line_group)
connected_line.add_updater(update_line)
#3. move dot1 and dot2
self.play(dot1.to_edge, LEFT, run_time=2)
self.play(dot1.to_edge, RIGHT, run_time=2)
self.play(dot2.to_edge, UP, run_time=2)
self.play(dot2.move_to, ORIGIN, run_time=2)
self.play(dot1.move_to, ORIGIN)
self.wait()
GIF
MP4
Go to the Table of Contents for Manim Code Collection
반응형
'Programming > Manim code' 카테고리의 다른 글
Draw line with rotating circles (0) | 2020.09.20 |
---|---|
Draw waves by several moving circles (0) | 2020.09.20 |
Draw summed Sine-wave (Two Circles) (0) | 2020.09.19 |
Draw moving sine-wave changing the amplitude (0) | 2020.09.19 |
Draw moving wave by the rotating dots (0) | 2020.09.19 |