2016-05-25 20:28:22 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2019-05-02 20:36:14 -07:00
|
|
|
from manimlib.imports import *
|
2018-02-02 11:10:17 +01:00
|
|
|
|
2018-01-20 15:29:50 -08:00
|
|
|
# To watch one of these scenes, run the following:
|
2019-01-03 17:08:22 -08:00
|
|
|
# python -m manim example_scenes.py SquareToCircle -pl
|
2018-04-06 13:58:59 -07:00
|
|
|
#
|
|
|
|
# Use the flat -l for a faster rendering at a lower
|
2019-01-03 17:08:22 -08:00
|
|
|
# quality.
|
2019-01-24 22:24:01 -08:00
|
|
|
# Use -s to skip to the end and just save the final frame
|
|
|
|
# Use the -p to have the animation (or image, if -s was
|
|
|
|
# used) pop up once done.
|
2019-01-03 17:08:22 -08:00
|
|
|
# Use -n <number> to skip ahead to the n'th animation of a scene.
|
2019-05-21 11:54:56 +02:00
|
|
|
# Use -r <number> to specify a resolution (for example, -r 1080
|
|
|
|
# for a 1920x1080 video)
|
2019-01-03 17:08:22 -08:00
|
|
|
|
|
|
|
|
|
|
|
class OpeningManimExample(Scene):
|
|
|
|
def construct(self):
|
|
|
|
title = TextMobject("This is some \\LaTeX")
|
|
|
|
basel = TexMobject(
|
|
|
|
"\\sum_{n=1}^\\infty "
|
|
|
|
"\\frac{1}{n^2} = \\frac{\\pi^2}{6}"
|
|
|
|
)
|
2019-02-04 14:54:25 -08:00
|
|
|
VGroup(title, basel).arrange(DOWN)
|
2019-01-03 17:08:22 -08:00
|
|
|
self.play(
|
|
|
|
Write(title),
|
|
|
|
FadeInFrom(basel, UP),
|
|
|
|
)
|
|
|
|
self.wait()
|
|
|
|
|
|
|
|
transform_title = TextMobject("That was a transform")
|
|
|
|
transform_title.to_corner(UP + LEFT)
|
|
|
|
self.play(
|
|
|
|
Transform(title, transform_title),
|
2019-02-14 11:34:21 -08:00
|
|
|
LaggedStart(*map(FadeOutAndShiftDown, basel)),
|
2019-01-03 17:08:22 -08:00
|
|
|
)
|
|
|
|
self.wait()
|
|
|
|
|
|
|
|
grid = NumberPlane()
|
|
|
|
grid_title = TextMobject("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),
|
2019-02-14 11:34:21 -08:00
|
|
|
ShowCreation(grid, run_time=3, lag_ratio=0.1),
|
2019-01-03 17:08:22 -08:00
|
|
|
)
|
|
|
|
self.wait()
|
|
|
|
|
|
|
|
grid_transform_title = TextMobject(
|
|
|
|
"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()
|
2018-01-15 19:15:05 -08:00
|
|
|
|
|
|
|
|
2016-05-25 20:28:22 -07:00
|
|
|
class SquareToCircle(Scene):
|
|
|
|
def construct(self):
|
|
|
|
circle = Circle()
|
|
|
|
square = Square()
|
2018-02-06 11:13:10 +01:00
|
|
|
square.flip(RIGHT)
|
2018-04-06 13:58:59 -07:00
|
|
|
square.rotate(-3 * TAU / 8)
|
2018-08-12 19:06:08 -07:00
|
|
|
circle.set_fill(PINK, opacity=0.5)
|
2018-01-15 19:15:05 -08:00
|
|
|
|
2016-05-25 20:28:22 -07:00
|
|
|
self.play(ShowCreation(square))
|
|
|
|
self.play(Transform(square, circle))
|
2018-01-16 22:39:43 -08:00
|
|
|
self.play(FadeOut(square))
|
2016-05-25 20:28:22 -07:00
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2016-05-25 20:39:13 -07:00
|
|
|
class WarpSquare(Scene):
|
|
|
|
def construct(self):
|
|
|
|
square = Square()
|
|
|
|
self.play(ApplyPointwiseFunction(
|
2018-08-12 19:06:08 -07:00
|
|
|
lambda point: complex_to_R3(np.exp(R3_to_complex(point))),
|
2016-05-25 20:39:13 -07:00
|
|
|
square
|
|
|
|
))
|
2018-01-15 19:15:05 -08:00
|
|
|
self.wait()
|
2016-05-25 20:28:22 -07:00
|
|
|
|
|
|
|
|
2016-05-25 20:39:13 -07:00
|
|
|
class WriteStuff(Scene):
|
|
|
|
def construct(self):
|
2018-08-12 19:06:08 -07:00
|
|
|
example_text = TextMobject(
|
|
|
|
"This is a some text",
|
|
|
|
tex_to_color_map={"text": YELLOW}
|
|
|
|
)
|
|
|
|
example_tex = TexMobject(
|
|
|
|
"\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",
|
|
|
|
)
|
|
|
|
group = VGroup(example_text, example_tex)
|
2019-02-04 14:54:25 -08:00
|
|
|
group.arrange(DOWN)
|
2018-08-12 19:06:08 -07:00
|
|
|
group.set_width(FRAME_WIDTH - 2 * LARGE_BUFF)
|
2018-02-02 11:10:17 +01:00
|
|
|
|
2018-08-12 19:06:08 -07:00
|
|
|
self.play(Write(example_text))
|
|
|
|
self.play(Write(example_tex))
|
2018-02-02 11:10:17 +01:00
|
|
|
self.wait()
|
|
|
|
|
2018-01-15 18:49:58 -08:00
|
|
|
|
2019-05-21 11:44:30 +02:00
|
|
|
class UpdatersExample(Scene):
|
2018-02-06 11:13:10 +01:00
|
|
|
def construct(self):
|
2018-08-12 19:06:08 -07:00
|
|
|
decimal = DecimalNumber(
|
|
|
|
0,
|
|
|
|
show_ellipsis=True,
|
|
|
|
num_decimal_places=3,
|
|
|
|
include_sign=True,
|
2018-02-06 11:13:10 +01:00
|
|
|
)
|
2018-08-12 19:06:08 -07:00
|
|
|
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,
|
2018-02-06 11:13:10 +01:00
|
|
|
)
|
|
|
|
self.wait()
|
|
|
|
|
2018-08-12 19:06:08 -07:00
|
|
|
# See old_projects folder for many, many more
|