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.width == scale_factor * s.width and (anim.mobject.target.get_center() == direction).all())
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
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
def test_animationbuilder_in_group(using_opengl_renderer): 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)
def test_animationgroup_with_wait(using_opengl_renderer): 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 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)
def generate_points(self): for vect in IN, OUT, LEFT, RIGHT, UP, DOWN: face = Square( side_length=self.side_length, shade_in_3d=True, ) face.flip() face.shift(self.side_length * OUT / 2.0) face.apply_matrix(z_to_vector(vect)) self.add(face)
def test_chained_animate_with_args(using_opengl_renderer): 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
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
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
def __init__(self, dark_theme: bool = True): super().__init__() logo_green = "#81b29a" logo_blue = "#454866" logo_red = "#e07a5f" m_height_over_anim_height = 0.75748 self.font_color = "#ece6e2" if dark_theme else "#343434" self.scale_factor = 1 self.M = MathTex(r"\mathbb{M}").scale(7).set_color(self.font_color) self.M.shift(2.25 * LEFT + 1.5 * UP) self.circle = Circle(color=logo_green, fill_opacity=1).shift(LEFT) self.square = Square(color=logo_blue, fill_opacity=1).shift(UP) self.triangle = Triangle(color=logo_red, fill_opacity=1).shift(RIGHT) self.shapes = VGroup(self.triangle, self.square, self.circle) self.add(self.shapes, self.M) self.move_to(ORIGIN) anim = VGroup() for i, ch in enumerate("anim"): tex = Tex( "\\textbf{" + ch + "}", tex_template=TexFontTemplates.gnu_freeserif_freesans, ) if i != 0: tex.next_to(anim, buff=0.01) tex.align_to(self.M, DOWN) anim.add(tex) anim.set_color(self.font_color) anim.height = m_height_over_anim_height * self.M.height # Note: "anim" is only shown in the expanded state # and thus not yet added to the submobjects of self. self.anim = anim
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