def construct(self): eq1_text = "4 x + 3 y = 0".split() eq2_text = "5 x - 2 y = 3".split() eq1_mob = TexMobject(*eq1_text) eq2_mob = TexMobject(*eq2_text) color_map = {"x": RED_B, "y": GREEN_C} eq1_mob.set_color_by_tex_to_color_map(color_map) eq2_mob.set_color_by_tex_to_color_map(color_map) for eq1_item, eq2_item in zip(eq1_mob, eq2_mob): eq2_item.align_to(eq1_item, LEFT) eq1 = VGroup(*eq1_mob) eq2 = VGroup(*eq2_mob) eq2.shift(DOWN) eq_group = VGroup(eq1, eq2) braces = Brace(eq_group, LEFT) eq_text = braces.get_text("A pair of equations") self.play(Write(eq_text)) self.play(GrowFromCenter(braces)) self.play(Write(eq1), Write(eq2)) self.wait(2)
def vector_to_coords(self, vector, integer_labels=True, clean_up=True): """ This method displays vector as a Vector() based vector, and then shows the corresponding lines that make up the x and y components of the vector. Then, a column matrix (henceforth called the label) is created near the head of the Vector. Parameters ---------- vector Union(np.ndarray, list, tuple) The vector to show. integer_label (bool=True) Whether or not to round the value displayed. in the vector's label to the nearest integer clean_up (bool=True) Whether or not to remove whatever this method did after it's done. """ 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.set_color(X_COLOR) y_line.set_color(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.wait() self.play( Transform(x_coord_start, x_coord, lag_ratio=0), Transform(y_coord_start, y_coord, lag_ratio=0), Write(brackets, run_time=1), ) self.wait() 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): eq1 = TextMobject(r"$ \vec{X}_0 \cdot \vec{Y}_1 = 3 $") eq1.shift(2 * UP) eq2 = TexMobject(r"\vec{F}_{net} = \sum_i \vec{F}_i") eq2.shift(2 * DOWN) self.play(Write(eq1)) self.play(Write(eq2)) self.wait()
def proof_part_1(self): proof_text, paint_text, and_text, perspective_text = self.proof_texts self.play(Write(proof_text), run_time=1) self.wait(4) self.play(Write(paint_text), run_time=1) self.wait(3) self.play(FadeIn(self.imagine_3d_text), run_time=1) self.wait(6) self.play(FadeOut(self.imagine_3d_text), run_time=1) self.wait() self.play(Write(VGroup(and_text, perspective_text), run_time=1)) self.wait()
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.set_color(X_COLOR) y_line.set_color(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.wait() self.play( Transform(x_coord_start, x_coord, lag_ratio=0), Transform(y_coord_start, y_coord, lag_ratio=0), Write(brackets, run_time=1), ) self.wait() 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 show_rhombi(self): self.wait() rhombi = VGroup( *[RhombusType() for RhombusType in (RRhombus, HRhombus, LRhombus)]) rhombi.arrange_submobjects(RIGHT, aligned_edge=DOWN, buff=1) rhombi.to_edge(RIGHT, buff=1) rhombi.to_edge(UP) hexagon_text, rhombi_text = self.bg_texts[0] self.play(Write(hexagon_text), run_time=1) self.wait() self.play(ShowCreation(rhombi, submobject_mode="all_at_once"), Write(rhombi_text), run_time=1) self.wait() self.rhombi = rhombi
def construct(self): eq1a = TextMobject("4x + 3y") eq1b = TextMobject("=") eq1c = TextMobject("0") eq2a = TextMobject("5x - 2y") eq2b = TextMobject("=") eq2c = TextMobject("3") eq1b.next_to(eq1a, RIGHT) eq1c.next_to(eq1b, RIGHT) eq2a.shift(DOWN) eq2b.shift(DOWN) eq2c.shift(DOWN) eq2a.align_to(eq1a, LEFT) eq2b.align_to(eq1b, LEFT) eq2c.align_to(eq1c, LEFT) eq_group = VGroup(eq1a, eq2a) braces = Brace(eq_group, LEFT) eq_text = braces.get_text("A pair of equations") self.add(eq1a, eq1b, eq1c) self.add(eq2a, eq2b, eq2c) self.play(GrowFromCenter(braces), Write(eq_text)) self.wait(3)
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 show_counter(self): counters = VGroup( *[rhombus.get_counter_tex() for rhombus in self.rhombi]) three_types_text = self.bg_texts[2] try_tiling_text, remark = self.bg_texts[3] self.play(FadeOut(self.reflines), ApplyMethod(self.rhombi.set_fill, None, 1), Write(three_types_text), run_time=2) self.wait() self.play(Write(try_tiling_text), run_time=2) self.play(Write(remark), run_time=1) self.wait() self.play(FadeIn(counters), run_time=1) self.wait(4) self.counters = counters
def add_T_label(self, x_val, side=RIGHT, label=None, color=WHITE, animated=False, **kwargs): """ This method adds to the Scene: -- a Vertical line from the x-axis to the corresponding point on the graph/curve. -- a small vertical Triangle whose top point lies on the base of the vertical line -- a TexMobject to be a label for the Line and Triangle, at the bottom of the Triangle. The scene needs to have the graph have the identifier/variable name self.v_graph. Parameters ---------- x_val (Union[float, int]) The x value at which the secant enters, and intersects the graph for the first time. side (np.ndarray()) label (str) The label to give the vertline and triangle color (str) The hex color of the label. animated (bool=False) Whether or not to animate the addition of the T_label **kwargs Any valid keyword argument of a self.play call. """ triangle = RegularPolygon(n=3, start_angle=np.pi / 2) triangle.set_height(MED_SMALL_BUFF) triangle.move_to(self.coords_to_point(x_val, 0), UP) triangle.set_fill(color, 1) triangle.set_stroke(width=0) if label is None: T_label = TexMobject(self.variable_point_label, fill_color=color) else: T_label = TexMobject(label, fill_color=color) T_label.next_to(triangle, DOWN) v_line = self.get_vertical_line_to_graph( x_val, self.v_graph, color=YELLOW ) if animated: self.play( DrawBorderThenFill(triangle), ShowCreation(v_line), Write(T_label, run_time=1), **kwargs ) if np.all(side == LEFT): self.left_T_label_group = VGroup(T_label, triangle) self.left_v_line = v_line self.add(self.left_T_label_group, self.left_v_line) elif np.all(side == RIGHT): self.right_T_label_group = VGroup(T_label, triangle) self.right_v_line = v_line self.add(self.right_T_label_group, self.right_v_line)
def construct(self): # Generate transformation animations of the twin dragon curve anims = list() fractal = VMobject() fractal.shift(UP) for order in range(-1, self.max_order+1): new_fractal = TwinDragon(order = order) new_fractal.shift(UP) run_time = 0.5 if order >= 0 else 0 anims.append( Transform( fractal, new_fractal, submobject_mode = "all_at_once", run_time = run_time, ) ) fractal = new_fractal # Add the channel name text = TextMobject("Solara570") text.scale(2).to_edge(DOWN, buff = 1.2) # Now sit back and watch self.play( Succession(*anims, rate_func = smooth), Write(text, lag_factor = 2.5, rate_func = squish_rate_func(smooth, 0.1, 0.9)), run_time = 4.5, )
def tex(self, latex): eq = TextMobject(latex) anims = [] anims.append(Write(eq)) for mobject in self.mobjects: anims.append(ApplyMethod(mobject.shift, 2 * UP)) self.play(*anims)
def add_T_label(self, x_val, side=RIGHT, label=None, color=WHITE, animated=False, **kwargs): triangle = RegularPolygon(n=3, start_angle=np.pi / 2) triangle.set_height(MED_SMALL_BUFF) triangle.move_to(self.coords_to_point(x_val, 0), UP) triangle.set_fill(color, 1) triangle.set_stroke(width=0) if label is None: T_label = TexMobject(self.variable_point_label, fill_color=color) else: T_label = TexMobject(label, fill_color=color) T_label.next_to(triangle, DOWN) v_line = self.get_vertical_line_to_graph(x_val, self.v_graph, color=YELLOW) if animated: self.play(DrawBorderThenFill(triangle), ShowCreation(v_line), Write(T_label, run_time=1), **kwargs) if np.all(side == LEFT): self.left_T_label_group = VGroup(T_label, triangle) self.left_v_line = v_line self.add(self.left_T_label_group, self.left_v_line) elif np.all(side == RIGHT): self.right_T_label_group = VGroup(T_label, triangle) self.right_v_line = v_line self.add(self.right_T_label_group, self.right_v_line)
def write_vector_coordinates(self, vector, **kwargs): """ Returns a column matrix indicating the vector coordinates, after writing them to the screen. Parameters ---------- vector (Arrow) The arrow representing the vector. **kwargs Any valid keyword arguments of matrix.vector_coordinate_label integer_labels (True) : Whether or not to round the coordinates to integers. n_dim (2) : The number of dimensions of the vector. color (WHITE) : The color of the label. Returns ------- Matrix The column matrix representing the vector. """ coords = vector_coordinate_label(vector, **kwargs) self.play(Write(coords)) return coords
def label_vector(self, vector, label, animate=True, **kwargs): """ Shortcut method for creating, and animating the addition of a label for the vector. Parameters ---------- vector (Vector) The vector for which the label must be added. label (TexMobject,str) The TexMobject/string of the label. animate (bool=True) Whether or not to animate the labelling w/ Write **kwargs Any valid keyword argument of get_vector_label Returns ------- TexMobject The TexMobject of the label. """ label = self.get_vector_label(vector, label, **kwargs) if animate: self.play(Write(label, run_time=1)) self.add(label) return label
def coords_to_vector(self, vector, coords_start=2 * RIGHT + 2 * UP, clean_up=True): starting_mobjects = list(self.submobjects) 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.set_color(X_COLOR) y_line.set_color(Y_COLOR) x_coord, y_coord = array.get_mob_matrix().flatten() self.play(Write(array, run_time=1)) self.wait() 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.wait() if clean_up: self.clear() self.add(*starting_mobjects)
def construct(self): logo = self.logo name = self.channel_name self.play(Write(name, run_time=3, lag_factor=2.5), *self.get_logo_animations(logo)) self.wait()
def add_title(self, title, scale_factor=1.5, animate=False): """ Adds a title, after scaling it, adding a background rectangle, moving it to the top and adding it to foreground_mobjects adding it as a local variable of self. Returns the Scene. Parameters ---------- title (str,TexMobject,TextMobject) What the title should be. scale_factor (int,float=1.5) How much the title should be scaled by. animate (bool=False) Whether or not to animate the addition. Returns ------- LinearTransformationScene The scene with the title added to it. """ 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): self.quote = self.get_quote() self.author = self.get_author(self.quote) self.play(FadeIn(self.quote, **self.fade_in_kwargs)) self.wait(2) self.play(Write(self.author, run_time=3)) self.wait()
def reback_or_anim_axis(self, reback, animate, *args): if reback: if self.add_coordinate_grid: return VGroup(self.lines_x_axis, self.lines_y_axis, self.x_axis, self.y_axis, *args) else: return VGroup(self.x_axis, self.y_axis, *args) else: if self.add_coordinate_grid: if animate: self.play(Write(VGroup(self.lines_x_axis, self.lines_y_axis, self.x_axis, self.y_axis, *args))) else: self.add(self.lines_x_axis, self.lines_y_axis, self.x_axis, self.y_axis, *args) else: if animate: self.play(Write(VGroup(self.x_axis, self.y_axis, *args))) else: self.add(self.x_axis, self.y_axis, *args)
def construct(self): t1 = TextMobject('Rangers') t2 = TextMobject('I am Rangers\' father').scale(2) self.add(t1) self.wait() self.play(MagicalMove(t1, t2)) self.play(Write(t2)) self.wait()
def proof_part_2(self): self.play(DrawBorderThenFill(self.rhombi, submobject_mode="all_at_once"), run_time=2) self.wait() self.wait(12) self.play(Write(self.time_texts), run_time=3) self.wait() source_texts = VGroup(*[texts[1] for texts in self.time_texts]) target_texts = VGroup(*self.conclusions[0][::2]) equal_signs = VGroup(self.conclusions[0][1::2]) qed = self.conclusions[1] self.play(Transform(source_texts.copy(), target_texts), Write(equal_signs), run_time=2) self.wait() self.play(FadeIn(qed)) self.wait(2)
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(title) self.title = title return self
def coords_to_vector(self, vector, coords_start=2 * RIGHT + 2 * UP, clean_up=True): """ This method writes the vector as a column matrix (henceforth called the label), takes the values in it one by one, and form the corresponding lines that make up the x and y components of the vector. Then, an Vector() based vector is created between the lines on the Screen. Parameters ---------- vector Union(np.ndarray, list, tuple) The vector to show. coords_start Union(np.ndarray,list,tuple) The starting point of the location of the label of the vector that shows it numerically. Defaults to 2 * RIGHT + 2 * UP or (2,2) clean_up (bool=True) Whether or not to remove whatever this method did after it's done. """ 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.set_color(X_COLOR) y_line.set_color(Y_COLOR) x_coord, y_coord = array.get_mob_matrix().flatten() self.play(Write(array, run_time=1)) self.wait() 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.wait() if clean_up: self.clear() self.add(*starting_mobjects)
def construct(self): line1 = TextMobject(r"The vector $\vec{F}_{net}$ is the net ", "force", " on object of mass ") line1.set_color_by_tex("force", BLUE) line2 = TextMobject("$m$", " and acceleration ", r"$\vec{a}$", ".") line2.set_color_by_tex_to_color_map({"m": YELLOW, "{a}": RED}) sentence = VGroup(line1, line2) sentence.arrange_submobjects(DOWN, buff=MED_LARGE_BUFF) self.play(Write(sentence)) self.wait(3)
def show_reflines(self): reflines = VGroup(*[rhombus.get_refline() for rhombus in self.rhombi]) eqtri_text = self.bg_texts[1] self.play(Write(eqtri_text), ShowCreation(reflines), Animation(self.rhombi), run_time=3) self.play( Indicate(VGroup(self.rhombi, reflines), scale_factor=1.05), run_time=2, ) self.wait() self.reflines = reflines
def construct(self): line1 = TexMobject( r"\text{The vector } \vec{F}_{net} \text{ is the net }", r"\text{force}", r"\text{ on object of mass }") line1.set_color_by_tex("force", BLUE) line2 = TexMobject("m", r"\text{ and acceleration }", r"\vec{a}", ".") line2.set_color_by_tex_to_color_map({"m": YELLOW, "{a}": RED}) sentence = VGroup(line1, line2) sentence.arrange_submobjects(DOWN, buff=MED_LARGE_BUFF) self.play(Write(sentence)) self.wait(3)
def show_claim(self): lhs, equal, rhs = claim = TexMobject( "\\prod_{r=1}^{+\\infty}{\\sum_{k=0}^{+\\infty}{f(p_r^k)}", "=", "\\sum_{n=1}^{+\\infty}{f(n)}") claim.scale(1.2) claim.to_edge(UP) lhs.set_color(GREEN) rhs.set_color(BLUE) prod_tex_rect = SurroundingRectangle(self.prod_tex, color=GREEN) sum_tex_rect = SurroundingRectangle(self.sum_tex, color=BLUE) self.play( ShowCreationThenDestruction(prod_tex_rect), Write(lhs), run_time=2, ) self.play( ShowCreationThenDestruction(sum_tex_rect), Write(rhs), run_time=2, ) self.play(Write(equal)) self.wait(3)
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 ask_about_how_to_prove(self): claim_text = self.q_texts[0] self.wait() self.play(self.q_texts.shift, DOWN, run_time=1) claim_rect = SurroundingRectangle(VGroup(claim_text, self.how_to_prove_text), stroke_color=YELLOW, buff=0.3) self.play( Write(self.how_to_prove_text), ShowCreation(claim_rect), run_time=1, ) self.wait() self.claim_rect = claim_rect