def __init__(self, eq1, eq2, regex, regex2=None, map_list=None, align_char=None): # align equations if align_char: difference_vec = \ self.mob_from_char(eq1, eq1.tex_string, align_char).get_center() - \ self.mob_from_char(eq2, eq2.tex_string, align_char).get_center() else: difference_vec = eq1.get_center() - eq2.get_center() eq2.shift(difference_vec) if regex2 is None: g1 = self.split_by_regex(eq1, regex) g2 = self.split_by_regex(eq2, regex) assert (len(g1.submobjects) == len(g2.submobjects)) trans = ReplacementTransform(g1, g2) AnimationGroup.__init__(self, trans) else: assert (map_list) g1 = self.split_by_regex(eq1, regex) g2 = self.split_by_regex(eq2, regex2) self.g1 = g1 self.g2 = g2 G1 = VGroup() G2 = VGroup() F1 = Group() F2 = Group() g1_nodes = set(pair[0] for pair in map_list) g2_nodes = set(pair[1] for pair in map_list) while map_list: l1 = [g1.submobjects[map_list[0][0]]] l2 = [g2.submobjects[map_list[0][1]]] new_list = [] for i in range(1, len(map_list)): if map_list[i][0] == map_list[0][0]: l2.append(g2.submobjects[map_list[i][1]]) elif map_list[i][1] == map_list[0][1]: l1.append(g1.submobjects[map_list[i][0]]) else: new_list.append(map_list[i]) map_list = new_list G1.submobjects.append(VGroup(*l1)) G2.submobjects.append(VGroup(*l2)) for i in range(len(g1.submobjects)): if i not in g1_nodes: F1.submobjects.append(g1.submobjects[i]) for i in range(len(g2.submobjects)): if i not in g2_nodes: F2.submobjects.append(g2.submobjects[i]) self.g1 = g1 self.g2 = g2 trans = ReplacementTransform(G1, G2) fadeout = FadeOut(F1) fadein = FadeIn(F2) AnimationGroup.__init__(self, trans, fadeout, fadein)
def __init__(self, bubble, **kwargs): digest_config(self, kwargs) create_bubble = self.bubble_animation_class( bubble, *self.bubble_animation_args, **self.bubble_animation_kwargs ) create_content = self.content_animation_class( VGroup(*bubble.content), *self.content_animation_args, **self.content_animation_kwargs ) AnimationGroup.__init__( self, create_bubble, create_content, **kwargs )
def __init__(self, pi_creature, **kwargs): assert hasattr(pi_creature, "bubble") digest_config(self, kwargs, locals()) pi_creature.generate_target() pi_creature.target.change_mode(self.target_mode) if self.look_at_arg is not None: pi_creature.target.look_at(self.look_at_arg) AnimationGroup.__init__( self, MoveToTarget(pi_creature), FadeOut(pi_creature.bubble), FadeOut(pi_creature.bubble.content), )
def get_flip_arrows_animation(self, n, color=None): arrows = [self.get_arrow_by_number(k) for k in range(n + 1)] for arrow in arrows: arrow.generate_target() arrow.target.rotate(np.pi) if color is not None: arrow.target.set_color(color) return AnimationGroup(*[MoveToTarget(arrow) for arrow in arrows])
def __init__(self, pi_creature, *content, **kwargs): digest_config(self, kwargs) bubble = pi_creature.get_bubble(*content, bubble_class=self.bubble_class, **self.bubble_kwargs) Group(bubble, bubble.content).shift_onto_screen() pi_creature.generate_target() pi_creature.target.change_mode(self.target_mode) if self.look_at_arg is not None: pi_creature.target.look_at(self.look_at_arg) change_mode = MoveToTarget(pi_creature, **self.change_mode_kwargs) bubble_creation = self.bubble_creation_class( bubble, **self.bubble_creation_kwargs) content_introduction = self.content_introduction_class( bubble.content, **self.content_introduction_kwargs) AnimationGroup.__init__(self, change_mode, bubble_creation, content_introduction, **kwargs)
def __init__(self, drunk, pos, total_time=1, turn_ratio=0.25): anims = [] if self.is_same_direction(drunk, pos): anims.append(ApplyMethod(drunk.step_on, pos, run_time=total_time)) else: turn_target = drunk.deepcopy().turn_around() move_target = turn_target.deepcopy().step_on(pos) ## TODO: This part is currently broken! anims.append( Succession( ApplyMethod(drunk.turn_around, run_time=turn_ratio * total_time), ApplyMethod(turn_target.step_on, pos, run_time=(1 - turn_ratio) * total_time), FadeOut(turn_target, run_time=0), Transform(drunk, move_target, run_time=0), )) drunk.change_direction() AnimationGroup.__init__(self, *anims)
def solve_the_equations(self): rects = VGroup(*[ CoverRectangle( equation[0].get_exponent(), stroke_color = color, text = str(num), text_color = color ) for equation, color, num in zip(self.equations, self.colors, self.nums) ]) self.play(DrawBorderThenFill(rects)) self.wait() sps = VGroup() for equation, num, color in zip(self.equations, self.nums, self.colors): sp = TexMobject("x", "^{%d}" % num, "=", "%d" % num) sp[1::2].set_color(color) sp.scale(2) sp.next_to(equation, DOWN, buff = 1) sps.add(sp) rss = VGroup() for num, sp, color in zip(self.nums, sps, self.colors): rs = TexMobject("x", "=", "%d" % num , "^{{1}\\over{%d}}" % num, "=\\sqrt{2}") for tex in (rs[2], rs[3][2]): tex.set_color(color) rs.match_height(sp).move_to(sp) rss.add(rs) tf_anims = [] for sp, rs in zip(sps, rss): tf_anims.append(ReplacementTransform(sp[0], rs[0])) tf_anims.append(ReplacementTransform(sp[1], rs[3][2], path_arc = -TAU/4)) tf_anims.append(ReplacementTransform(sp[2], rs[1])) tf_anims.append(ReplacementTransform(sp[3], rs[2])) tf_anims.append(Write(rs[3][:2])) self.play(FadeIn(sps)) self.wait() self.play(AnimationGroup(*tf_anims), run_time = 2) self.wait() self.play(Write(VGroup(*[rs[4:] for rs in rss]), submobject_mode = "all_at_once")) self.wait() self.play(FadeOut(rects)) self.wait() self.rss = rss
def creation_anim(self, label_anim=FadeIn, brace_anim=GrowFromCenter): return AnimationGroup(brace_anim(self.brace), label_anim(self.label))
def __init__(self, mobject, **kwargs): digest_config(self, kwargs) rect = SurroundingRectangle( mobject, **self.surrounding_rectangle_config ) AnimationGroup.__init__(self, self.rect_to_animation(rect, **kwargs))
def __init__(self, mobject, **kwargs): digest_config(self, kwargs) rect = SurroundingRectangle(mobject, **self.surrounding_rectangle_config) AnimationGroup.__init__(self, self.rect_to_animation(rect, **kwargs))
def clean_up(self, surrounding_scene=None): AnimationGroup.clean_up(self, surrounding_scene) self.pi_creature.bubble = None if surrounding_scene is not None: surrounding_scene.add(self.pi_creature)