| from __future__ import annotations |
|
|
| from enum import Enum |
|
|
| from manim import * |
|
|
| __all__ = [ |
| "SquareToCircle", |
| "SceneWithMultipleCalls", |
| "SceneWithMultipleWaitCalls", |
| "NoAnimations", |
| "SceneWithStaticWait", |
| "SceneWithSceneUpdater", |
| "SceneForFrozenFrameTests", |
| "SceneWithNonStaticWait", |
| "StaticScene", |
| "InteractiveStaticScene", |
| "SceneWithSections", |
| "ElaborateSceneWithSections", |
| ] |
|
|
|
|
| class SquareToCircle(Scene): |
| def construct(self): |
| square = Square() |
| circle = Circle() |
| self.play(Transform(square, circle)) |
|
|
|
|
| class SceneWithMultipleCalls(Scene): |
| def construct(self): |
| number = Integer(0) |
| self.add(number) |
| for _i in range(10): |
| self.play(Animation(Square())) |
|
|
|
|
| class SceneWithMultipleWaitCalls(Scene): |
| def construct(self): |
| self.play(Create(Square())) |
| self.wait(1) |
| self.play(Create(Square().shift(DOWN))) |
| self.wait(1) |
| self.play(Create(Square().shift(2 * DOWN))) |
| self.wait(1) |
| self.play(Create(Square().shift(3 * DOWN))) |
| self.wait(1) |
|
|
|
|
| class NoAnimations(Scene): |
| def construct(self): |
| dot = Dot().set_color(GREEN) |
| self.add(dot) |
| self.wait(0.1) |
|
|
|
|
| class SceneWithStaticWait(Scene): |
| def construct(self): |
| self.add(Square()) |
| self.wait() |
|
|
|
|
| class SceneWithSceneUpdater(Scene): |
| def construct(self): |
| self.add(Square()) |
| self.add_updater(lambda dt: 42) |
| self.wait() |
|
|
|
|
| class SceneForFrozenFrameTests(Scene): |
| def construct(self): |
| self.mobject_update_count = 0 |
| self.scene_update_count = 0 |
|
|
| def increment_mobject_update_count(mob, dt): |
| self.mobject_update_count += 1 |
|
|
| def increment_scene_update_count(dt): |
| self.scene_update_count += 1 |
|
|
| s = Square() |
| s.add_updater(increment_mobject_update_count) |
| self.add(s) |
| self.add_updater(increment_scene_update_count) |
|
|
| self.wait(frozen_frame=True) |
|
|
|
|
| class SceneWithNonStaticWait(Scene): |
| def construct(self): |
| s = Square() |
| |
| s.add_updater(lambda mob, dt: None) |
| self.add(s) |
| self.wait() |
|
|
|
|
| class StaticScene(Scene): |
| def construct(self): |
| dot = Dot().set_color(GREEN) |
| self.add(dot) |
|
|
|
|
| class InteractiveStaticScene(Scene): |
| def construct(self): |
| dot = Dot().set_color(GREEN) |
| self.add(dot) |
| self.interactive_mode = True |
|
|
|
|
| class SceneWithSections(Scene): |
| def construct(self): |
| |
| class PresentationSectionType(str, Enum): |
| |
| NORMAL = "presentation.normal" |
| |
| SKIP = "presentation.skip" |
| |
| LOOP = "presentation.loop" |
| |
| COMPLETE_LOOP = "presentation.complete_loop" |
|
|
| |
| self.wait() |
|
|
| self.next_section() |
| self.wait(2) |
|
|
| self.next_section(name="test") |
| self.wait() |
|
|
| self.next_section( |
| "Prepare For Unforeseen Consequences.", DefaultSectionType.NORMAL |
| ) |
| self.wait(2) |
|
|
| self.next_section(section_type=PresentationSectionType.SKIP) |
| self.wait() |
|
|
| self.next_section( |
| name="this section should be removed as it doesn't contain any animations" |
| ) |
|
|
|
|
| class ElaborateSceneWithSections(Scene): |
| def construct(self): |
| |
| self.next_section("create square") |
| square = Square() |
| self.play(FadeIn(square)) |
| self.wait() |
|
|
| self.next_section("transform to circle") |
| circle = Circle() |
| self.play(Transform(square, circle)) |
| self.wait() |
|
|
| |
| self.next_section("skipped animations section", skip_animations=True) |
| circle = Circle() |
| self.play(Transform(square, circle)) |
| self.wait() |
|
|
| self.next_section("fade out") |
| self.play(FadeOut(square)) |
| self.wait() |
|
|
|
|
| class SceneWithRandomness(Scene): |
| def construct(self): |
| dots = VGroup() |
| for _ in range(10): |
| dot = Dot( |
| point=np.random.uniform(-3, 3, size=3), |
| ) |
| dots.add(dot) |
| self.add(dots) |
| self.wait() |
|
|