def get_vector_label(self, vector, label, direction="left", rotate=False, color=None, label_scale_factor=VECTOR_LABEL_SCALE_FACTOR): if not isinstance(label, TexMobject): if len(label) == 1: label = "\\vec{\\textbf{%s}}" % label label = TexMobject(label) if color is None: color = vector.get_color() label.highlight(color) label.scale(label_scale_factor) label.add_background_rectangle() angle = vector.get_angle() if not rotate: label.rotate(-angle) if direction is "left": label.shift(-label.get_bottom() + 0.1 * UP) else: label.shift(-label.get_top() + 0.1 * DOWN) label.rotate(angle) label.shift((vector.get_end() - vector.get_start()) / 2) return label
def mention_squaring_it(self): morty = self.pi_creature arrow = Arrow(self.plane.coords_to_point(2, 1), self.plane.coords_to_point(3, 4), path_arc=np.pi / 3, color=MAROON_B) square_label = TexMobject("z \\to z^2") square_label.highlight(arrow.get_color()) square_label.add_background_rectangle() square_label.next_to(arrow.point_from_proportion(0.5), RIGHT, buff=SMALL_BUFF) self.play(FadeIn(morty)) self.play( PiCreatureSays( morty, "Try squaring \\\\ it!", target_mode="hooray", bubble_kwargs={ "width": 4, "height": 3 }, )) self.play(ShowCreation(arrow), Write(square_label)) self.dither() self.play( RemovePiCreatureBubble(morty, target_mode="pondering", look_at_arg=self.example_label))
def add_plane(self): plane = ComplexPlane( unit_size=self.unit_size, center_point=self.plane_center, stroke_width=2, ) plane.axes.set_stroke(width=4) coordinate_labels = VGroup() for x in self.x_label_range: if x == 0: continue coord = TexMobject(str(x)) coord.scale(0.75) coord.next_to(plane.coords_to_point(x, 0), DOWN, SMALL_BUFF) coord.add_background_rectangle() coordinate_labels.add(coord) for y in self.y_label_range: if y == 0: continue coord = TexMobject("%di" % y) coord.scale(0.75) coord.next_to(plane.coords_to_point(0, y), LEFT, SMALL_BUFF) coord.add_background_rectangle() coordinate_labels.add(coord) self.add(plane, coordinate_labels) self.plane = plane self.plane.coordinate_labels = coordinate_labels
def get_coordinate_labels(self, *numbers): result = VGroup() nudge = 0.1 * (DOWN + RIGHT) if len(numbers) == 0: numbers = range(-int(self.x_radius), int(self.x_radius) + 1) numbers += [ complex(0, y) for y in range(-int(self.y_radius), int(self.y_radius) + 1) ] for number in numbers: point = self.number_to_point(number) num_str = str(number).replace("j", "i") if num_str.startswith("0"): num_str = "0" elif num_str in ["1i", "-1i"]: num_str = num_str.replace("1", "") num_mob = TexMobject(num_str) num_mob.add_background_rectangle() num_mob.scale(self.number_scale_factor) if complex(number).imag != 0: vect = DOWN + RIGHT else: vect = DOWN + RIGHT num_mob.next_to(point, vect, SMALL_BUFF) result.add(num_mob) return result
def get_matrices(self): m1_mob = Matrix(np.array(self.t_matrix1).transpose()) m2_mob = Matrix(np.array(self.t_matrix2).transpose()) comp_matrix = Matrix([["?", "?"], ["?", "?"]]) m1_mob.highlight(YELLOW) m2_mob.highlight(PINK) comp_matrix.get_entries().submobject_gradient_highlight(YELLOW, PINK) equals = TexMobject("=") equals.next_to(comp_matrix, LEFT) comp_matrix.add(equals) m1_mob = VMobject(BackgroundRectangle(m1_mob), m1_mob) m2_mob = VMobject(BackgroundRectangle(m2_mob), m2_mob) comp_matrix = VMobject(BackgroundRectangle(comp_matrix), comp_matrix) VMobject(m2_mob, m1_mob, comp_matrix).arrange_submobjects( buff=0.1).to_corner(UP + LEFT).shift(DOWN) for i, mob in enumerate([m1_mob, m2_mob]): brace = Brace(mob, UP) text = TexMobject("M_%d" % (i + 1)) text.next_to(brace, UP) brace.add_background_rectangle() text.add_background_rectangle() brace.add(text) mob.label = brace return m1_mob, m2_mob, comp_matrix
def add_point(self): point = self.plane.coords_to_point(3, 2) dot = Dot(point, color=self.dot_color) line = Line(self.plane.get_center_point(), point) line.highlight(dot.get_color()) number_label = TexMobject("3+2i") number_label.add_background_rectangle() number_label.next_to(dot, RIGHT, SMALL_BUFF) distance_labels = VGroup() for tex in "3^2 + 2^2", "13": pre_label = TexMobject("\\sqrt{%s}" % tex) label = VGroup( BackgroundRectangle(pre_label), VGroup(*pre_label[:2]), VGroup(*pre_label[2:]), ) label.scale(0.75) label.next_to(line.get_center(), UP, SMALL_BUFF) label.rotate(line.get_angle(), about_point=line.get_center()) distance_labels.add(label) self.play(FadeIn(number_label), ShowCreation(line), DrawBorderThenFill(dot)) self.play(Write(distance_labels[0])) self.dither() self.play(ReplacementTransform(*distance_labels)) self.dither() self.distance_label = distance_labels[1] self.line = line self.dot = dot self.number_label = number_label
def get_vector_label(self, vector, label, direction = "left", rotate = False, color = None, label_scale_factor = VECTOR_LABEL_SCALE_FACTOR): if not isinstance(label, TexMobject): if len(label) == 1: label = "\\vec{\\textbf{%s}}"%label label = TexMobject(label) if color is None: color = vector.get_color() label.highlight(color) label.scale(label_scale_factor) label.add_background_rectangle() angle = vector.get_angle() if not rotate: label.rotate(-angle) if direction is "left": label.shift(-label.get_bottom() + 0.1*UP) else: label.shift(-label.get_top() + 0.1*DOWN) label.rotate(angle) label.shift((vector.get_end() - vector.get_start())/2) return label
def construct(self): self.setup() symbols = TexMobject(list(self.symbols_str)) symbols.scale(1.5) symbols.to_edge(UP) a, b, c = None, None, None for mob, letter in zip(symbols.split(), self.symbols_str): if letter == "A": a = mob elif letter == "B": b = mob elif letter == "C": c = mob symbols.add_background_rectangle() self.add_foreground_mobject(symbols) brace = Brace(c, DOWN) words = TextMobject("Apply this transformation") words.add_background_rectangle() words.next_to(brace, DOWN) brace.add(words) self.play(Write(brace, run_time=1)) self.add_foreground_mobject(brace) last = VectorizedPoint() for t_matrix, sym in zip(self.t_matrices, [c, b, a]): self.play(brace.next_to, sym, DOWN, sym.highlight, YELLOW, last.highlight, WHITE) self.apply_transposed_matrix(t_matrix, run_time=1) last = sym self.wait()
def construct(self): v_tex = "\\vec{\\textbf{v}}" eq = TexMobject("A", v_tex, "=", "\\lambda", v_tex) eq.highlight_by_tex(v_tex, YELLOW) eq.highlight_by_tex("\\lambda", MAROON_B) eq.scale(3) eq.add_background_rectangle() eq.shift(2 * DOWN) title = TextMobject("Eigen", "vectors \\\\", "Eigen", "values", arg_separator="") title.scale(2.5) title.to_edge(UP) # title.highlight_by_tex("Eigen", MAROON_B) title[0].highlight(YELLOW) title[2].highlight(MAROON_B) title.add_background_rectangle() self.add_vector([-1, 1], color=YELLOW, animate=False) self.apply_transposed_matrix([[3, 0], [1, 2]]) self.plane.fade() self.remove(self.j_hat) self.add(eq, title)
def get_cosine_second_derivative(self): if not hasattr(self, "cosine_derivative"): self.get_cosine_derivative() second_deriv = TexMobject( "{d^2(", "\\cos", ")", "\\over", "dx}", "(", "0", ")", ) second_deriv.highlight_by_tex("cos", self.colors[0]) second_deriv.highlight_by_tex("-\\cos", self.colors[2]) second_deriv.scale(0.75) second_deriv.add_background_rectangle() second_deriv.next_to( self.cosine_derivative, DOWN, buff = MED_LARGE_BUFF, aligned_edge = LEFT ) rhs = TexMobject("=", "-\\cos(0)", "=", "-1") rhs.highlight_by_tex("cos", self.colors[2]) rhs.scale(0.8) rhs.next_to( second_deriv, RIGHT, align_using_submobjects = True ) self.cosine_second_derivative = VGroup(second_deriv, rhs) return self.cosine_second_derivative
def get_matrices(self): m1_mob = Matrix(np.array(self.t_matrix1).transpose()) m2_mob = Matrix(np.array(self.t_matrix2).transpose()) comp_matrix = Matrix([["?", "?"], ["?", "?"]]) m1_mob.highlight(YELLOW) m2_mob.highlight(PINK) comp_matrix.get_entries().submobject_gradient_highlight(YELLOW, PINK) equals = TexMobject("=") equals.next_to(comp_matrix, LEFT) comp_matrix.add(equals) m1_mob = VMobject(BackgroundRectangle(m1_mob), m1_mob) m2_mob = VMobject(BackgroundRectangle(m2_mob), m2_mob) comp_matrix = VMobject(BackgroundRectangle(comp_matrix), comp_matrix) VMobject( m2_mob, m1_mob, comp_matrix ).arrange_submobjects(buff = 0.1).to_corner(UP+LEFT).shift(DOWN) for i, mob in enumerate([m1_mob, m2_mob]): brace = Brace(mob, UP) text = TexMobject("M_%d"%(i+1)) text.next_to(brace, UP) brace.add_background_rectangle() text.add_background_rectangle() brace.add(text) mob.label = brace return m1_mob, m2_mob, comp_matrix
def view_as_complex_number(self): imag_coords = VGroup() for y in range(-4, 5, 2): if y == 0: continue label = TexMobject("%di" % y) label.add_background_rectangle() label.scale(0.75) label.next_to(self.plane.coords_to_point(0, y), LEFT, SMALL_BUFF) imag_coords.add(label) tuple_label = self.example_tuple_label new_label = TexMobject("2+i") new_label.add_background_rectangle() new_label.next_to( self.example_dot, DOWN + RIGHT, buff=0, ) self.play(Write(imag_coords)) self.dither() self.play(FadeOut(tuple_label)) self.play(FadeIn(new_label)) self.dither(2) self.example_label = new_label self.plane.coordinate_labels.add(*imag_coords)
def construct(self): v_tex = "\\vec{\\textbf{v}}" eq = TexMobject("A", v_tex, "=", "\\lambda", v_tex) eq.highlight_by_tex(v_tex, YELLOW) eq.highlight_by_tex("\\lambda", MAROON_B) eq.scale(3) eq.add_background_rectangle() eq.shift(2*DOWN) title = TextMobject( "Eigen", "vectors \\\\", "Eigen", "values" , arg_separator = "") title.scale(2.5) title.to_edge(UP) # title.highlight_by_tex("Eigen", MAROON_B) title[0].highlight(YELLOW) title[2].highlight(MAROON_B) title.add_background_rectangle() self.add_vector([-1, 1], color = YELLOW, animate = False) self.apply_transposed_matrix([[3, 0], [1, 2]]) self.plane.fade() self.remove(self.j_hat) self.add(eq, title)
def get_coordinate_labels(self, *numbers): # TODO: Should merge this with the code from NumberPlane.get_coordinate_labels result = VGroup() nudge = 0.1*(DOWN+RIGHT) if len(numbers) == 0: numbers = range(-int(self.x_radius), int(self.x_radius)+1) numbers += [ complex(0, y) for y in range(-int(self.y_radius), int(self.y_radius)+1) ] for number in numbers: if number == complex(0, 0): continue point = self.number_to_point(number) num_str = str(number).replace("j", "i") if num_str.startswith("0"): num_str = "0" elif num_str in ["1i", "-1i"]: num_str = num_str.replace("1", "") num_mob = TexMobject(num_str) num_mob.add_background_rectangle() num_mob.scale_to_fit_height(self.written_coordinate_height) num_mob.next_to(point, DOWN+LEFT, SMALL_BUFF) result.add(num_mob) self.coordinate_labels = result return result
def get_axis_labels(self, x_label = "x", y_label = "y"): x_axis, y_axis = self.get_axes().split() quads = [ (x_axis, x_label, UP, RIGHT), (y_axis, y_label, RIGHT, UP), ] labels = VGroup() for axis, tex, vect, edge in quads: label = TexMobject(tex) label.add_background_rectangle() label.next_to(axis, vect) label.to_edge(edge) labels.add(label) self.axis_labels = labels return labels
def get_axis_labels(self, x_label = "x", y_label = "y"): x_axis, y_axis = self.get_axes().split() quads = [ (x_axis, x_label, UP, RIGHT), (y_axis, y_label, RIGHT, UP), ] labels = VGroup() for axis, tex, vect, edge in quads: label = TexMobject(tex) label.add_background_rectangle() label.next_to(axis, vect) label.to_edge(edge) labels.add(label) self.axis_labels = labels return labels
def construct(self): self.setup() self.add_unit_square() a, b, c, d = 3, 2, 3.5, 2 self.dither() self.apply_transposed_matrix([[a, 0], [0, 1]]) i_brace = Brace(self.i_hat, DOWN) width = TexMobject("a").scale(1.5) i_brace.put_at_tip(width) width.highlight(X_COLOR) width.add_background_rectangle() self.play(GrowFromCenter(i_brace), Write(width)) self.dither() self.apply_transposed_matrix([[1, 0], [0, d]]) side_brace = Brace(self.square, RIGHT) height = TexMobject("d").scale(1.5) side_brace.put_at_tip(height) height.highlight(Y_COLOR) height.add_background_rectangle() self.play(GrowFromCenter(side_brace), Write(height)) self.dither() self.apply_transposed_matrix( [[1, 0], [float(b)/d, 1]], added_anims = [ ApplyMethod(m.shift, b*RIGHT) for m in side_brace, height ] ) self.dither() self.play(*map(FadeOut, [i_brace, side_brace, width, height])) matrix1 = np.dot( [[a, b], [c, d]], np.linalg.inv([[a, b], [0, d]]) ) matrix2 = np.dot( [[a, b], [-c, d]], np.linalg.inv([[a, b], [c, d]]) ) self.apply_transposed_matrix(matrix1.transpose(), path_arc = 0) self.dither() self.apply_transposed_matrix(matrix2.transpose(), path_arc = 0) self.dither()
def construct(self): plane = NumberPlane(x_unit_size=3, y_unit_size=3) # plane.main_lines.fade(0.5) # plane.secondary_lines.fade(0.5) plane.fade(0.5) self.add(plane) circle = Circle(radius=3) circle.set_stroke(YELLOW, 2) self.add(circle) radius = Line(ORIGIN, circle.get_right()) arc = Arc(radius=0.5, angle=TAU, num_anchors=200) arc.highlight(GREEN) start_arc = arc.copy() theta = TexMobject("\\theta", "=") theta[0].match_color(arc) theta.add_background_rectangle() update_theta = ContinualUpdateFromFunc( theta, lambda m : m.shift( rotate_vector(0.9*RIGHT, radius.get_angle()/2) \ - m[1][0].get_center() ) ) angle = Integer(0, unit="^\\circ") update_angle = ContinualChangingDecimal( angle, lambda a: radius.get_angle() * (360 / TAU), position_update_func=lambda a: a.next_to(theta, RIGHT, SMALL_BUFF)) self.add(update_theta, update_angle) last_frac = 0 for frac in 1. / 4, 1. / 12, 3. / 8, 1. / 6, 5. / 6: self.play(Rotate(radius, angle=(frac - last_frac) * TAU, about_point=ORIGIN), UpdateFromAlphaFunc( arc, lambda m, a: m.pointwise_become_partial( start_arc, 0, interpolate(last_frac, frac, a))), run_time=3) last_frac = frac self.wait()
def get_coordinate_labels(self, x_vals=None, y_vals=None): result = [] if x_vals == None and y_vals == None: x_vals = range(-int(self.x_radius), int(self.x_radius)) y_vals = range(-int(self.y_radius), int(self.y_radius)) for index, vals in enumerate([x_vals, y_vals]): num_pair = [0, 0] for val in vals: if val == 0: continue num_pair[index] = val point = self.coords_to_point(*num_pair) num = TexMobject(str(val)) num.add_background_rectangle() num.scale_to_fit_height(self.written_coordinate_height) vect = DOWN if index == 0 else LEFT num.next_to(point, vect, buff=SMALL_BUFF) result.append(num) return result
def construct(self): r1, r2 = numbers = -3, 2 colors = GREEN, RED dot1, dot2 = dots = VGroup(*[Dot(color = c) for c in colors]) for dot, number in zip(dots, numbers): dot.move_to(number*RIGHT) pair_label = TexMobject("(", str(r1), ",", str(r2), ")") for number, color in zip(numbers, colors): pair_label.highlight_by_tex(str(number), color) pair_label.next_to(dots, UP, buff = 2) arrows = VGroup(*[ Arrow(pair_label[i], dot, color = dot.get_color()) for i, dot in zip([1, 3], dots) ]) two_d_point = Dot(r1*RIGHT + r2*UP, color = YELLOW) pair_label.add_background_rectangle() x_axis = NumberLine(color = BLUE) y_axis = NumberLine(color = BLUE) plane = NumberPlane().fade() self.add(x_axis, y_axis, dots, pair_label) self.play(ShowCreation(arrows, run_time = 2)) self.dither() self.play( pair_label.next_to, two_d_point, UP+LEFT, SMALL_BUFF, Rotate(y_axis, np.pi/2), Rotate(dot2, np.pi/2), FadeOut(arrows) ) lines = VGroup(*[ DashedLine(dot, two_d_point, color = dot.get_color()) for dot in dots ]) self.play(*map(ShowCreation, lines)) self.play(ShowCreation(two_d_point)) everything = VGroup(*self.get_mobjects()) self.play( FadeIn(plane), Animation(everything), Animation(dot2) ) self.dither()
def show_associated_triplet(self): arrow = Arrow(LEFT, RIGHT, color=GREEN) arrow.next_to(self.square_label, RIGHT) triple = TexMobject("0^2 + 8^2 = 8^2") for part, color in zip(triple[::3], SIDE_COLORS): part.highlight(color) triple.add_background_rectangle() triple.next_to(arrow, RIGHT) morty = Mortimer() morty.next_to(self.plane.coords_to_point(12, 0), UP) self.play(ShowCreation(arrow), FadeIn(morty)) self.play(Write(triple), morty.change, "raise_right_hand", triple) self.play(Blink(morty)) self.play(morty.change, "tired") self.dither(2) self.play(Blink(morty)) self.dither()
def get_coordinate_labels(self, x_vals=None, y_vals=None): coordinate_labels = VGroup() if x_vals == None: x_vals = range(-int(self.x_radius), int(self.x_radius) + 1) if y_vals == None: y_vals = range(-int(self.y_radius), int(self.y_radius) + 1) for index, vals in enumerate([x_vals, y_vals]): num_pair = [0, 0] for val in vals: if val == 0: continue num_pair[index] = val point = self.coords_to_point(*num_pair) num = TexMobject(str(val)) num.add_background_rectangle() num.scale_to_fit_height(self.written_coordinate_height) num.next_to(point, DOWN + LEFT, buff=SMALL_BUFF) coordinate_labels.add(num) self.coordinate_labels = coordinate_labels return coordinate_labels
def add_plane(self): plane = ComplexPlane( center_point=self.initial_plane_center, unit_size=self.initial_unit_size, stroke_width=2, secondary_line_ratio=0, ) plane.axes.set_stroke(width=4) plane.coordinate_labels = VGroup() for x in range(-8, 20, 2): if x == 0: continue label = TexMobject(str(x)) label.scale(0.5) label.add_background_rectangle(opacity=1) label.next_to(plane.coords_to_point(x, 0), DOWN, SMALL_BUFF) plane.coordinate_labels.add(label) self.add(plane, plane.coordinate_labels) self.plane = plane
def plot_result(self): result_label = self.final_line.copy() result_label.add_background_rectangle() point = self.plane.coords_to_point(5, 12) dot = Dot(point, color=GREEN) line = Line(self.plane.get_center_point(), point) line.highlight(dot.get_color()) distance_label = TexMobject("13") distance_label.add_background_rectangle() distance_label.next_to(line.get_center(), UP + LEFT, SMALL_BUFF) self.play(result_label.next_to, dot, UP + LEFT, SMALL_BUFF, Animation(self.final_line), DrawBorderThenFill(dot)) self.dither() self.play(*[ ReplacementTransform(m1.copy(), m2) for m1, m2 in [(self.line, line), (self.distance_label, distance_label)] ]) self.dither()
def get_coordinate_labels(self, x_vals = None, y_vals = None): result = [] if x_vals == None and y_vals == None: x_vals = range(-int(self.x_radius), int(self.x_radius)) y_vals = range(-int(self.y_radius), int(self.y_radius)) for index, vals in enumerate([x_vals, y_vals]): num_pair = [0, 0] for val in vals: if val == 0: continue num_pair[index] = val point = self.coords_to_point(*num_pair) num = TexMobject(str(val)) num.add_background_rectangle() num.scale_to_fit_height( self.written_coordinate_height ) vect = DOWN if index == 0 else LEFT num.next_to(point, vect, buff = SMALL_BUFF) result.append(num) return result
def show_whole_distance_examples(self): dot_tuple_groups = self.integer_distance_dot_tuple_groups for dot_tuple_group in dot_tuple_groups: dot, tuple_mob = dot_tuple_group p0 = self.plane.get_center_point() p1 = dot.get_center() triangle = Polygon( p0, p1[0] * RIGHT + p0[1] * UP, p1, stroke_width=0, fill_color=BLUE, fill_opacity=0.75, ) line = Line(p0, p1, color=dot.get_color()) a, b = self.plane.point_to_coords(p1) c = int(np.sqrt(a**2 + b**2)) hyp_label = TexMobject(str(c)) hyp_label.add_background_rectangle() hyp_label.next_to(triangle.get_center(), UP + LEFT, buff=SMALL_BUFF) line.add(hyp_label) dot_tuple_group.triangle = triangle dot_tuple_group.line = line group = dot_tuple_groups[0] self.play(Write(group.line)) self.play(FadeIn(group.triangle), Animation(group.line)) self.dither(2) for new_group in dot_tuple_groups[1:]: self.play( Transform(group, new_group), Transform(group.triangle, new_group.triangle), Transform(group.line, new_group.line), ) self.dither(2) self.play(*map(FadeOut, [group, group.triangle, group.line]))
def draw_triangle(self): hyp_length = TexMobject("u", "^2", "+", "v", "^2") hyp_length.highlight_by_tex("u", U_COLOR) hyp_length.highlight_by_tex("v", V_COLOR) hyp_length.add_background_rectangle() line = self.square_line hyp_length.next_to(line.get_center(), UP, SMALL_BUFF) hyp_length.rotate(line.get_angle(), about_point=line.get_center()) triangle = Polygon( ORIGIN, RIGHT, RIGHT + UP, stroke_width=0, fill_color=MAROON_B, fill_opacity=0.5, ) triangle.replace(line, stretch=True) self.play(Write(hyp_length)) self.dither() self.play(FadeIn(triangle)) self.dither()
def get_line_brace_text(self, func_name="sin"): line = self.get_trig_line(func_name) angle = line.get_angle() vect = rotate_vector(UP, angle) vect = np.round(vect, 1) if (vect[1] < 0) ^ (func_name is "sec"): vect = -vect angle += np.pi brace = Brace( Line( line.get_length() * LEFT / 2, line.get_length() * RIGHT / 2, ), UP) brace.rotate(angle) brace.shift(line.get_center()) brace.highlight(line.get_color()) text = TexMobject("\\%s(\\theta)" % func_name) text.scale(0.75) text[-2].highlight(self.theta_color) text.add_background_rectangle() text.next_to(brace.get_center_of_mass(), vect, buff=1.2 * MED_BUFF) return VGroup(line, brace, text)
def show_squaring(self): self.force_skipping() self.square_point() dot = self.example_dot old_label = self.example_label line = self.example_line square_dot = self.square_dot old_square_label = self.square_label square_line = self.square_line z_to_z_squared = self.z_to_z_squared arrow = self.z_to_z_squared_arrow result_length_label = self.result_length_label self.clear() self.add(self.plane, self.plane.coordinate_labels) self.revert_to_original_skipping_status() label = TexMobject("u+vi") label.move_to(old_label, LEFT) label.add_background_rectangle() square_label = TexMobject("(u+vi)^2") square_label.move_to(old_square_label, LEFT) square_label.add_background_rectangle() self.add(label, dot, line) self.play(ShowCreation(arrow), FadeIn(z_to_z_squared)) self.play(*[ ReplacementTransform( start.copy(), target, run_time=1.5, path_arc=np.pi / 2) for start, target in [ (dot, square_dot), (line, square_line), (label, square_label), ] ]) self.example_label = label self.square_label = square_label
def wander_over_lattice_points(self): initial_examples = [(5, 3), (6, 8), (2, 7)] integer_distance_examples = [(3, 4), (12, 5), (15, 8)] dot_tuple_groups = VGroup() for x, y in initial_examples + integer_distance_examples: dot = Dot( self.plane.coords_to_point(x, y), color=self.dot_color, radius=self.dot_radius, ) tuple_mob = TexMobject("(", str(x), ",", str(y), ")") tuple_mob.add_background_rectangle() tuple_mob.next_to(dot, UP + RIGHT, buff=0) dot_tuple_groups.add(VGroup(dot, tuple_mob)) dot_tuple_group = dot_tuple_groups[0] final_group = dot_tuple_groups[-len(integer_distance_examples)] all_dots = self.get_all_plane_dots() self.play(Write(dot_tuple_group, run_time=2)) self.dither() for new_group in dot_tuple_groups[1:len(initial_examples)]: self.play(Transform(dot_tuple_group, new_group)) self.dither() self.play( LaggedStart( FadeIn, all_dots, rate_func=there_and_back, run_time=3, lag_ratio=0.2, )) self.dither() self.play(ReplacementTransform(dot_tuple_group, final_group)) self.integer_distance_dot_tuple_groups = VGroup( *dot_tuple_groups[len(initial_examples):])
def construct(self): self.setup() self.add_unit_square() a, b, c, d = 3, 2, 3.5, 2 self.wait() self.apply_transposed_matrix([[a, 0], [0, 1]]) i_brace = Brace(self.i_hat, DOWN) width = TexMobject("a").scale(1.5) i_brace.put_at_tip(width) width.highlight(X_COLOR) width.add_background_rectangle() self.play(GrowFromCenter(i_brace), Write(width)) self.wait() self.apply_transposed_matrix([[1, 0], [0, d]]) side_brace = Brace(self.square, RIGHT) height = TexMobject("d").scale(1.5) side_brace.put_at_tip(height) height.highlight(Y_COLOR) height.add_background_rectangle() self.play(GrowFromCenter(side_brace), Write(height)) self.wait() self.apply_transposed_matrix([[1, 0], [float(b) / d, 1]], added_anims=[ ApplyMethod(m.shift, b * RIGHT) for m in side_brace, height ]) self.wait() self.play(*map(FadeOut, [i_brace, side_brace, width, height])) matrix1 = np.dot([[a, b], [c, d]], np.linalg.inv([[a, b], [0, d]])) matrix2 = np.dot([[a, b], [-c, d]], np.linalg.inv([[a, b], [c, d]])) self.apply_transposed_matrix(matrix1.transpose(), path_arc=0) self.wait() self.apply_transposed_matrix(matrix2.transpose(), path_arc=0) self.wait()
def get_line_brace_text(self, func_name = "sin"): line = self.get_trig_line(func_name) angle = line.get_angle() vect = rotate_vector(UP, angle) vect = np.round(vect, 1) if (vect[1] < 0) ^ (func_name is "sec"): vect = -vect angle += np.pi brace = Brace( Line( line.get_length()*LEFT/2, line.get_length()*RIGHT/2, ), UP ) brace.rotate(angle) brace.shift(line.get_center()) brace.highlight(line.get_color()) text = TexMobject("\\%s(\\theta)"%func_name) text.scale(0.75) text[-2].highlight(self.theta_color) text.add_background_rectangle() text.next_to(brace.get_center_of_mass(), vect, buff = 1.2*MED_SMALL_BUFF) return VGroup(line, brace, text)
def construct(self): num = TexMobject("2^{256}") num.scale_to_fit_height(2) num.highlight(BLUE_C) num.set_stroke(BLUE_B, 3) num.shift(MED_SMALL_BUFF * UP) num.add_background_rectangle(opacity=1) num.background_rectangle.scale_in_place(1.5) self.add(num) background_num_str = "115792089237316195423570985008687907853269984665640564039457584007913129639936" n_chars = len(background_num_str) new_str = "" for i, char in enumerate(background_num_str): new_str += char # if i%3 == 1: # new_str += "{,}" if i % (n_chars / 4) == 0: new_str += " \\\\ " background_num = TexMobject(new_str) background_num.scale_to_fit_width(2 * SPACE_WIDTH - LARGE_BUFF) background_num.set_fill(opacity=0.2) secure = TextMobject("Secure?") secure.scale(4) secure.shift(SPACE_HEIGHT * DOWN / 2) secure.highlight(RED) secure.set_stroke(RED_A, 3) lock = SVGMobject( file_name="shield_locked", fill_color=WHITE, ) lock.scale_to_fit_height(6) self.add(background_num, num)
def construct(self): self.setup() symbols = TexMobject(list(self.symbols_str)) symbols.scale(1.5) symbols.to_edge(UP) a, b, c = None, None, None for mob, letter in zip(symbols.split(), self.symbols_str): if letter == "A": a = mob elif letter == "B": b = mob elif letter == "C": c = mob symbols.add_background_rectangle() self.add_foreground_mobject(symbols) brace = Brace(c, DOWN) words = TextMobject("Apply this transformation") words.add_background_rectangle() words.next_to(brace, DOWN) brace.add(words) self.play(Write(brace, run_time = 1)) self.add_foreground_mobject(brace) last = VectorizedPoint() for t_matrix, sym in zip(self.t_matrices, [c, b, a]): self.play( brace.next_to, sym, DOWN, sym.highlight, YELLOW, last.highlight, WHITE ) self.apply_transposed_matrix(t_matrix, run_time = 1) last = sym self.dither()
def show_root_example(self): x, y = (2, 1) point = self.plane.coords_to_point(x, y) dot = Dot(point, color=self.dot_color, radius=self.dot_radius) tuple_label = TexMobject(str((x, y))) tuple_label.add_background_rectangle() tuple_label.next_to(dot, RIGHT, SMALL_BUFF) line = Line(self.plane.get_center_point(), point) line.highlight(dot.get_color()) distance_labels = VGroup() for tex in "2^2 + 1^2", "5": pre_label = TexMobject("\\sqrt{%s}" % tex) rect = BackgroundRectangle(pre_label) label = VGroup( rect, VGroup(*pre_label[:2]), VGroup(*pre_label[2:]), ) label.scale(0.8) label.next_to(line.get_center(), UP, SMALL_BUFF) label.rotate(line.get_angle(), about_point=line.get_center()) distance_labels.add(label) self.play(ShowCreation(line), DrawBorderThenFill(dot, stroke_width=3, stroke_color=PINK)) self.play(Write(tuple_label)) self.dither() self.play(FadeIn(distance_labels[0])) self.dither(2) self.play(Transform(*distance_labels)) self.dither(2) self.distance_label = distance_labels[0] self.example_dot = dot self.example_line = line self.example_tuple_label = tuple_label
def construct(self): self.plane.fade() v = Vector(self.v_coords, color=V_COLOR) w = Vector(self.w_coords, color=W_COLOR) v.coords = Matrix(self.v_coords) w.coords = Matrix(self.w_coords) v.coords.next_to(v.get_end(), LEFT) w.coords.next_to(w.get_end(), RIGHT) v.coords.highlight(v.get_color()) w.coords.highlight(w.get_color()) for coords in v.coords, w.coords: coords.background_rectangle = BackgroundRectangle(coords) coords.add_to_back(coords.background_rectangle) v.label = self.get_vector_label(v, "v", "left", color=v.get_color()) w.label = self.get_vector_label(w, "w", "right", color=w.get_color()) matrix = Matrix( np.array([ list(v.coords.copy().get_entries()), list(w.coords.copy().get_entries()), ]).T) matrix_background = BackgroundRectangle(matrix) col1, col2 = it.starmap(Group, matrix.get_mob_matrix().T) det_text = get_det_text(matrix) v_tex, w_tex = get_vect_tex("v", "w") cross_product = TexMobject(v_tex, "\\times", w_tex, "=") cross_product.highlight_by_tex(v_tex, V_COLOR) cross_product.highlight_by_tex(w_tex, W_COLOR) cross_product.add_background_rectangle() equation_start = Group(cross_product, Group(matrix_background, det_text, matrix)) equation_start.arrange_submobjects() equation_start.next_to(ORIGIN, DOWN).to_edge(LEFT) for vect in v, w: self.play(ShowCreation(vect), Write(vect.coords), Write(vect.label)) self.dither() self.play( Transform(v.coords.background_rectangle, matrix_background), Transform(w.coords.background_rectangle, matrix_background), Transform(v.coords.get_entries(), col1), Transform(w.coords.get_entries(), col2), Transform(v.coords.get_brackets(), matrix.get_brackets()), Transform(w.coords.get_brackets(), matrix.get_brackets()), ) self.play(*map(Write, [det_text, cross_product])) v1, v2 = v.coords.get_entries() w1, w2 = w.coords.get_entries() entries = v1, v2, w1, w2 for entry in entries: entry.target = entry.copy() det = np.linalg.det([self.v_coords, self.w_coords]) equals, dot1, minus, dot2, equals_result = syms = Group( *map(TexMobject, ["=", "\\cdot", "-", "\\cdot", "=%d" % det])) equation_end = Group(equals, v1.target, dot1, w2.target, minus, w1.target, dot2, v2.target, equals_result) equation_end.arrange_submobjects() equation_end.next_to(equation_start) syms_rect = BackgroundRectangle(syms) syms.add_to_back(syms_rect) equation_end.add_to_back(syms_rect) syms.remove(equals_result) self.play(Write(syms), Transform(Group(v1, w2).copy(), Group(v1.target, w2.target), rate_func=squish_rate_func(smooth, 0, 1. / 3), path_arc=np.pi / 2), Transform(Group(v2, w1).copy(), Group(v2.target, w1.target), rate_func=squish_rate_func(smooth, 2. / 3, 1), path_arc=np.pi / 2), run_time=3) self.dither() self.play(Write(equals_result)) self.add_foreground_mobject(equation_start, equation_end) self.show_transformation(v, w) det_sym = TexMobject(str(int(abs(det)))) det_sym.scale(1.5) det_sym.next_to(v.get_end() + w.get_end(), DOWN + RIGHT, buff=MED_BUFF / 2) arc = self.get_arc(v, w, radius=1) arc.highlight(RED) self.play(Write(det_sym)) self.play(ShowCreation(arc)) self.dither()
def square_point(self): z = self.number z_point = self.plane.number_to_point(z) zero_point = self.plane.number_to_point(0) dot = Dot(z_point, color=self.dot_color) line = Line(zero_point, z_point) line.highlight(dot.get_color()) label = TexMobject(complex_string_with_i(z)) label.add_background_rectangle() label.next_to(dot, RIGHT, SMALL_BUFF) square_point = self.plane.number_to_point(z**2) square_dot = Dot(square_point, color=self.square_color) square_line = Line(zero_point, square_point) square_line.highlight(square_dot.get_color()) square_label = TexMobject(complex_string_with_i(z**2)) square_label.add_background_rectangle() square_label.next_to(square_dot, UP + RIGHT, SMALL_BUFF) result_length_label = TexMobject(str(int(abs(z**2)))) result_length_label.next_to(square_line.get_center(), self.result_label_vect) result_length_label.add_background_rectangle() arrow = Arrow( z_point, square_point, # buff = SMALL_BUFF, path_arc=np.pi / 2) arrow.highlight(WHITE) z_to_z_squared = TexMobject("z", "\\to", "z^2") z_to_z_squared.highlight_by_tex("z", dot.get_color()) z_to_z_squared.highlight_by_tex("z^2", square_dot.get_color()) z_to_z_squared.next_to(arrow.point_from_proportion(0.5), RIGHT, MED_SMALL_BUFF) z_to_z_squared.add_to_back( BackgroundRectangle( VGroup(z_to_z_squared[2][0], *z_to_z_squared[:-1])), BackgroundRectangle(z_to_z_squared[2][1])) self.play(Write(label), ShowCreation(line), DrawBorderThenFill(dot)) self.dither() self.play( ShowCreation(arrow), FadeIn(z_to_z_squared), Animation(label), ) self.play(*[ ReplacementTransform( start.copy(), target, path_arc=np.pi / 2, run_time=1.5) for start, target in [ (dot, square_dot), (line, square_line), (label, square_label), ] ]) self.dither() self.play(Write(result_length_label)) self.dither() self.example_dot = dot self.example_label = label self.example_line = line self.square_dot = square_dot self.square_label = square_label self.square_line = square_line self.z_to_z_squared = z_to_z_squared self.z_to_z_squared_arrow = arrow self.result_length_label = result_length_label
def construct(self): self.setup_axes() func_graph = self.get_graph( self.function, self.function_color, ) approx_graphs = [ self.get_graph( taylor_approximation(self.function, n), self.approximation_color ) for n in self.order_sequence ] near_text = TextMobject( "Near %s $= %d$"%( self.x_axis_label, self.center_point ) ) near_text.to_corner(UP + RIGHT) near_text.add_background_rectangle() equation = TexMobject( self.function_tex, "\\approx", *self.approximation_terms ) equation.next_to(near_text, DOWN, MED_LARGE_BUFF) equation.to_edge(RIGHT) near_text.next_to(equation, UP, MED_LARGE_BUFF) equation.highlight_by_tex( self.function_tex, self.function_color, substring = False ) approx_terms = VGroup(*[ equation.get_part_by_tex(tex, substring = False) for tex in self.approximation_terms ]) approx_terms.set_fill( self.approximation_color, opacity = 0, ) equation.add_background_rectangle() approx_graph = VectorizedPoint( self.input_to_graph_point(self.center_point, func_graph) ) self.play( ShowCreation(func_graph, run_time = 2), Animation(equation), Animation(near_text), ) for graph, term in zip(approx_graphs, approx_terms): self.play( Transform(approx_graph, graph, run_time = 2), Animation(equation), Animation(near_text), term.set_fill, None, 1, ) self.dither() self.dither(2)