mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
96 lines
2.6 KiB
Python
96 lines
2.6 KiB
Python
from manim import *
|
|
|
|
|
|
class Test(Scene):
|
|
groups_api = True
|
|
|
|
@group
|
|
def first_section(self) -> None:
|
|
line = Line()
|
|
line.add_updater(lambda m, dt: m.rotate(PI * dt))
|
|
line.to_edge(LEFT)
|
|
self.add(line)
|
|
square = Square()
|
|
tex = Tex(
|
|
"Hello, ",
|
|
"world",
|
|
r" $e^{i\theta}$",
|
|
stroke_color=RED,
|
|
fill_color=BLUE,
|
|
stroke_width=2,
|
|
).to_edge(RIGHT)
|
|
tex.set_color_by_tex("world", GREEN)
|
|
self.add(tex)
|
|
self.play(Create(tex), Rotate(square, PI / 2))
|
|
self.wait(1)
|
|
self.play(FadeOut(square))
|
|
|
|
@group
|
|
def three_mobjects(self) -> None:
|
|
hexagon = RegularPolygon(6)
|
|
circle = Circle()
|
|
star = Star()
|
|
VGroup(hexagon, circle, star).arrange()
|
|
self.play(
|
|
Succession(
|
|
Create(hexagon),
|
|
DrawBorderThenFill(circle),
|
|
SpinInFromNothing(star),
|
|
)
|
|
)
|
|
self.play(FadeOut(VGroup(hexagon, circle, star)))
|
|
|
|
@group
|
|
def manim_banner(self) -> None:
|
|
banner = ManimBanner().scale(0.5)
|
|
self.play(banner.create())
|
|
self.play(banner.expand())
|
|
self.wait(1)
|
|
self.play(Unwrite(banner))
|
|
|
|
@group
|
|
def graph(self):
|
|
vertices = [1, 2, 3]
|
|
edges = [(1, 2), (2, 3), (3, 1)]
|
|
graph = Graph(vertices, edges, layout="circular")
|
|
self.play(Create(graph))
|
|
self.play(
|
|
graph.animate.add_vertices(
|
|
4,
|
|
5,
|
|
vertex_config={4: {"fill_color": RED}, 5: {"fill_color": RED}},
|
|
positions={4: [2, 1, 0], 5: [2, -1, 0]},
|
|
)
|
|
)
|
|
self.play( # TODO: this animation is currently broken
|
|
graph.animate.add_edges(
|
|
(2, 4),
|
|
(3, 5),
|
|
(4, 5),
|
|
edge_config={
|
|
(2, 4): {"stroke_color": GREEN},
|
|
(3, 5): {"stroke_color": GREEN},
|
|
(4, 5): {"stroke_color": YELLOW},
|
|
},
|
|
)
|
|
)
|
|
self.wait(1)
|
|
self.play(graph.animate.remove_vertices(1))
|
|
self.play(graph.animate.remove_edges((4, 5)))
|
|
self.play(Uncreate(graph))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
with (
|
|
tempconfig(
|
|
{
|
|
"preview": True,
|
|
"write_to_movie": False,
|
|
"disable_caching": True,
|
|
"frame_rate": 60,
|
|
"disable_caching_warning": True,
|
|
}
|
|
),
|
|
Manager(Test) as manager,
|
|
):
|
|
manager.render()
|