def get_division_change_animations( self, sample_space, parts, p_list, dimension = 1, new_label_kwargs = None, **kwargs ): if new_label_kwargs is None: new_label_kwargs = {} anims = [] p_list = sample_space.complete_p_list(p_list) space_copy = sample_space.copy() vect = DOWN if dimension == 1 else RIGHT parts.generate_target() for part, p in zip(parts.target, p_list): part.replace(space_copy, stretch = True) part.stretch(p, dimension) parts.target.arrange_submobjects(vect, buff = 0) parts.target.move_to(space_copy) anims.append(MoveToTarget(parts)) if hasattr(parts, "labels") and parts.labels is not None: label_kwargs = parts.label_kwargs label_kwargs.update(new_label_kwargs) new_braces, new_labels = sample_space.get_subdivision_braces_and_labels( parts.target, **label_kwargs ) anims += [ Transform(parts.braces, new_braces), Transform(parts.labels, new_labels), ] return anims
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 apply_complex_function(self, func, added_anims=[], **kwargs): transformer, transform_kwargs = self.get_transformer(**kwargs) transformer.generate_target() transformer.target.apply_complex_function(func) for mob in transformer.target[0].family_members_with_points(): mob.make_smooth() if self.post_transformation_stroke_width is not None: transformer.target.set_stroke( width=self.post_transformation_stroke_width) self.play(MoveToTarget(transformer, **transform_kwargs), *added_anims)
def compile_method(state): if state["curr_method"] is None: return mobject = state["curr_method"].im_self if state["last_method"] and state["last_method"].im_self is mobject: animations.pop() #method should already have target then. else: mobject.target = mobject.copy() state["curr_method"].im_func(mobject.target, *state["method_args"]) animations.append(MoveToTarget(mobject)) state["last_method"] = state["curr_method"] state["curr_method"] = None state["method_args"] = []
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 increment(self, run_time_per_anim = 1): moving_dot = Dot( self.counting_dot_starting_position, radius = self.count_dot_starting_radius, color = self.digit_place_colors[0], ) moving_dot.generate_target() moving_dot.set_fill(opacity = 0) kwargs = { "run_time" : run_time_per_anim } continue_rolling_over = True first_move = True place = 0 while continue_rolling_over: added_anims = [] if first_move: added_anims += self.get_digit_increment_animations() first_move = False moving_dot.target.replace( self.dot_template_iterators[place].next() ) self.play(MoveToTarget(moving_dot), *added_anims, **kwargs) self.curr_configurations[place].add(moving_dot) if len(self.curr_configurations[place].split()) == self.get_place_max(place): full_configuration = self.curr_configurations[place] self.curr_configurations[place] = VGroup() place += 1 center = full_configuration.get_center_of_mass() radius = 0.6*max( full_configuration.get_width(), full_configuration.get_height(), ) circle = Circle( radius = radius, stroke_width = 0, fill_color = self.digit_place_colors[place], fill_opacity = 0.5, ) circle.move_to(center) moving_dot = VGroup(circle, full_configuration) moving_dot.generate_target() moving_dot[0].set_fill(opacity = 0) else: continue_rolling_over = False
def apply_complex_function(self, func, added_anims=[], **kwargs): transformer, transform_kwargs = self.get_transformer(**kwargs) transformer.generate_target() #Rescale, apply function, scale back transformer.target.shift(-self.background.get_center_point()) transformer.target.scale(1. / self.background.unit_size) transformer.target.apply_complex_function(func) transformer.target.scale(self.background.unit_size) transformer.target.shift(self.background.get_center_point()) # for mob in transformer.target[0].family_members_with_points(): mob.make_smooth() if self.post_transformation_stroke_width is not None: transformer.target.set_stroke( width=self.post_transformation_stroke_width) self.play(MoveToTarget(transformer, **transform_kwargs), *added_anims)
def __init__(self, pi_creature, *content, **kwargs): digest_config(self, kwargs) bubble = pi_creature.get_bubble("speech", **self.bubble_kwargs) bubble.write(*content) bubble.resize_to_content() bubble.pin_to(pi_creature) pi_creature.bubble = bubble pi_creature.generate_target() pi_creature.target.change_mode(self.target_mode) if self.look_at_arg: pi_creature.target.look_at(self.look_at_arg) AnimationGroup.__init__( self, MoveToTarget(pi_creature, **self.change_mode_kwargs), ShowCreation(bubble, **self.bubble_creation_kwargs), Write(bubble.content, **self.write_kwargs), **kwargs)
def __init__(self, pi_creature, *content, **kwargs): digest_config(self, kwargs) if isinstance(content, Mobject): bubble_content = content else: bubble_content = TextMobject(*content) bubble = pi_creature.get_bubble(self.bubble_class, content=bubble_content, **self.bubble_kwargs) pi_creature.generate_target() pi_creature.target.change_mode(self.target_mode) if self.look_at_arg: pi_creature.target.look_at(self.look_at_arg) AnimationGroup.__init__( self, MoveToTarget(pi_creature, **self.change_mode_kwargs), ShowCreation(bubble, **self.bubble_creation_kwargs), Write(bubble.content, **self.write_kwargs), **kwargs)
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 compile_method(state): if state["curr_method"] is None: return mobject = state["curr_method"].im_self if state["last_method"] and state["last_method"].im_self is mobject: animations.pop() #method should already have target then. else: mobject.target = mobject.deepcopy() # if len(state["method_args"]) > 0 and isinstance( state["method_args"][-1], dict): method_kwargs = state["method_args"].pop() else: method_kwargs = {} state["curr_method"].im_func(mobject.target, *state["method_args"], **method_kwargs) animations.append(MoveToTarget(mobject)) state["last_method"] = state["curr_method"] state["curr_method"] = None state["method_args"] = []
def __init__(self, pi_creature, *content, **kwargs): digest_config(self, kwargs) if isinstance(content[0], Mobject): bubble_content = content[0] else: bubble_content = TextMobject(*content) bubble = pi_creature.get_bubble(self.bubble_class, content=bubble_content, **self.bubble_kwargs) 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) writing = Write(bubble.content, **self.write_kwargs) AnimationGroup.__init__(self, change_mode, bubble_creation, writing, **kwargs)
def show_the_solution(self): # Prepare for the solution pre_solve = VGroup(*self.question[::2]) self.play( ReplacementTransform(pre_solve, self.solve), FadeOut(self.question[1]), run_time = 1, ) self.wait() # Manipulate LHS old_l_part, r_part = self.equation new_l_part = ExpTower(order = self.highest_order+1, is_infinite = True) new_l_part.match_height(old_l_part) new_l_part.next_to(r_part, LEFT, aligned_edge = DOWN) old_rect, new_rect = rects = [ CoverRectangle(part, text = "2") for part in (old_l_part, new_l_part.get_exponent()) ] old_two, new_two = twos = [ rect.get_text_mob() for rect in rects ] self.play(DrawBorderThenFill(old_rect, run_time = 1)) self.wait() self.play( ReplacementTransform(old_l_part, new_l_part), ReplacementTransform(old_rect, new_rect), ) self.wait() new_equation = VGroup(new_l_part, r_part, new_rect) new_equation.generate_target() new_equation.target.scale(0.8) new_equation.target.shift(UP) self.play(MoveToTarget(new_equation)) self.wait() # A little bit clean-up source_eq = VGroup(*[ mob.copy() for mob in (new_l_part.get_base(), new_two, r_part[0], r_part[1]) ]) source_eq.generate_target() target_eq = TexMobject("x", "^2", "=", "2") target_eq.scale(3).next_to(source_eq, DOWN, buff = 1) for k, (old_part, new_part) in enumerate(zip(source_eq.target, target_eq)): old_part.move_to(new_part) if k == 1: old_part.scale(0.5) old_part.shift(RIGHT/4) self.play( FadeOut(new_rect), MoveToTarget(source_eq), ) self.wait() # Reveal the final answer result = TexMobject("x", "=", "\\sqrt", "2") result.set_height(source_eq.get_height() * 0.7) result.move_to(source_eq) self.play(*[ ReplacementTransform(source_eq[m], result[n], path_arc = angle) for m, n, angle in [(0, 0, 0), (1, 2, -TAU/3), (2, 1, 0), (3, 3, 0)] ]) self.wait() qed = QEDSymbol() qed.next_to(result, RIGHT, aligned_edge = DOWN, buff = 1.5) self.play(FadeIn(qed)) self.wait()