def __init__(self, AnimationClass, mobjects, **kwargs): full_kwargs = AnimationClass.CONFIG full_kwargs.update(kwargs) full_kwargs["mobject"] = Mobject(*[ mob.get_point_mobject() for mob in mobjects ]) self.centers_container = AnimationClass(**full_kwargs) full_kwargs.pop("mobject") Animation.__init__(self, Mobject(*mobjects), **full_kwargs) self.name = str(self) + AnimationClass.__name__
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) text_1 = TextMobject("Theorem of") \ .next_to(number_line, DOWN) text_2 = TextMobject("Beethoven") \ .next_to(number_line, DOWN) dashed_line = DashedLine( number_line.get_left(), number_line.get_right(), color=YELLOW, ).set_stroke(width=11) self.add(number_line, text_1) self.play( LaggedStart(*[ ShowCreationThenDestruction(dashed_segment) for dashed_segment in dashed_line ], run_time=5), AnimationGroup(Animation(Mobject(), run_time=2.1), ReplacementTransform(text_1, text_2), lag_ratio=1)) self.wait()
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) numbers = VGroup( *[TextMobject("%s" % i) \ .next_to(number_line.get_tick(i - 2), DOWN) for i in range(1, 5)] ) self.add(number_line) self.play(ShowCreation(triangle)) self.wait(0.3) self.play( ApplyMethod(triangle.shift, RIGHT * 4, rate_func=linear, run_time=4), *[ AnimationGroup(Animation(Mobject(), run_time=i + 1), Write(numbers[i]), lag_ratio=1) for i in range(4) ], ) self.wait()
def test_get_updaters(self): obj = Mobject() obj.add_updater(__func__) obj.add_updater(__func__) obj.add_updater(__func__) self.assertListEqual([__func__, __func__, __func__], obj.get_updaters())
def test_add_updater(self): obj = Mobject() self.assertListEqual([], obj.updaters) obj.add_updater(__func__) self.assertListEqual([__func__], obj.updaters) obj.add_updater(__dt_func__) self.assertListEqual([__func__, __dt_func__], obj.updaters)
def test_stretch_factor_1(self): obj = Mobject() obj.points = np.array([[1.0, 1.0, 1.0]]) obj.stretch(1, 0) obj.stretch(1, 1) obj.stretch(1, 2) np.testing.assert_array_equal(obj.points, np.array([[1, 1, 1]]))
def __init__(self, mobject_or_chars): TextMobject.__init__(self) if mobject_or_chars == None or (isinstance(mobject_or_chars, Mobject) and mobject_or_chars.name == "Mobject"): mobject = Mobject() elif isinstance(mobject_or_chars, (list)): mobject = ImageMobject(mobject_or_chars[0]) self.add(mobject) self = mobject.copy() elif isinstance(mobject_or_chars, Mobject) and mobject_or_chars.name == "ImageMobject": mobject = mobject_or_chars self.add(mobject) self = mobject_or_chars[0].copy() else: if isinstance(mobject_or_chars, str): #mobject =MTex(mobject_or_chars) mobject = TextMobject(mobject_or_chars) elif isinstance(mobject_or_chars, int): mobject = Integer(mobject_or_chars) elif isinstance(mobject_or_chars, float): mobject = DecimalNumber(mobject_or_chars) elif isinstance(mobject_or_chars, (tuple)): mobject = TextMobject(*mobject_or_chars) else: mobject = mobject_or_chars self.become(mobject) self.name = mobject.name self.__class__ = mobject.__class__
def __init__(self, mobjs="", mobj=Circle(), scale=1, shift=[0, 0, 0], offset=None, run_time=1, clear=True, **kwargs): if offset is None: offset = shift if mobjs != None: if mobjs == "": try: mobjs = ImageMobjectGroup( np.char.mod('%01d', range(0, 10)), "sidewayoutput\\sidewayoutput2020yt") except: mobjs = ImageMobjectGroup( np.char.mod('%01d', range(9, -1, -1)), "001\\") #if mobj!=None: t = mobj.update().get_critical_point( [-1, 1, 0]) - mobjs.get_critical_point([-1, 1, 0]) [ each.add_updater(lambda mob, mob0=mobj: mob.shift( mob0.get_critical_point([-1, 1, 0]) - mob.get_critical_point( [-1, 1, 0])).shift(offset)) for each in mobjs ] if clear: mobjs.add(Mobject()) super().__init__( ShowSubmobjectsOneByOne(mobjs.update().scale(scale), run_time=run_time, **kwargs), )
def generate_points(self): phi = (1 + np.sqrt(5)) / 2 x = np.array([1, 0, 0]) y = np.array([0, 1, 0]) z = np.array([0, 0, 1]) v1, v2 = (phi, 1 / phi, 0), (phi, -1 / phi, 0) vertex_pairs = [ (v1, v2), (x + y + z, v1), (x + y - z, v1), (x - y + z, v2), (x - y - z, v2), ] five_lines_points = Mobject(*[ Line(pair[0], pair[1], density=1.0 / self.epsilon) for pair in vertex_pairs ]).points #Rotate those 5 edges into all 30. for i in range(3): perm = [j % 3 for j in range(i, i + 3)] for b in [-1, 1]: matrix = b * np.array([x[perm], y[perm], z[perm]]) self.add_points(np.dot(five_lines_points, matrix)) self.pose_at_angle() self.set_color(GREEN)
def test_rotate_returns_self(self): a = random.Random().randint(-1000, 1000) x = random.Random().randint(-1000, 1000) y = random.Random().randint(-1000, 1000) z = random.Random().randint(-1000, 1000) obj = Mobject() obj.points = np.array([x, y, z]) self.assertEqual(obj, obj.rotate(a, about_point=np.array([0, 0, 0])))
def __init__(self, *mobjects, **kwargs): self.show_rate_func = linear kwargs = merge_config_kwargs(self, kwargs) super().__init__( ShowSubmobjectsOneByOne(mobjects[0].add(Mobject()), rate_func=self.show_rate_func, **kwargs), FadeInThenIndicateThenFadeOut(mobjects[1], **kwargs), **kwargs)
def test_shift_onto_screen_two(self): obj = Mobject() obj.points = np.array([[FRAME_X_RADIUS * 2, 0, 0]]) obj.shift_onto_screen() np.testing.assert_array_equal( obj.points, np.array([[FRAME_X_RADIUS - DEFAULT_MOBJECT_TO_EDGE_BUFFER, 0, 0]]))
def test_stretch_origin(self): obj = Mobject() obj.points = np.array([[0.0, 0.0, 0.0]]) f = random.Random().randint(-1000, 1000) obj.stretch(f, 0) obj.stretch(f, 1) obj.stretch(f, 2) np.testing.assert_array_equal(obj.points, np.zeros((1, 3)))
def test_center(self): x = random.Random().randint(-1000, 1000) y = random.Random().randint(-1000, 1000) z = random.Random().randint(-1000, 1000) obj = Mobject() obj.points = np.array([[x, y, z]]) obj.center() np.testing.assert_array_equal(obj.points, np.zeros((1, 3)))
def __init__(self, *animations, **kwargs): if not all([isinstance(m, (Animation)) for m in animations]): raise Exception("All subanimations must be of type Animation") digest_config(self, kwargs) if self.name is None: self.name = self.__class__.__name__ self.subanimations = [] Animation.__init__(self, Mobject(), **kwargs) self.add(*animations)
def test_scale(self): s = random.Random().randint(-1000, 1000) x = random.Random().randint(-1000, 1000) y = random.Random().randint(-1000, 1000) z = random.Random().randint(-1000, 1000) obj = Mobject() obj.points = np.array([[x, y, z]]) obj.scale(s, about_point=np.array([0, 0, 0])) np.testing.assert_array_equal(obj.points, np.array([[x * s, y * s, z * s]]))
def test_apply_to_family(self): obj = Mobject() obj.points = np.zeros((1, 3)) self.assertEqual(0, obj.get_x()) self.assertEqual(0, obj.get_y()) self.assertEqual(0, obj.get_z()) obj.apply_to_family(__x_func__) self.assertEqual(1, obj.get_x()) self.assertEqual(0, obj.get_y()) self.assertEqual(0, obj.get_z())
def __init__(self, background=None, **kwargs): digest_config(self, kwargs, locals()) self.init_vars() self.rgb_max_val = np.iinfo(self.pixel_array_dtype).max self.pixel_array_to_cairo_context = {} self.init_background() self.resize_frame_shape() self.reset() self.xframe = Mobject() self.cameramframe = self
def __gen__(self, obj, depth): for _ in range(self.r.randint(1, self.max_num_of_points + 1)): obj.points = numpy.append(obj.points, [self.__gen_array_in_bounds__()], axis=0) if depth <= 0 or not self.__should_make_child__(.75): return obj for _ in range(self.r.randint(0, self.max_num_of_children)): child = Mobject() obj.add(self.__gen__(child, depth - 1)) return obj
def __init__(self, *sub_anims, **kwargs): sub_anims = [x for x in sub_anims if not(x.empty)] digest_config(self, locals()) self.update_config(**kwargs) # Handles propagation to self.sub_anims if len(sub_anims) == 0: self.empty = True self.run_time = 0 else: self.run_time = max([a.run_time for a in sub_anims]) everything = Mobject(*[a.mobject for a in sub_anims]) Animation.__init__(self, everything, **kwargs)
def test_shift(self): a = random.Random().randint(-1000, 1000) b = random.Random().randint(-1000, 1000) c = random.Random().randint(-1000, 1000) x = random.Random().randint(-1000, 1000) y = random.Random().randint(-1000, 1000) z = random.Random().randint(-1000, 1000) obj = Mobject() obj.points = np.array([[x, y, z]]) obj.shift(np.array([a, b, c])) np.testing.assert_array_equal(obj.points, np.array([[x + a, y + b, z + c]]))
def test_stretch_factor_random(self): obj = Mobject() obj.points = np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]) f = random.Random().randint(-1000, 1000) obj.stretch(f, 0) obj.stretch(f, 1) obj.stretch(f, 2) f /= 2 np.testing.assert_array_almost_equal(obj.points, np.array([[-f, -f, -f], [f, f, f]]), decimal=0)
def __init__(self, **kwargs): digest_config(self, kwargs, locals()) if self.file_name is None: raise Exception("Must invoke Bubble subclass") SVGMobject.__init__(self, self.file_name, **kwargs) self.center() self.stretch_to_fit_height(self.height) self.stretch_to_fit_width(self.width) if self.direction[0] > 0: self.flip() self.direction_was_specified = ("direction" in kwargs) self.content = Mobject() self.refresh_triangulation()
def get_highlight(self, mobject: Mobject) -> Mobject: if isinstance(mobject, VMobject) and mobject.has_points( ) and not self.select_top_level_mobs: length = max([mobject.get_height(), mobject.get_width()]) result = VHighlight( mobject, max_stroke_addition=min([50 * length, 10]), ) result.add_updater(lambda m: m.replace(mobject, stretch=True)) return result elif isinstance(mobject, DotCloud): return Mobject() else: return self.get_corner_dots(mobject)
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) text_1 = TextMobject("1") \ .next_to(number_line.get_tick(-1), DOWN) text_2 = TextMobject("2") \ .next_to(number_line.get_tick(0), DOWN) text_3 = TextMobject("3") \ .next_to(number_line.get_tick(1), DOWN) text_4 = TextMobject("4") \ .next_to(number_line.get_tick(2), DOWN) self.add(number_line) self.play(ShowCreation(triangle)) self.wait(0.3) self.play( ApplyMethod(triangle.shift, RIGHT * 4, rate_func=linear, run_time=4), AnimationGroup(Animation(Mobject(), run_time=1), Write(text_1), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=2), Write(text_2), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=3), Write(text_3), lag_ratio=1), AnimationGroup(Animation(Mobject(), run_time=4), Write(text_4), lag_ratio=1)) self.wait()
def __init__(self, **kwargs): digest_config(self, kwargs, locals()) if self.file_name is None: raise Exception("Must invoke Bubble subclass") try: SVGMobject.__init__(self, **kwargs) except IOError as err: self.file_name = os.path.join(FILE_DIR, self.file_name) SVGMobject.__init__(self, **kwargs) self.center() self.stretch_to_fit_height(self.height) self.stretch_to_fit_width(self.width) if self.direction[0] > 0: self.flip() self.direction_was_specified = ("direction" in kwargs) self.content = Mobject()
def test_rotate(self): a = random.Random().randint(-1000, 1000) x = random.Random().randint(-1000, 1000) y = random.Random().randint(-1000, 1000) z = random.Random().randint(-1000, 1000) obj = Mobject() obj.points = np.array([[x, y, z]]) obj.rotate(a, axis=np.array([0, 0, 1]), about_point=np.array([0, 0, 0])) np.testing.assert_array_equal( obj.points, np.array([[ x * math.cos(a) - y * math.sin(a), x * math.sin(a) + y * math.cos(a), z ]]))
def test_align_on_border(self): obj = Mobject() obj.points = np.zeros((1, 3)) obj.align_on_border(np.array([0, 1, 0])) np.testing.assert_array_equal( obj.points, np.array([[0, FRAME_Y_RADIUS - DEFAULT_MOBJECT_TO_EDGE_BUFFER, 0]])) obj.align_on_border(np.array([1, 0, 0])) np.testing.assert_array_equal( obj.points, np.array([[ FRAME_X_RADIUS - DEFAULT_MOBJECT_TO_EDGE_BUFFER, FRAME_Y_RADIUS - DEFAULT_MOBJECT_TO_EDGE_BUFFER, 0 ]]))
def construct(self): number_line = NumberLine(x_min=-2, x_max=2) text = TextMobject("Text") \ .next_to(number_line, DOWN) dashed_line = DashedLine( number_line.get_left(), number_line.get_right(), color=YELLOW, ).set_stroke(width=11) self.add(number_line) self.wait(0.3) self.play( LaggedStart(*[ ShowCreationThenDestruction(dashed_segment) for dashed_segment in dashed_line ], run_time=5), AnimationGroup(Animation(Mobject(), run_time=2.1), Write(text), lag_ratio=1)) self.wait()
def construct(self): # Add title title = self.title = TextMobject("Clicky Stuffs") title.scale(1.5) title.to_edge(UP, buff=MED_SMALL_BUFF) pi_creatures = VGroup(Randolph(), Mortimer()) for pi, vect in zip(pi_creatures, [LEFT, RIGHT]): pi.set_height(title.get_height()) pi.change_mode("thinking") pi.look(DOWN) pi.next_to(title, vect, buff=MED_LARGE_BUFF) self.add(title, pi_creatures) # Set the top of the screen logo_box = Square(side_length=2.5) logo_box.to_corner(DOWN + LEFT, buff=MED_LARGE_BUFF) black_rect = Rectangle( fill_color=BLACK, fill_opacity=1, stroke_width=3, stroke_color=BLACK, width=FRAME_WIDTH, height=0.6 * FRAME_HEIGHT, ) black_rect.to_edge(UP, buff=0) line = DashedLine(FRAME_X_RADIUS * LEFT, FRAME_X_RADIUS * RIGHT) line.move_to(ORIGIN) # Add thanks thanks = TextMobject(self.thanks_words) thanks.scale(0.9) thanks.next_to(black_rect.get_bottom(), UP, SMALL_BUFF) thanks.set_color(YELLOW) underline = Line(LEFT, RIGHT) underline.match_width(thanks) underline.scale(1.1) underline.next_to(thanks, DOWN, SMALL_BUFF) thanks.add(underline) # Build name list file_name = os.path.join(get_directories()["data"], "patrons.txt") with open(file_name, "r") as fp: names = [ self.modify_patron_name(name.strip()) for name in fp.readlines() ] if self.randomize_order: random.shuffle(names) else: names.sort() name_labels = VGroup(*map(TextMobject, names)) name_labels.scale(self.patron_scale_val) for label in name_labels: if label.get_width() > self.max_patron_width: label.set_width(self.max_patron_width) columns = VGroup(*[ VGroup(*name_labels[i::self.n_patron_columns]) for i in range(self.n_patron_columns) ]) column_x_spacing = 0.5 + max([c.get_width() for c in columns]) for i, column in enumerate(columns): for n, name in enumerate(column): name.shift(n * self.name_y_spacing * DOWN) name.align_to(ORIGIN, LEFT) column.move_to(i * column_x_spacing * RIGHT, UL) columns.center() max_width = FRAME_WIDTH - 1 if columns.get_width() > max_width: columns.set_width(max_width) underline.match_width(columns) columns.next_to(underline, DOWN, buff=3) # Set movement columns.generate_target() distance = columns.get_height() + 2 wait_time = self.scroll_time frame = self.camera.frame frame_shift = ApplyMethod( frame.shift, distance * DOWN, run_time=wait_time, rate_func=linear, ) blink_anims = [] blank_mob = Mobject() for x in range(wait_time): if random.random() < 0.25: blink_anims.append(Blink(random.choice(pi_creatures))) else: blink_anims.append(Animation(blank_mob)) blinks = Succession(*blink_anims) static_group = VGroup(black_rect, line, thanks, pi_creatures, title) static_group.fix_in_frame() self.add(columns, static_group) self.play(frame_shift, blinks)