[1]:
from manim import *
from manim_geometry import *
config.media_embed = True
config.media_width = "100%"
_RV = "-v WARNING -qm --progress_bar None --disable_caching"
_RI = "-v WARNING -s --progress_bar None --disable_caching"
Manim Community v0.18.0
Auto-animations¶
While you can access all objects as an attribute of “Geos”, each construction has a default animation, for this you can use the auto_animation
method. This method receives the following parameters:
all_styles
[dict]: Here the styles of the auxiliary objects are defined.anim_kwargs
[dict]: Here the typical kwargs of the animations are defined,run_time
, etc., I do not recommend modifying any other option besidesrun_time
.show_dot/show_dots
[Bool]: Shows the auxiliary point or points.remove_arc/remove_arcs
[Bool]: Removes the auxiliary arcs.**kwargs
: Here you can define the styles of the object being animated.
Dots¶
[2]:
class Example(Scene):
def construct(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"d1,d2": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),
})
geos.auto_animation("d1")
geos.auto_animation("d2", anim_kwargs={"run_time":5})
self.wait()
%manim $_RV Example
Lines¶
[3]:
class Example(Scene):
def construct(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"l1": Line(LEFT, RIGHT).shift(UP),
"l2": Line(LEFT*2, RIGHT*2),
"l3": Line(LEFT*3, RIGHT*3).shift(DOWN),
"l4": Line(LEFT*4, RIGHT*4).shift(DOWN*2),
})
geos.auto_animation("l1")
geos.auto_animation("l2", dot_kwargs={"radius": 0.2, "color": RED})
geos.auto_animation("l3", show_dots=False, color=BLUE)
geos.auto_animation("l4", anim_kwargs={"run_time":3})
%manim $_RV Example
Circles¶
[4]:
class Example(Scene):
def construct(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"c1": geos.circle(ORIGIN, 1),
"c2": geos.circle(ORIGIN, 2),
})
geos.auto_animation("c1")
geos.auto_animation("c2",
all_styles={"color": YELLOW},
color=BLUE,
anim_kwargs={"run_time": 3})
self.wait()
%manim $_RV Example
Warning
In case you need to animate step by step you can use the following method. I don’t recommend it but it’s there, you can read the source code of manim_geometry/geos.py
which is where this is defined, I’ve tried hard to make it easy to understand but the library is not designed for you to modify this.
[19]:
class Example(Scene):
def construct(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"c1": geos.circle(ORIGIN, 1),
})
geos.prepare_animation("c1")
self.play(geos.c1._prepared_anim.get_step(0)) # Show dot
self.play(geos.c1._prepared_anim.get_step(1), run_time=4) # Draw line
self.play(geos.c1._prepared_anim.get_step(2)) # Rotate line drawing circle
self.play(geos.c1._prepared_anim.get_step(3)) # Remove line and dot
# Check geos.py to see all the steps
self.wait()
%manim $_RV Example
[6]:
class Example(Scene):
def construct(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"c1": geos.circle(ORIGIN, 1, start_angle=-PI/2),
"c2": geos.circle(ORIGIN, 2, start_angle=-PI),
})
geos.auto_animation("c1")
geos.auto_animation("c2", reverse=True)
self.wait()
%manim $_RV Example
Multiple FadeIn¶
[7]:
class Example(Scene):
def construct(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"l1": Line(LEFT, RIGHT).shift(UP),
"l2": Line(LEFT*2, RIGHT*2),
"l3": Line(LEFT*3, RIGHT*3).shift(DOWN),
"d1,d2": geos.dots_at_start_end_line("l1")
})
geos.fade_in_multiple("d1,d2")
geos.fade_in_multiple("l1,l2,l3", scale=0.5)
self.wait()
%manim $_RV Example
FadeIn Dot and Label¶
[23]:
class FadeInDotAndLabel(Scene):
def construct(self):
geos = Geos(self)
geos.create_geos({
"d1,d2,d3": GeosVGroup(
Dot(LEFT), Dot(ORIGIN), Dot(RIGHT)
).scale(3).rotate(30*DEGREES)
},
set_all_labels=True
)
geos.show_dot_and_label("d1")
geos.show_dot_and_label("d2,d3")
self.wait()
%manim $_RV FadeInDotAndLabel
Line bisector¶
[8]:
class LineBisector1(Scene):
def setup(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"d1,d2": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),
"b1": geos.line_bisection_two_points("d1,d2", color=GREEN),
"c1": geos.circle("d1", 2),
"c2": geos.circle("d2", 2),
})
self.geos = geos
def construct(self):
self.geos.auto_animation("b1")
self.wait()
%manim $_RV LineBisector1
[9]:
class LineBisector2(LineBisector1):
def construct(self):
self.geos.auto_animation(
"b1",
arc_kwargs={"color": RED},
line_kwargs={"color": YELLOW},
dot_kwargs={"color": PURPLE},
)
self.wait()
%manim $_RV LineBisector2
[10]:
class LineBisector3(LineBisector1):
def construct(self):
self.geos.auto_animation("b1", all_styles={"color": YELLOW}, color=PINK)
self.wait()
%manim $_RV LineBisector3
[11]:
class LineBisector4(Scene):
def setup(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"d1,d2": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),
"b1": geos.line_bisection_two_points("d1,d2", all_styles={"color": PINK}),
"c1": geos.circle("d1", 2),
"c2": geos.circle("d2", 2),
})
geos.auto_animation("b1")
%manim $_RV LineBisector4
[12]:
class LineBisector5(LineBisector1):
def construct(self):
self.geos.auto_animation("b1", show_dots=False)
self.wait()
%manim $_RV LineBisector5
[13]:
class LineBisector5(LineBisector1):
def construct(self):
geos = self.geos
geos.auto_animation("b1", remove_arcs=False, dot_kwargs={"radius": 0.2, "color": RED})
self.play(geos.b1.arcs.animate.set_color(RED))
self.play(geos.b1.animate.set_color(YELLOW))
self.play(FadeOut(geos.b1.arcs))
self.wait()
%manim $_RV LineBisector5
[14]:
class LineBisector5(LineBisector1):
def construct(self):
geos = self.geos
geos.auto_animation("b1", remove_arcs=False, show_line=False)
self.play(geos.b1.arcs.animate.set_color(RED))
self.play(Create(geos.b1))
self.play(FadeOut(geos.b1.arcs))
self.wait()
%manim $_RV LineBisector5
Common chord¶
[15]:
class CommonChord1(Scene):
def setup(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
init_geos = {
"d1,d2": GeosVGroup(Dot(LEFT), Dot(RIGHT*4)).rotate(30*DEGREES),
"c1": geos.circle("d1", 2),
"b12": geos.common_chord_partial("d2,c1", color=YELLOW),
}
geos.create_geos(init_geos)
self.geos = geos
def construct(self):
self.add(self.geos.d1, self.geos.c1)
self.geos.auto_animation("b12")
%manim $_RV CommonChord1
[16]:
class CommonChord2(CommonChord1):
def construct(self):
self.add(self.geos.d1, self.geos.c1)
geos = self.geos
geos.auto_animation(
"b12",
all_styles={"color": PINK},
dot_kwargs={"radius": 0.2},
remove_arc=False,
show_line=False,
color=BLUE
)
self.play(geos.b12.arc.animate.set_color(YELLOW))
self.play(Create(geos.b12))
self.play(FadeOut(geos.b12.arc))
self.wait()
%manim $_RV CommonChord2
Nearest/Farthest angle bisector¶
[17]:
class Example(Scene):
def construct(self):
self.add(NumberPlane().fade(0.7))
geos = Geos(self)
geos.create_geos({
"d1,d2": GeosVGroup(Dot(LEFT), Dot(RIGHT)).rotate(30*DEGREES),
"dU": Dot(UP),
"iI_1": geos.nearest_angle_bisector("d1", "d2", "dU", color=ORANGE),
"iI_2": geos.farthest_angle_bisector("d1,d2,dU", color=GREEN),
"iI_3": geos.farthest_angle_bisector("d1,dU,d2", color=BLUE),
"c1": geos.circle("d1", 2, z_index=-1),
"c2": geos.circle("d2", 2, z_index=-1),
},
set_all_labels=True
)
self.add(geos.get_all_dots(), geos.get_all_circles(), geos.get_all_labels())
geos.auto_animation("iI_1")
geos.auto_animation("iI_2",
remove_arcs=False,
add_dot=True,
all_styles={"color": PINK},
dot_kwargs={"radius": 0.1}
)
self.play(geos.iI_2.arcs.animate.shift(DOWN))
self.play(FadeOut(geos.iI_2.arcs))
geos.auto_animation("iI_3", show_dots=False, add_dot=True)
self.wait()
%manim $_RV Example
[ ]: