def destroy_existing(self, destroyed_blocks):
     all_anims = []
     overlay_objs = []
     for id1, id2 in destroyed_blocks:
         # Generate a square containing both arrow blocks, and fade colour.
         if self.DESTRUCTION_RUNTIME > 0:
             anims = []
             if self.DESTRUCTION_ARROW_ANIM is not None:
                 anims.append(self.DESTRUCTION_ARROW_ANIM(self.arrow_blocks[id1]))
                 anims.append(self.DESTRUCTION_ARROW_ANIM(self.arrow_blocks[id2]))
             else:
                 # Instantly remove on animate.
                 anims.append(FadeOut(self.arrow_blocks[id1], rate_func=lambda t: 1))
                 anims.append(FadeOut(self.arrow_blocks[id2], rate_func=lambda t: 1))
             if self.DESTRUCTION_OVERLAY_COLOUR is not None:
                 top = max(self.arrow_blocks[id1].get_top()[1], self.arrow_blocks[id2].get_top()[1])
                 right = max(self.arrow_blocks[id1].get_right()[0], self.arrow_blocks[id2].get_right()[0])
                 fade_square = Square(side_length=self.scale * 2, color=self.DESTRUCTION_OVERLAY_COLOUR)
                 fade_square.set_opacity(self.DESTRUCTION_OVERLAY_STARTING_ALPHA)
                 fade_square.move_to([right - self.scale, top - self.scale, 0])
                 overlay_objs.append(fade_square)
                 anims.append(FadeOut(fade_square))
             all_anims.append(AnimationGroup(*anims))
         else:
             self.remove(self.arrow_blocks[id1], self.arrow_blocks[id2])
         del self.arrow_blocks[id1]
         del self.arrow_blocks[id2]
     if self.DESTRUCTION_RUNTIME > 0 and len(all_anims) > 0:
         return overlay_objs, LaggedStart(*all_anims, lag_ratio=self.DESTRUCTION_LAG_RATIO)
     return None, None
Beispiel #2
0
    def construct(self):
        circle = Circle(color=nq_colors["purple"])
        circle.set_fill(nq_colors["purple"], opacity=0.5)

        square = Square(color=nq_colors["orange"])
        square.flip(RIGHT)
        square.rotate(-3 * 2 * math.pi / 8)

        self.play(ShowCreation(square))
        self.play(Transform(square, circle))
        self.play(FadeOut(square))
Beispiel #3
0
def test_succession_in_succession_timing():
    """Test timing of nested successions."""
    line = Line()
    animation_1s = FadeIn(line, shift=UP, run_time=1.0)
    animation_4s = FadeOut(line, shift=DOWN, run_time=4.0)
    nested_succession = Succession(animation_1s, animation_4s)
    succession = Succession(
        FadeIn(line, shift=UP, run_time=4.0),
        nested_succession,
        FadeIn(line, shift=UP, run_time=1.0),
    )
    assert nested_succession.get_run_time() == 5.0
    assert succession.get_run_time() == 10.0
    succession._setup_scene(Mock())
    succession.begin()
    succession.interpolate(0.1)
    assert succession.active_index == 0
    # The nested succession must not be active yet, and as a result hasn't set active_animation yet.
    assert not hasattr(nested_succession, "active_animation")
    succession.interpolate(0.39)
    assert succession.active_index == 0
    assert not hasattr(nested_succession, "active_animation")
    # The nested succession starts at 40% of total run time
    succession.interpolate(0.4)
    assert succession.active_index == 1
    assert nested_succession.active_index == 0
    # The nested succession second animation starts at 50% of total run time.
    succession.interpolate(0.49)
    assert succession.active_index == 1
    assert nested_succession.active_index == 0
    succession.interpolate(0.5)
    assert succession.active_index == 1
    assert nested_succession.active_index == 1
    # The last animation starts at 90% of total run time. The nested succession must be finished at that time.
    succession.interpolate(0.89)
    assert succession.active_index == 1
    assert nested_succession.active_index == 1
    succession.interpolate(0.9)
    assert succession.active_index == 2
    assert nested_succession.active_index == 2
    assert nested_succession.active_animation is None
    # After 100%, nothing must be playing anymore.
    succession.interpolate(1.0)
    assert succession.active_index == 3
    assert succession.active_animation is None
    assert nested_succession.active_index == 2
    assert nested_succession.active_animation is None
Beispiel #4
0
    def __init__(
        self, 
        creature, 
        look_at_arg = None,
        run_time= 0.5,
        **kwargs
    ):
        assert hasattr(creature, "bubble")

        if look_at_arg:
            creature.target.look_at(look_at_arg)

        AnimationGroup.__init__(
            self,
            Uncreate(creature.bubble),
            FadeOut(creature.bubble.content),
            run_time = run_time
        )
 def create_arrows(self, created):
     all_anims = []
     overlay_objs = []
     for (id1, (p11, p12), (d1x, d1y)), (id2, (p21, p22), (d2x, d2y)) in created:
         self.arrow_blocks[id1] = self._create_arrow(
             [((p11[0] + p12[0])/2 + 0.5) * self.scale, ((p11[1] + p12[1])/2 + 0.5) * self.scale, 0],
             [d1x, d1y],
         )
         self.arrow_blocks[id2] = self._create_arrow(
             [((p21[0] + p22[0])/2 + 0.5) * self.scale, ((p21[1] + p22[1])/2 + 0.5) * self.scale, 0],
             [d2x, d2y],
         )
         overlay_objs.extend([self.arrow_blocks[id1], self.arrow_blocks[id2]])
         if self.ARROW_OVERLAY_COLOUR is not None:
             top = max(self.arrow_blocks[id1].get_top()[1], self.arrow_blocks[id2].get_top()[1])
             right = max(self.arrow_blocks[id1].get_right()[0], self.arrow_blocks[id2].get_right()[0])
             fade_square = Square(side_length=self.scale * 2, color=self.ARROW_OVERLAY_COLOUR)
             fade_square.set_opacity(self.ARROW_OVERLAY_STARTING_ALPHA)
             fade_square.move_to([right - self.scale, top - self.scale, 0])
             overlay_objs.append(fade_square)
         if self.ARROW_CREATE_RUNTIME > 0:
             anims = []
             if self.ARROW_OVERLAY_COLOUR is not None:
                 anims.append(FadeOut(fade_square))
             if self.ARROW_CREATE_ANIM is not None:
                 if self.ARROW_CREATE_ANIM == FadeInFrom:
                     anims.append(FadeInFrom(self.arrow_blocks[id1], direction=[-d1x * self.scale, -d1y * self.scale, 0]))
                     anims.append(FadeInFrom(self.arrow_blocks[id2], direction=[-d2x * self.scale, -d2y * self.scale, 0]))
                 else:
                     anims.append(self.ARROW_CREATE_ANIM(self.arrow_blocks[id1]))
                     anims.append(self.ARROW_CREATE_ANIM(self.arrow_blocks[id2]))
             else:
                 # This adds them to the scene.
                 anims.append(Transform(self.arrow_blocks[id1], self.arrow_blocks[id1]))
                 anims.append(Transform(self.arrow_blocks[id2], self.arrow_blocks[id2]))
             all_anims.append(AnimationGroup(*anims))
     if self.ARROW_CREATE_RUNTIME > 0 and len(all_anims) > 0:
         return overlay_objs, LaggedStart(*all_anims, lag_ratio=self.ARROW_LAG_RATIO)
     return overlay_objs, None
Beispiel #6
0
def test_succession_timing():
    """Test timing of animations in a succession."""
    line = Line()
    animation_1s = FadeIn(line, shift=UP, run_time=1.0)
    animation_4s = FadeOut(line, shift=DOWN, run_time=4.0)
    succession = Succession(animation_1s, animation_4s)
    assert succession.get_run_time() == 5.0
    succession.begin()
    assert succession.active_index == 0
    # The first animation takes 20% of the total run time.
    succession.interpolate(0.199)
    assert succession.active_index == 0
    succession.interpolate(0.2)
    assert succession.active_index == 1
    succession.interpolate(0.8)
    assert succession.active_index == 1
    # At 100% and more, no animation must be active anymore.
    succession.interpolate(1.0)
    assert succession.active_index == 2
    assert succession.active_animation is None
    succession.interpolate(1.2)
    assert succession.active_index == 2
    assert succession.active_animation is None
    def construct(self):
        FIVED_YELLOW = "#FFA500"
        FIVED_GRAY = "#0D0D0D"
        LOGO_UP = 1.5

        bgnd = ImageMobject(filename_or_array="empty_board_1920x1080.tif")
        logo = SVGMobject(file_name="fived")
        text = SVGMobject(file_name="fived_text", stroke_width=0.15)

        bot = logo[0].set_color(FIVED_GRAY)
        top = logo[1].set_color(FIVED_GRAY)
        mid = logo[2].set_color(FIVED_YELLOW)

        frame = Square().scale(1.15)
        frame.set_stroke(color=FIVED_GRAY, width=6)

        text.set_color(FIVED_GRAY)
        text.scale(0.27)
        text.shift(LEFT * 0.15)

        mid_anim = DrawBorderThenFill(
            vmobject=mid,
            run_time=3,
            rate_func=double_smooth,
            stroke_width=6,
            stroke_color=FIVED_YELLOW,
        )

        bot_anim = DrawBorderThenFill(
            vmobject=bot,
            run_time=3,
            rate_func=double_smooth,
            stroke_width=1,
            stroke_color=DARK_GRAY,
        )

        top_anim = DrawBorderThenFill(
            vmobject=top,
            run_time=3,
            rate_func=double_smooth,
            stroke_width=1,
            stroke_color=DARK_GRAY,
        )

        txt_anim = DrawBorderThenFill(
            vmobject=text,
            run_time=3,
            rate_func=double_smooth,
            stroke_width=1.5,
            stroke_color=DARK_GRAY,
        )

        frame_create = DrawBorderThenFill(
            vmobject=frame,
            run_time=3,
            rate_func=double_smooth,
            stroke_width=1,
            stroke_color=DARK_GRAY,
        )

        self.add(bgnd)  # add background
        self.play(frame_create, bot_anim, top_anim, mid_anim)
        self.play(ApplyMethod(logo.shift, UP * LOGO_UP),
                  ApplyMethod(frame.shift, UP * LOGO_UP),
                  run_time=1)
        self.play(txt_anim)
        self.wait()

        ps_anim = FadeToColor(text[4], FIVED_YELLOW)

        self.play(ps_anim)

        d = text[4].copy()
        self.add(d)

        self.play(VFadeOut(logo, direction=UP, run_time=0.5),
                  VFadeOut(frame, run_time=0.5),
                  VFadeOut(text, direction=DOWN, run_time=0.5),
                  ApplyMethod(d.shift, LEFT, run_time=0.75))

        self.play(ApplyMethod(d.scale, 240), run_time=0.5)
        self.wait()
        self.remove(bgnd)
        self.play(FadeOut(d), run_time=0.5)
        self.wait()