class HypocycloidSceneComplete(Scene):
radius=1.5
color_path=RED
divisions=[1,2,3,4,5,6,7,8]
def construct(self):
self.show_animation()
def show_animation(self):
c = True
for i in self.divisions:
r2=self.radius/i
self.hypo(self.radius,r2,c)
c = False
def hypo(self,r1,r2,animation):
# Manim circle
c1 = Circle(radius=r1,color=BLUE)
# Small circle
c2 = Circle(radius=r2,color=YELLOW).rotate(PI)
c2.align_to(c1,RIGHT)
c2.start = c2.copy()
# Dot
dot = Dot(c2.point_from_proportion(0.5),color=self.color_path)
# Line
line = Line(c2.get_center(),dot.get_center()).set_stroke(GREEN,2.5)
# Path
path = VMobject(color=self.color_path)
path.set_points_as_corners([dot.get_center(),dot.get_center()+UP*0.001])
# Path group
path_group = VGroup(line,dot,path)
# Alpha
alpha = ValueTracker(0)
# If the animation start then shows the animation
if animation:
self.play(Create(line),Create(c1),Create(c2),GrowFromCenter(dot))
else:
self.remove(self.dot)
self.add_foreground_mobjects(dot)
self.play(Create(line),Create(c2))
self.remove_foreground_mobjects(dot)
self.add(c1,c2,path)
# update function of path_group
def update_group(group):
l,mob,previus_path = group
mob.move_to(c2.point_from_proportion(0.5))
old_path = path.copy()
old_path.append_vectorized_mobject(Line(old_path.points[-1],dot.get_center()))
old_path.make_smooth()
l.put_start_and_end_on(c2.get_center(),dot.get_center())
path.become(old_path)
# update function of small circle
def update_c2(c):
c.become(c.start)
c.rotate(TAU*alpha.get_value(),about_point=c1.get_center())
c.rotate(-TAU*(r1/r2)*alpha.get_value(),about_point=c.get_center())
path_group.add_updater(update_group)
c2.add_updater(update_c2)
self.add(c2,path_group)
self.play(
alpha.animate.set_value(1),rate_func=linear
)
self.wait()
c2.clear_updaters()
path_group.clear_updaters()
self.dot = dot
self.play(FadeOut(path),FadeOut(c2),FadeOut(line))
# don't remove below command for run button to work
%manim -qm -v WARNING HypocycloidSceneComplete
반응형
'html5' 카테고리의 다른 글
manim TracedPath (0) | 2024.05.19 |
---|---|
manim Growing (0) | 2024.05.17 |
manim animation mp4 (0) | 2024.05.11 |
python library: how to use manim ex1 (0) | 2024.05.11 |
eigenvalue, eigenvector practice (0) | 2024.04.30 |