Пример #1
0
def test_chained_animate():
    s = Square()
    scale_factor = 2
    direction = np.array((1, 1, 0))
    anim = s.animate.scale(scale_factor).shift(direction).build()
    assert (anim.mobject.target.get_width() == scale_factor * s.get_width()
            and (anim.mobject.target.get_center() == direction).all())
Пример #2
0
def test_Data():
    config.renderer = "opengl"
    a = Square().move_to(RIGHT)
    data_bb = a.data["bounding_box"]
    assert np.array_equal(
        data_bb,
        np.array([[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [2.0, 1.0, 0.0]]),
    )

    # test that calling the attribute equals calling it from self.data
    assert np.array_equal(a.bounding_box, data_bb)

    # test that the array can be indexed
    assert np.array_equal(
        a.bounding_box[1],
        np.array(
            [1.0, 0.0, 0.0],
        ),
    )

    # test that a value can be set
    a.bounding_box[1] = 300

    # test that both the attr and self.data arrays match after adjusting a value

    data_bb = a.data["bounding_box"]
    assert np.array_equal(
        data_bb,
        np.array([[0.0, -1.0, 0.0], [300.0, 300.0, 300.0], [2.0, 1.0, 0.0]]),
    )

    assert np.array_equal(a.bounding_box, data_bb)
    config.renderer = "cairo"  # needs to be here or else the following cairo tests fail
Пример #3
0
def test_animate_with_args():
    s = Square()
    scale_factor = 2
    run_time = 2

    anim = s.animate(run_time=run_time).scale(scale_factor).build()
    assert anim.mobject.target.width == scale_factor * s.width
    assert anim.run_time == run_time
Пример #4
0
def test_animate_with_args_misplaced():
    s = Square()
    scale_factor = 2
    run_time = 2

    with pytest.raises(ValueError, match="must be passed before"):
        s.animate.scale(scale_factor)(run_time=run_time)

    with pytest.raises(ValueError, match="must be passed before"):
        s.animate(run_time=run_time)(run_time=run_time).scale(scale_factor)
Пример #5
0
def test_chained_animate_with_args():
    s = Square()
    scale_factor = 2
    direction = np.array((1, 1, 0))
    run_time = 2

    anim = s.animate(
        run_time=run_time).scale(scale_factor).shift(direction).build()
    assert (anim.mobject.target.width == scale_factor * s.width
            and (anim.mobject.target.get_center() == direction).all())
    assert anim.run_time == run_time
Пример #6
0
def test_animationbuilder_in_group():
    sqr = Square()
    circ = Circle()
    animation_group = AnimationGroup(sqr.animate.shift(DOWN).scale(2), FadeIn(circ))
    assert all(isinstance(anim, Animation) for anim in animation_group.animations)
    succession = Succession(sqr.animate.shift(DOWN).scale(2), FadeIn(circ))
    assert all(isinstance(anim, Animation) for anim in succession.animations)
Пример #7
0
def test_animationgroup_with_wait():
    sqr = Square()
    sqr_anim = FadeIn(sqr)
    wait = Wait()
    animation_group = AnimationGroup(wait, sqr_anim, lag_ratio=1)

    animation_group.begin()
    timings = animation_group.anims_with_timings

    assert timings == [(wait, 0.0, 1.0), (sqr_anim, 1.0, 2.0)]
 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
Пример #9
0
def test_animationgroup_is_passing_remover_to_animations(
        animation_remover, animation_group_remover):
    scene = Scene()
    sqr_animation = Create(Square(), remover=animation_remover)
    circ_animation = Write(Circle(), remover=animation_remover)
    animation_group = AnimationGroup(sqr_animation,
                                     circ_animation,
                                     remover=animation_group_remover)

    scene.play(animation_group)
    scene.wait(0.1)

    assert sqr_animation.remover
    assert circ_animation.remover
Пример #10
0
def test_animationgroup_is_passing_remover_to_nested_animationgroups():
    scene = Scene()
    sqr_animation = Create(Square())
    circ_animation = Write(Circle(), remover=True)
    polygon_animation = Create(RegularPolygon(5))
    animation_group = AnimationGroup(
        AnimationGroup(sqr_animation, polygon_animation), circ_animation, remover=True
    )

    scene.play(animation_group)
    scene.wait(0.1)

    assert sqr_animation.remover
    assert circ_animation.remover
    assert polygon_animation.remover
Пример #11
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))
 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
Пример #13
0
def test_simple_animate():
    s = Square()
    scale_factor = 2
    anim = s.animate.scale(scale_factor).build()
    assert anim.mobject.target.width == scale_factor * s.width
 def _generate_open_square(self, position):
     sq = Square(side_length=self.scale, **self.OPEN_SQUARE_KWARGS)
     sq.move_to(position)
     return sq
Пример #15
0
    def generate_points(self):
        faces = np.array(
            get_faces_of_cubie(self.dimensions,
                               (self.position[0], self.position[1],
                                self.position[2]))).tolist()
        i = 0
        for vect in OUT, DOWN, LEFT, IN, UP, RIGHT:
            face = Square(side_length=2, shade_in_3d=True,
                          stroke_width=3)  #(**self.dict)
            if vect.tolist() in faces:
                face.set_fill(self.colors[i], 1)
            else:
                face.set_fill(BLACK, 1)

            face.flip()
            face.shift(2 * OUT / 2.0)
            face.apply_matrix(z_to_vector(vect))

            self.faces[tuple(vect)] = face
            self.add(face)
            i += 1
    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()