File size: 4,781 Bytes
3eedfa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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()
        # Non static wait are triggered by mobject with time based updaters.
        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):
        # this would be defined in a third party application using the segmented video API
        class PresentationSectionType(str, Enum):
            # start, end, wait for continuation by user
            NORMAL = "presentation.normal"
            # start, end, immediately continue to next section
            SKIP = "presentation.skip"
            # start, end, restart, immediately continue to next section when continued by user
            LOOP = "presentation.loop"
            # start, end, restart, finish animation first when user continues
            COMPLETE_LOOP = "presentation.complete_loop"

        # this animation is part of the first, automatically created section
        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):
        # the first automatically created section should be deleted <- it's empty
        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()

        # this section will be entirely skipped
        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),  # noqa: NPY002
            )
            dots.add(dot)
        self.add(dots)
        self.wait()