3b1b-manim/example_scenes.py

76 lines
2 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2018-08-12 19:06:08 -07:00
from big_ol_pile_of_manim_imports import *
# To watch one of these scenes, run the following:
# python extract_scene.py file_name <SceneName> -p
#
# Use the flat -l for a faster rendering at a lower
# quality, use -s to skip to the end and just show
# the final frame, and use -n <number> to skip ahead
# to the n'th animation of a scene.
2018-01-15 19:15:05 -08:00
class SquareToCircle(Scene):
def construct(self):
circle = Circle()
square = Square()
2018-02-06 11:13:10 +01:00
square.flip(RIGHT)
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
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: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: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)
group.arrange_submobjects(DOWN)
group.set_width(FRAME_WIDTH - 2 * LARGE_BUFF)
2018-08-12 19:06:08 -07:00
self.play(Write(example_text))
self.play(Write(example_tex))
self.wait()
2018-01-15 18:49:58 -08:00
2018-08-12 19:06:08 -07:00
class UdatersExample(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