def __init__(self, pi_creature, *content, **kwargs): digest_config(self, kwargs) bubble = pi_creature.get_bubble("speech") bubble.write(*content) bubble.resize_to_content() bubble.pin_to(pi_creature) pi_creature.bubble = bubble AnimationGroup.__init__( self, ApplyMethod( pi_creature.change_mode, self.target_mode, **self.change_mode_kwargs ), ShowCreation( bubble, **self.bubble_creation_kwargs ), Write( bubble.content, **self.write_kwargs ), **kwargs )
def setup_axes(self, animate=False): ##TODO, once eoc is done, refactor this to be less redundant. x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range self.x_labeled_nums = self.x_labeled_nums or [] if self.x_leftmost_tick is None: self.x_leftmost_tick = self.x_min x_axis = NumberLine(x_min=self.x_min, x_max=self.x_max, unit_size=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = filter(lambda x: x != 0, self.x_labeled_nums) x_axis.add_numbers(*self.x_labeled_nums) x_label = TextMobject(self.x_axis_label) x_label.next_to(x_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range self.y_labeled_nums = self.y_labeled_nums or [] if self.y_bottom_tick is None: self.y_bottom_tick = self.y_min y_axis = NumberLine(x_min=self.y_min, x_max=self.y_max, unit_size=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = filter(lambda y: y != 0, self.y_labeled_nums) y_axis.add_numbers(*self.y_labeled_nums) for mob in y_axis.numbers: mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF) mob.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to(y_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors)
def coords_to_vector(self, vector, coords_start=2 * RIGHT + 2 * UP, clean_up=True): starting_mobjects = list(self.mobjects) array = Matrix(vector) array.shift(coords_start) arrow = Vector(vector) x_line = Line(ORIGIN, vector[0] * RIGHT) y_line = Line(x_line.get_end(), arrow.get_end()) x_line.highlight(X_COLOR) y_line.highlight(Y_COLOR) x_coord, y_coord = array.get_mob_matrix().flatten() self.play(Write(array, run_time=1)) self.dither() self.play( ApplyFunction( lambda x: self.position_x_coordinate(x, x_line, vector), x_coord)) self.play(ShowCreation(x_line)) self.play( ApplyFunction( lambda y: self.position_y_coordinate(y, y_line, vector), y_coord), FadeOut(array.get_brackets())) y_coord, brackets = self.get_mobjects_from_last_animation() self.play(ShowCreation(y_line)) self.play(ShowCreation(arrow)) self.dither() if clean_up: self.clear() self.add(*starting_mobjects)
def construct(self): morty = Mortimer() morty.next_to(ORIGIN, DOWN) n_patrons = len(self.specific_patrons) special_thanks = TextMobject("Special thanks") special_thanks.highlight(YELLOW) special_thanks.to_edge(UP) patreon_logo = PatreonLogo() patreon_logo.next_to(morty, UP, buff=MED_LARGE_BUFF) left_patrons = VGroup( *map(TextMobject, self.specific_patrons[:n_patrons / 2])) right_patrons = VGroup( *map(TextMobject, self.specific_patrons[n_patrons / 2:])) for patrons in left_patrons, right_patrons: patrons.arrange_submobjects(DOWN, aligned_edge=LEFT, buff=1.5 * MED_SMALL_BUFF) all_patrons = VGroup(left_patrons, right_patrons) all_patrons.scale(0.7) for patrons, vect in (left_patrons, LEFT), (right_patrons, RIGHT): patrons.to_corner(UP + vect, buff=MED_SMALL_BUFF) shift_distance = max(0, 1 - SPACE_HEIGHT - all_patrons.get_bottom()[1]) velocity = shift_distance / 9.0 def get_shift_anim(): return ApplyMethod(all_patrons.shift, velocity * UP, rate_func=None) self.play( morty.change_mode, "gracious", DrawBorderThenFill(patreon_logo), ) self.play(Write(special_thanks, run_time=1)) self.play(Write(left_patrons), morty.look_at, left_patrons) self.play(Write(right_patrons), morty.look_at, right_patrons) self.play(Blink(morty), get_shift_anim()) for patrons in left_patrons, right_patrons: for index in 0, -1: self.play(morty.look_at, patrons[index], get_shift_anim()) self.play(get_shift_anim())
def construct(self): self.quote = self.get_quote() self.author = self.get_author(self.quote) self.play(FadeIn(self.quote, **self.fade_in_kwargs)) self.dither(2) self.play(Write(self.author, run_time=3)) self.dither()
def add_title(self, title, scale_factor=1.5, animate=False): if not isinstance(title, Mobject): title = TextMobject(title).scale(scale_factor) title.to_edge(UP) title.add_background_rectangle() if animate: self.play(Write(title)) self.add_foreground_mobject(title) self.title = title return self
def construct(self): logo = MirekOlsakLogo(self.camera) series_title = TextMobject(self.series_str).to_edge(UP) self.add(series_title) chapter_title = TextMobject(self.chapter_str) chapter_title.scale(1.4) self.play(Write(chapter_title)) self.play(ShowCreation(logo)) self.dither(self.dither_time) self.play(FadeOut(VGroup(series_title, chapter_title, logo)))
def say(self, words, target_mode="speaking"): if isinstance(words, str): words = TextMobject(words) bubble = SpeechBubble() bubble.add_content(words) bubble.resize_to_content() bubble.pin_to(self.pi_creature) self.play(self.pi_creature.change_mode, target_mode, self.pi_creature.look_at, bubble.content, ShowCreation(bubble), Write(bubble.content)) self.pi_creature.bubble = bubble
def vector_to_coords(self, vector, integer_labels=True, clean_up=True): starting_mobjects = list(self.mobjects) show_creation = False if isinstance(vector, Arrow): arrow = vector vector = arrow.get_end()[:2] else: arrow = Vector(vector) show_creation = True array = vector_coordinate_label(arrow, integer_labels=integer_labels) x_line = Line(ORIGIN, vector[0] * RIGHT) y_line = Line(x_line.get_end(), arrow.get_end()) x_line.highlight(X_COLOR) y_line.highlight(Y_COLOR) x_coord, y_coord = array.get_mob_matrix().flatten() x_coord_start = self.position_x_coordinate(x_coord.copy(), x_line, vector) y_coord_start = self.position_y_coordinate(y_coord.copy(), y_line, vector) brackets = array.get_brackets() if show_creation: self.play(ShowCreation(arrow)) self.play(ShowCreation(x_line), Write(x_coord_start), run_time=1) self.play(ShowCreation(y_line), Write(y_coord_start), run_time=1) self.dither() self.play( Transform(x_coord_start, x_coord, submobject_mode="all_at_once"), Transform(y_coord_start, y_coord, submobject_mode="all_at_once"), Write(brackets, run_time=1), ) self.dither() self.remove(x_coord_start, y_coord_start, brackets) self.add(array) if clean_up: self.clear() self.add(*starting_mobjects) return array, x_line, y_line
def construct(self): morty = Mortimer() morty.next_to(ORIGIN, DOWN) n_patrons = len(self.specific_patrons) special_thanks = TextMobject("Special thanks") special_thanks.highlight(YELLOW) special_thanks.to_edge(UP) patreon_logo = PatreonLogo() patreon_logo.next_to(morty, UP, buff=MED_LARGE_BUFF) patrons = map(TextMobject, self.specific_patrons) patron_groups = [] index = 0 counter = 0 while index < len(patrons): next_index = index + self.patron_group_size group = VGroup(*patrons[index:next_index]) group.arrange_submobjects(DOWN, aligned_edge=LEFT) if counter % 2 == 0: group.to_edge(LEFT) else: group.to_edge(RIGHT) patron_groups.append(group) index = next_index counter += 1 self.play( morty.change_mode, "gracious", DrawBorderThenFill(patreon_logo), ) self.play(Write(special_thanks, run_time=1)) for i, group in enumerate(patron_groups): anims = [ FadeIn( group, run_time=2, submobject_mode="lagged_start", lag_factor=4, ), morty.look_at, group.get_top(), ] if i >= 2: anims.append(FadeOut(patron_groups[i - 2])) self.play(*anims) self.play(morty.look_at, group.get_bottom()) self.play(Blink(morty))
def construct(self): morty = Mortimer() morty.next_to(ORIGIN, DOWN) n_patrons = len(self.specific_patrons) special_thanks = TextMobject("Special thanks") special_thanks.highlight(YELLOW) special_thanks.to_edge(UP) patreon_logo = PatreonLogo() patreon_logo.next_to(morty, UP, buff=MED_LARGE_BUFF) patrons = map(TextMobject, self.specific_patrons) num_groups = float(len(patrons)) / self.patron_group_size proportion_range = np.linspace(0, 1, num_groups + 1) indices = (len(patrons) * proportion_range).astype('int') patron_groups = [ VGroup(*patrons[i:j]) for i, j in zip(indices, indices[1:]) ] for i, group in enumerate(patron_groups): group.arrange_submobjects(DOWN, aligned_edge=LEFT) group.scale(self.patron_scale_val) group.to_edge(LEFT if i % 2 == 0 else RIGHT) self.play( morty.change_mode, "gracious", DrawBorderThenFill(patreon_logo), ) self.play(Write(special_thanks, run_time=1)) print len(patron_groups) for i, group in enumerate(patron_groups): anims = [ FadeIn( group, run_time=2, submobject_mode="lagged_start", lag_factor=4, ), morty.look_at, group.get_top(), ] if i >= 2: anims.append(FadeOut(patron_groups[i - 2])) self.play(*anims) self.play(morty.look_at, group.get_bottom()) self.play(Blink(morty))
def label_graph(self, graph, label="f(x)", proportion=0.7, direction=LEFT, buff=2 * MED_BUFF, animate=True): label = TexMobject(label) label.highlight(graph.get_color()) label.next_to(graph.point_from_proportion(proportion), direction, buff=buff) if animate: self.play(Write(label)) self.add(label) return label
def get_bubble_intro_animation(self, content, bubble_type, pi_creature, **bubble_kwargs): bubble = pi_creature.get_bubble(bubble_type, **bubble_kwargs) bubble.add_content(content) if pi_creature.bubble: content_intro_anims = [ Transform(pi_creature.bubble, bubble), Transform(pi_creature.bubble.content, bubble.content) ] else: content_intro_anims = [ FadeIn(bubble), Write(content), ] pi_creature.bubble = bubble return content_intro_anims
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) 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 __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 setup_axes(self, animate=True): x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range x_axis = NumberLine(x_min=self.x_min, x_max=self.x_max, space_unit_to_num=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick or self.x_min, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if self.x_labeled_nums: x_axis.add_numbers(*self.x_labeled_nums) x_label = TextMobject(self.x_axis_label) x_label.next_to(x_axis, RIGHT + UP, buff=SMALL_BUFF) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range y_axis = NumberLine(x_min=self.y_min, x_max=self.y_max, space_unit_to_num=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick or self.y_min, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if self.y_labeled_nums: y_axis.add_numbers(*self.y_labeled_nums) y_axis.numbers.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to(y_axis.get_top(), RIGHT, buff=2 * MED_BUFF) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = x_axis, y_axis self.default_graph_colors = it.cycle(self.default_graph_colors)
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 write_vector_coordinates(self, vector, **kwargs): coords = vector_coordinate_label(vector, **kwargs) self.play(Write(coords)) return coords
def setup_axes(self, animate = False): x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width/x_num_range if self.x_labeled_nums is None: self.x_labeled_nums = np.arange( self.x_min, self.x_max, 2*self.x_tick_frequency ) x_axis = NumberLine( x_min = self.x_min, x_max = self.x_max, space_unit_to_num = self.space_unit_to_x, tick_frequency = self.x_tick_frequency, leftmost_tick = self.x_leftmost_tick or self.x_min, numbers_with_elongated_ticks = self.x_labeled_nums, color = self.axes_color ) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: x_axis.add_numbers(*filter( lambda x : x != 0, self.x_labeled_nums )) x_label = TextMobject(self.x_axis_label) x_label.next_to( x_axis.get_tick_marks(), UP+RIGHT, buff = SMALL_BUFF ) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height/y_num_range if self.y_labeled_nums is None: self.y_labeled_nums = np.arange( self.y_min, self.y_max, 2*self.y_tick_frequency ) y_axis = NumberLine( x_min = self.y_min, x_max = self.y_max, space_unit_to_num = self.space_unit_to_y, tick_frequency = self.y_tick_frequency, leftmost_tick = self.y_bottom_tick or self.y_min, numbers_with_elongated_ticks = self.y_labeled_nums, color = self.axes_color ) y_axis.shift(self.graph_origin-y_axis.number_to_point(0)) y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: y_axis.add_numbers(*filter( lambda y : y != 0, self.y_labeled_nums )) for mob in y_axis.numbers: mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF) mob.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to( y_axis.get_tick_marks(), UP+RIGHT, buff = SMALL_BUFF ) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = x_axis, y_axis self.default_graph_colors = it.cycle(self.default_graph_colors)
def label_vector(self, vector, label, animate=True, **kwargs): label = self.get_vector_label(vector, label, **kwargs) if animate: self.play(Write(label, run_time=1)) self.add(label) return label