Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Restore examples/basic.py (#560)

Devin Neal3b6519a58678
diff --git a/example_scenes/basic.py b/example_scenes/basic.py
index ade056995..5eefaf3b9 100644
--- a/example_scenes/basic.py
+++ b/example_scenes/basic.py
@@ -13,14 +13,59 @@ from manim import *
# Use -r <number> to specify a resolution (for example, -r 1080
# for a 1920x1080 video)
-from manim import *
-
-class Dot1(Scene):
+class OpeningManimExample(Scene):
def construct(self):
- dot = Dot().set_color(GREEN)
- self.add(dot)
- self.wait(1)
+ title = Tex("This is some \\LaTeX")
+ basel = MathTex("\\sum_{n=1}^\\infty " "\\frac{1}{n^2} = \\frac{\\pi^2}{6}")
+ VGroup(title, basel).arrange(DOWN)
+ self.play(
+ Write(title),
+ FadeInFrom(basel, UP),
+ )
+ self.wait()
+
+ transform_title = Tex("That was a transform")
+ transform_title.to_corner(UP + LEFT)
+ self.play(
+ Transform(title, transform_title),
+ LaggedStart(*map(FadeOutAndShiftDown, basel)),
+ )
+ self.wait()
+
+ grid = NumberPlane()
+ grid_title = Tex("This is a grid")
+ grid_title.scale(1.5)
+ grid_title.move_to(transform_title)
+
+ self.add(grid, grid_title) # Make sure title is on top of grid
+ self.play(
+ FadeOut(title),
+ FadeInFromDown(grid_title),
+ ShowCreation(grid, run_time=3, lag_ratio=0.1),
+ )
+ self.wait()
+
+ grid_transform_title = Tex(
+ "That was a non-linear function \\\\" "applied to the grid"
+ )
+ grid_transform_title.move_to(grid_title, UL)
+ grid.prepare_for_nonlinear_transform()
+ self.play(
+ grid.apply_function,
+ lambda p: p
+ + np.array(
+ [
+ np.sin(p[1]),
+ np.sin(p[0]),
+ 0,
+ ]
+ ),
+ run_time=3,
+ )
+ self.wait()
+ self.play(Transform(grid_title, grid_transform_title))
+ self.wait()
class SquareToCircle(Scene):
@@ -45,3 +90,43 @@ class WarpSquare(Scene):
)
)
self.wait()
+
+
+class WriteStuff(Scene):
+ def construct(self):
+ example_text = Tex("This is a some text", tex_to_color_map={"text": YELLOW})
+ example_tex = MathTex(
+ "\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",
+ )
+ group = VGroup(example_text, example_tex)
+ group.arrange(DOWN)
+ group.set_width(config["frame_width"] - 2 * LARGE_BUFF)
+
+ self.play(Write(example_text))
+ self.play(Write(example_tex))
+ self.wait()
+
+
+class UpdatersExample(Scene):
+ def construct(self):
+ decimal = DecimalNumber(
+ 0,
+ show_ellipsis=True,
+ num_decimal_places=3,
+ include_sign=True,
+ )
+ square = Square().to_edge(UP)
+
+ decimal.add_updater(lambda d: d.next_to(square, RIGHT))
+ decimal.add_updater(lambda d: d.set_value(square.get_center()[1]))
+ self.add(square, decimal)
+ self.play(
+ square.to_edge,
+ DOWN,
+ rate_func=there_and_back,
+ run_time=5,
+ )
+ self.wait()
+
+
+# See many more examples at https://manimce.readthedocs.io/en/latest/examples.html