def add_polygons(self): a = self.i_hat.get_end()[0]*RIGHT b = self.j_hat.get_end()[0]*RIGHT c = self.i_hat.get_end()[1]*UP d = self.j_hat.get_end()[1]*UP shapes_colors_and_tex = [ (Polygon(ORIGIN, a, a+c), TEAL, "bd/2"), (Polygon(ORIGIN, d+b, d), TEAL, "\\dfrac{bd}{2}"), (Polygon(a+c, a+b+c, a+b+c+d), MAROON, "\\dfrac{ac}{2}"), (Polygon(b+d, a+b+c+d, b+c+d), MAROON, "ac/2"), (Polygon(a, a+b, a+b+c, a+c), PINK, "bc"), (Polygon(d, d+b, d+b+c, d+c), PINK, "bc"), ] everyone = VMobject() for shape, color, tex in shapes_colors_and_tex: shape.set_stroke(width = 0) shape.set_fill(color = color, opacity = 0.7) tex_mob = TexMobject(tex) tex_mob.scale(0.7) tex_mob.move_to(shape.get_center_of_mass()) everyone.add(shape, tex_mob) self.play(FadeIn( everyone, submobject_mode = "lagged_start", run_time = 1 ))
def intro_vector(self): plane = NumberPlane() labels = VMobject(*plane.get_coordinate_labels()) vector = Vector(RIGHT+2*UP, color = YELLOW) coordinates = vector_coordinate_label(vector) symbol = TexMobject("\\vec{\\textbf{v}}") symbol.shift(0.5*(RIGHT+UP)) self.play(ShowCreation( plane, submobject_mode = "lagged_start", run_time = 3 )) self.play(ShowCreation( vector, submobject_mode = "one_at_a_time" )) self.play( Write(labels), Write(coordinates), Write(symbol) ) self.dither(2) self.play( FadeOut(plane), FadeOut(labels), ApplyMethod(vector.shift, 4*LEFT+UP), ApplyMethod(coordinates.shift, 2.5*RIGHT+0.5*DOWN), ApplyMethod(symbol.shift, 0.5*(UP+LEFT)) ) self.remove(plane, labels) return vector, symbol, coordinates
def show_geometry(self, slider, vector): point_a = self.point_a.get_center() horiz_line = Line(point_a, point_a + 6*RIGHT) ceil_point = point_a ceil_point[0] = slider.get_center()[0] vert_brace = Brace( Mobject(Point(ceil_point), Point(slider.get_center())), RIGHT, buff = 0.5 ) vect_brace = Brace(slider) vect_brace.stretch_to_fit_width(vector.get_length()) vect_brace.rotate(np.arctan(vector.get_slope())) vect_brace.center().shift(vector.get_center()) nudge = 0.2*(DOWN+LEFT) vect_brace.shift(nudge) y_mob = TexMobject("y") y_mob.next_to(vert_brace) sqrt_y = TexMobject("k\\sqrt{y}") sqrt_y.scale(0.5) sqrt_y.shift(vect_brace.get_center()) sqrt_y.shift(3*nudge) self.play(ShowCreation(horiz_line)) self.play( GrowFromCenter(vert_brace), ShimmerIn(y_mob) ) self.play( GrowFromCenter(vect_brace), ShimmerIn(sqrt_y) ) self.dither(3) self.solve_energy()
def construct(self): matrix = Matrix([ [2, 0], [-1, 1], [-2, 1], ]) matrix.highlight_columns(X_COLOR, Y_COLOR) rows_brace = Brace(matrix, LEFT) rows_words = rows_brace.get_text("3", "rows") rows_words.highlight(PINK) cols_brace = Brace(matrix, UP) cols_words = cols_brace.get_text("2", "columns") cols_words.highlight(TEAL) title = TexMobject("3", "\\times", "2", "\\text{ matrix}") title.to_edge(UP) self.add(matrix) self.play( GrowFromCenter(rows_brace), Write(rows_words, run_time = 2) ) self.play( GrowFromCenter(cols_brace), Write(cols_words, run_time = 2) ) self.dither() self.play( rows_words[0].copy().move_to, title[0], cols_words[0].copy().move_to, title[2], Write(VMobject(title[1], title[3])) ) self.dither()
def specifics_concepts(self): matrix_vector_product = TexMobject(" ".join([ matrix_to_tex_string(EXAMPLE_TRANFORM), matrix_to_tex_string(TRANFORMED_VECTOR), "&=", matrix_to_tex_string([ ["1 \\cdot 1 + 0 \\cdot 2"], ["1 \\cdot 1 + (-1)\\cdot 2"] ]), "\\\\ &=", matrix_to_tex_string([[1], [-1]]), ])) matrix_vector_product.scale_to_fit_width(SPACE_WIDTH-0.5) matrix_vector_product.next_to(self.vline, LEFT) self.play( Write(self.numeric), FadeIn(matrix_vector_product), run_time = 2 ) self.dither() self.play(Write(self.geometric, run_time = 2)) ### Paste in linear transformation self.dither() digest_locals(self)
def construct(self): l_m1, l_m2, eq, r_m2, r_m1 = TexMobject([ "M_1", "M_2", "=", "M_2", "M_1" ]).scale(1.5).split() VMobject(l_m1, r_m1).highlight(YELLOW) VMobject(l_m2, r_m2).highlight(PINK) q_marks = TextMobject("???") q_marks.highlight(TEAL) q_marks.next_to(eq, UP) neq = TexMobject("\\neq") neq.move_to(eq) self.play(*map(Write, [l_m1, l_m2, eq])) self.play( Transform(l_m1.copy(), r_m1), Transform(l_m2.copy(), r_m2), path_arc = -np.pi, run_time = 2 ) self.play(Write(q_marks)) self.dither() self.play(Transform( VMobject(eq, q_marks), VMobject(neq), submobject_mode = "lagged_start" )) self.dither()
def side_project(self, morty): rect = PictureInPictureFrame() rect.next_to(morty, UP+LEFT) side_project = TextMobject("Side project") side_project.next_to(rect, UP) dollar_sign = TexMobject("\\$") cross = VGroup(*[ Line(vect, -vect, color = RED) for vect in UP+RIGHT, UP+LEFT ]) cross.scale_to_fit_height(dollar_sign.get_height()) no_money = VGroup(dollar_sign, cross) no_money.next_to(rect, DOWN) self.play( morty.change_mode, "raise_right_hand", morty.look_at, rect ) self.play( Write(side_project), ShowCreation(rect) ) self.dither() self.play(Blink(morty)) self.dither() self.play(Write(dollar_sign)) self.play(ShowCreation(cross)) self.screen_title = side_project self.cross = cross
def construct(self): point_a, point_b = 3*LEFT, 3*RIGHT dots = [] for point, char in [(point_a, "A"), (point_b, "B")]: dot = Dot(point) letter = TexMobject(char) letter.next_to(dot, UP+LEFT) dot.add(letter) dots.append(dot) path = ParametricFunction( lambda t : (t/2 + np.cos(t))*RIGHT + np.sin(t)*UP, start = -2*np.pi, end = 2*np.pi ) path.scale(6/(2*np.pi)) path.shift(point_a - path.points[0]) path.highlight(RED) line = Line(point_a, point_b) words = TextMobject("Shortest path from $A$ to $B$") words.to_edge(UP) self.play( ShimmerIn(words), *map(GrowFromCenter, dots) ) self.play(ShowCreation(path)) self.play(Transform( path, line, path_func = path_along_arc(np.pi) )) self.dither()
def generate_points(self): self.cell_height = self.height / self.nrows self.cell_width = self.width / self.nrows self.bottom_left = (self.cell_width * self.nrows / 2.0)*LEFT + \ (self.cell_height * self.nrows / 2.0)*DOWN num_to_num_mob = {} self.coords_to_mobs = {} self.coords = [ (n, k) for n in range(self.nrows) for k in range(n+1) ] for n, k in self.coords: num = choose(n, k) center = self.coords_to_center(n, k) num_mob = TexMobject(str(num)) scale_factor = min( 1, self.portion_to_fill * self.cell_height / num_mob.get_height(), self.portion_to_fill * self.cell_width / num_mob.get_width(), ) num_mob.center().scale(scale_factor).shift(center) if n not in self.coords_to_mobs: self.coords_to_mobs[n] = {} self.coords_to_mobs[n][k] = num_mob self.add(*[ self.coords_to_mobs[n][k] for n, k in self.coords ]) return self
def generate_points(self): start_angle = np.pi/2 + self.arc_angle/2 end_angle = np.pi/2 - self.arc_angle/2 self.add(Arc( start_angle = start_angle, angle = -self.arc_angle )) tick_angle_range = np.linspace(start_angle, end_angle, self.num_ticks) for index, angle in enumerate(tick_angle_range): vect = rotate_vector(RIGHT, angle) tick = Line((1-self.tick_length)*vect, vect) label = TexMobject(str(10*index)) label.scale_to_fit_height(self.tick_length) label.shift((1+self.tick_length)*vect) self.add(tick, label) needle = Polygon( LEFT, UP, RIGHT, stroke_width = 0, fill_opacity = 1, fill_color = self.needle_color ) needle.stretch_to_fit_width(self.needle_width) needle.stretch_to_fit_height(self.needle_height) needle.rotate(start_angle - np.pi/2) self.add(needle) self.needle = needle self.center_offset = self.get_center()
def construct(self): derivative = TexMobject( "\\frac{d(a^t)}{dt} =", "a^t \\ln(a)" ) derivative[0][3].highlight(YELLOW) derivative[1][1].highlight(YELLOW) derivative[0][2].highlight(BLUE) derivative[1][0].highlight(BLUE) derivative[1][5].highlight(BLUE) derivative.scale(3) # derivative.to_edge(UP) derivative.shift(DOWN) brace = Brace(Line(LEFT, RIGHT), UP) brace.scale_to_fit_width(derivative[1].get_width()) brace.next_to(derivative[1], UP) question = TextMobject("Why?") question.scale(2.5) question.next_to(brace, UP) # randy = Randolph() # randy.scale(1.3) # randy.next_to(ORIGIN, LEFT).to_edge(DOWN) # randy.change_mode("pondering") # question = TextMobject("What is $e\\,$?") # e = question[-2] # e.scale(1.2, about_point = e.get_bottom()) # e.highlight(BLUE) # question.scale(1.7) # question.next_to(randy, RIGHT, aligned_edge = UP) # question.shift(DOWN) # randy.look_at(question) self.add(derivative, brace, question)
def get_subdivision_braces_and_labels( self, parts, labels, direction, buff = SMALL_BUFF, min_num_quads = 1 ): label_mobs = VGroup() braces = VGroup() for label, part in zip(labels, parts): brace = Brace( part, direction, min_num_quads = min_num_quads, buff = buff ) if isinstance(label, Mobject): label_mob = label else: label_mob = TexMobject(label) label_mob.scale(self.default_label_scale_val) label_mob.next_to(brace, direction, buff) braces.add(brace) label_mobs.add(label_mob) parts.braces = braces parts.labels = label_mobs parts.label_kwargs = { "labels" : label_mobs.copy(), "direction" : direction, "buff" : buff, } return VGroup(parts.braces, parts.labels)
def construct(self): exp = TexMobject("x^y = z") log = TexMobject("\\log_x(z) = y") rad = TexMobject("\\sqrt[y]{z} = x") exp.to_edge(LEFT).shift(2*UP) rad.to_edge(RIGHT).shift(2*DOWN) x1, y1, eq, z1 = exp.split() l, o, g, x2, p, z2, p, eq, y2 = log.split() y3, r, r, z3, eq, x3 = rad.split() vars1 = VMobject(x1, y1, z1).copy() vars2 = VMobject(x2, y2, z2) vars3 = VMobject(x3, y3, z3) self.play(Write(exp)) self.play(Transform(vars1, vars2, path_arc = -np.pi)) self.play(Write(log)) self.play(Transform(vars1, vars3, path_arc = -np.pi)) self.play(Write(rad)) self.dither() words = TextMobject("Artificially unrelated") words.to_corner(UP+RIGHT) words.highlight(YELLOW) self.play(Write(words)) self.dither()
def show_derivative(self): deriv = TexMobject("\\frac{df}{dx}") deriv.next_to(self.graph_label, DOWN, MED_LARGE_BUFF) deriv.highlight(self.deriv_color) ss_group = self.get_secant_slope_group( 1, self.graph, dx = 0.01, secant_line_color = self.deriv_color ) self.play( Write(deriv), *map(ShowCreation, ss_group) ) self.animate_secant_slope_group_change( ss_group, target_x = self.x3, run_time = 5 ) self.dither() self.animate_secant_slope_group_change( ss_group, target_x = self.x2, run_time = 3 ) self.dither() self.ss_group = ss_group self.deriv = deriv
def construct(self): p_tex = "$%s$"%get_vect_tex("p") p_mob = TextMobject(p_tex) p_mob.scale(1.5) p_mob.highlight(P_COLOR) input_array = Matrix(list("xyz")) dot_product = Group(p_mob, Dot(radius = 0.07), input_array) dot_product.arrange_submobjects(buff = MED_BUFF/2) equals = TexMobject("=") dot_product.next_to(equals, LEFT) words = Group(*it.starmap(TextMobject, [ ("(Length of projection)",), ("(Length of ", p_tex, ")",) ])) times = TexMobject("\\times") words[1].highlight_by_tex(p_tex, P_COLOR) words[0].next_to(equals, RIGHT) words[1].next_to(words[0], DOWN, aligned_edge = LEFT) times.next_to(words[0], RIGHT) everyone = Group(dot_product, equals, times, words) everyone.center().scale_to_fit_width(SPACE_WIDTH - 1) self.add(dot_product) self.play(Write(equals)) self.play(Write(words[0])) self.dither() self.play( Write(times), Write(words[1]) ) self.dither()
def show_snells(self, index, frame): left_text, right_text = [ "\\dfrac{\\sin(\\theta_%d)}{\\phantom{\\sqrt{y_1}}}"%x for x in index, index+1 ] left, equals, right = TexMobject( [left_text, "=", right_text] ).split() vs = [] sqrt_ys = [] for x, numerator in [(index, left), (index+1, right)]: v, sqrt_y = [ TexMobject( text, size = "\\Large" ).next_to(numerator, DOWN) for text in "v_%d"%x, "\\sqrt{y_%d}"%x ] vs.append(v) sqrt_ys.append(sqrt_y) start, end = [ Mobject( left.copy(), mobs[0], equals.copy(), right.copy(), mobs[1] ).replace(frame) for mobs in vs, sqrt_ys ] self.add(start) self.dither(2) self.play(Transform( start, end, path_func = counterclockwise_path() )) self.dither(2) self.remove(start, end)
def get_label_group(self, t): graph = self.graph v_line = self.get_vertical_line_to_graph( t, graph, color = YELLOW, ) brace = Brace(v_line, RIGHT) height_label = brace.get_text("$2^%d$"%t) ss_group = self.get_secant_slope_group( t, graph, dx = 0.01, df_label = "dM", dx_label = "dt", dx_line_color = GREEN, secant_line_color = RED, ) slope_label = TexMobject( "\\text{Slope}", "=", "2^%d"%t, "(%.7f\\dots)"%np.log(2) ) slope_label.next_to( ss_group.secant_line.point_from_proportion(0.65), DOWN+RIGHT, buff = 0 ) slope_label.highlight_by_tex("Slope", RED) return VGroup( v_line, brace, height_label, ss_group, slope_label )
def add_scaling(self, arrows, syms, arrays): s_arrows = VMobject( TexMobject("2"), Vector([1, 1]).highlight(YELLOW), TexMobject("="), Vector([2, 2]).highlight(WHITE) ) s_arrows.arrange_submobjects(RIGHT) s_arrows.scale(0.75) s_arrows.next_to(arrows, DOWN) s_arrays = VMobject( TexMobject("2"), matrix_to_mobject([3, -5]).highlight(YELLOW), TextMobject("="), matrix_to_mobject(["2(3)", "2(-5)"]) ) s_arrays.arrange_submobjects(RIGHT) s_arrays.scale(0.5) s_arrays.next_to(arrays, DOWN) s_syms = TexMobject(["2", "\\vec{\\textbf{v}}"]) s_syms.split()[-1].highlight(YELLOW) s_syms.next_to(syms, DOWN) self.play( Write(s_arrows), Write(s_arrays), Write(s_syms), run_time = 2 ) self.dither()
def construct(self): in_vect = Matrix(self.input_coords) out_vect = Matrix(self.output_coords) in_vect.highlight(BLUE) out_vect.highlight(GREEN) func = TexMobject("L(\\vec{\\textbf{v}})") point = VectorizedPoint(func.get_center()) in_vect.next_to(func, LEFT, buff = 1) out_vect.next_to(func, RIGHT, buff = 1) in_words = TextMobject("Input") in_words.next_to(in_vect, DOWN) in_words.highlight(BLUE_C) out_words = TextMobject("Output") out_words.next_to(out_vect, DOWN) out_words.highlight(GREEN_C) title = TextMobject(self.title) title.to_edge(UP) self.add(title) self.play(Write(func)) self.play(Write(in_vect), Write(in_words)) self.dither() self.add(in_vect.copy()) self.play(Transform(in_vect, point, submobject_mode = "lagged_start")) self.play(Transform(in_vect, out_vect, submobject_mode = "lagged_start")) self.add(out_words) self.dither()
def move_matrix_parentheses(self, morty, matrices): m1, m2, m3 = matrices parens = TexMobject(["(", ")"]) parens.scale_to_fit_height(1.2*m1.get_height()) lp, rp = parens.split() state1 = VMobject( VectorizedPoint(m1.get_left()), m1, m2, VectorizedPoint(m2.get_right()), m3 ) state2 = VMobject(*[ m.copy() for m in lp, m1, m2, rp, m3 ]) state3 = VMobject(*[ m.copy() for m in m1, lp, m2, m3, rp ]) for state in state2, state3: state.arrange_submobjects(RIGHT, buff = 0.1) m1, lp, m2, m3, rp = state3.split() state3 = VMobject(lp, m1, m2, rp, m3) self.play(morty.change_mode, "angry") for state in state2, state3: self.play(Transform(state1, state)) self.dither() self.play(morty.change_mode, "confused") self.dither()
def construct(self): grid = get_grid() grid.sort_points(np.linalg.norm) freq_line = get_freq_line() freq_line.sort_points(lambda p : p[0]) red, blue = Color(RED), Color(BLUE) freq_line.gradient_highlight(red, blue) colors = [ Color(rgb = interpolate( np.array(red.rgb), np.array(blue.rgb), alpha )) for alpha in np.arange(4)/3. ] string = Line(3*LEFT, 3*RIGHT, color = colors[1]) vibration = Vibrate(string) vibration_copy = vibration.copy() vibration_copy.mobject.stroke_width = 1 sub_vibrations = [ Vibrate( string.copy().shift((n-1)*UP).highlight(colors[n]), overtones = 1, spatial_period = 6./(n+1), temporal_period = 1./(n+1), amplitude = 0.5/(n+1) ) for n in range(4) ] words = TexMobject("&\\vdots \\\\ \\text{thousands }& \\text{of frequencies} \\\\ &\\vdots") words.to_edge(UP, buff = 0.1) self.add(grid) self.dither() self.play(DelayByOrder(ApplyMethod( grid.gradient_highlight, red, blue ))) self.play(Transform(grid, freq_line)) self.dither() self.play( ShimmerIn( words, rate_func = squish_rate_func(smooth, 0, 0.2) ), *sub_vibrations, run_time = 5 ) self.play( *[ TransformAnimations( sub_vib, vibration ) for sub_vib in sub_vibrations ]+[FadeOut(words)] ) self.clear() self.add(freq_line) self.play(vibration)
def construct(self): series = VideoSeries() series.to_edge(UP) this_video = series[3] next_video = series[4] brace = Brace(this_video, DOWN) this_video.save_state() this_video.highlight(YELLOW) this_tex = TexMobject( "{d(", "a^t", ") \\over dt} = ", "a^t", "\\ln(a)" ) this_tex[1][1].highlight(YELLOW) this_tex[3][1].highlight(YELLOW) this_tex.next_to(brace, DOWN) next_tex = VGroup(*map(TextMobject, [ "Chain rule", "Product rule", "$\\vdots$" ])) next_tex.arrange_submobjects(DOWN) next_tex.next_to(brace, DOWN) next_tex.shift( next_video.get_center()[0]*RIGHT\ -next_tex.get_center()[0]*RIGHT ) self.add(series, brace, *this_tex[:3]) self.change_student_modes( "confused", "pondering", "erm", look_at_arg = this_tex ) self.play(ReplacementTransform( this_tex[1].copy(), this_tex[3] )) self.dither() self.play( Write(this_tex[4]), ReplacementTransform( this_tex[3][0].copy(), this_tex[4][3], path_arc = np.pi, remover = True ) ) self.dither(2) self.play(this_tex.replace, this_video) self.play( brace.next_to, next_video, DOWN, this_video.restore, Animation(this_tex), next_video.highlight, YELLOW, Write(next_tex), self.get_teacher().change_mode, "raise_right_hand" ) self.change_student_modes( *["pondering"]*3, look_at_arg = next_tex ) self.dither(3)
def construct(self): but = TextMobject("but") dots = TexMobject("\\dots") dots.next_to(but, aligned_edge = DOWN) but.shift(20*RIGHT) self.play(ApplyMethod(but.shift, 20*LEFT)) self.play(Write(dots, run_time = 5)) self.dither()
def construct(self): for char, color in zip(["\\imath", "\\jmath", "k"], [X_COLOR, Y_COLOR, Z_COLOR]): sym = TexMobject("{\\hat{%s}}"%char) sym.scale(3) sym.highlight(color) self.play(Write(sym)) self.dither() self.clear()
def show_natural_loggedness(self, expression): base, constant = expression[1], expression[-3] log_constant, exp_constant = constant.copy(), constant.copy() log_base, exp_base = base.copy(), base.copy() log_equals, exp_equals = map(TexMobject, "==") ln = TexMobject("\\ln(2)") log_base.move_to(ln[-2]) ln.remove(ln[-2]) log_equals.next_to(ln, LEFT) log_constant.next_to(log_equals, LEFT) log_expression = VGroup( ln, log_constant, log_equals, log_base ) e = TexMobject("e") exp_constant.scale(0.7) exp_constant.next_to(e, UP+RIGHT, buff = 0) exp_base.next_to(exp_equals, RIGHT) VGroup(exp_base, exp_equals).next_to( VGroup(e, exp_constant), RIGHT, aligned_edge = DOWN ) exp_expression = VGroup( e, exp_constant, exp_equals, exp_base ) for group, vect in (log_expression, UP), (exp_expression, DOWN): group.to_edge(RIGHT) group.shift(vect) self.play( ReplacementTransform(base.copy(), log_base), ReplacementTransform(constant.copy(), log_constant), run_time = 2 ) self.play(Write(ln), Write(log_equals)) self.dither() self.play( ReplacementTransform( log_expression.copy(), exp_expression, run_time = 2, ) ) self.dither(2) ln_a = expression[-1] self.play( FadeOut(expression[-2]), FadeOut(constant), ln_a.move_to, constant, LEFT, ln_a.highlight, BLUE ) self.dither() self.play(*map(FadeOut, [log_expression, exp_expression])) self.dither()
def construct(self): dated_events = [ { "date" : 1696, "text": "Johann Bernoulli poses Brachistochrone problem", "picture" : "Johann_Bernoulli2" }, { "date" : 1662, "text" : "Fermat states his principle of least time", "picture" : "Pierre_de_Fermat" } ] speical_dates = [2016] + [ obj["date"] for obj in dated_events ] centuries = range(1600, 2100, 100) timeline = NumberLine( numerical_radius = 300, number_at_center = 1800, unit_length_to_spatial_width = SPACE_WIDTH/100, tick_frequency = 10, numbers_with_elongated_ticks = centuries ) timeline.add_numbers(*centuries) centers = [ Point(timeline.number_to_point(year)) for year in speical_dates ] timeline.add(*centers) timeline.shift(-centers[0].get_center()) self.add(timeline) self.dither() run_times = iter([3, 1]) for point, event in zip(centers[1:], dated_events): self.play(ApplyMethod( timeline.shift, -point.get_center(), run_time = run_times.next() )) picture = ImageMobject(event["picture"], invert = False) picture.scale_to_fit_width(2) picture.to_corner(UP+RIGHT) event_mob = TextMobject(event["text"]) event_mob.shift(2*LEFT+2*UP) date_mob = TexMobject(str(event["date"])) date_mob.scale(0.5) date_mob.shift(0.6*UP) line = Line(event_mob.get_bottom(), 0.2*UP) self.play( ShimmerIn(event_mob), ShowCreation(line), ShimmerIn(date_mob) ) self.play(FadeIn(picture)) self.dither(3) self.play(*map(FadeOut, [event_mob, date_mob, line, picture]))
def get_kilogoogle(self): G = self.get_google_logo()[-1] kilo = TextMobject("K") kilo.scale(1.5) kilo.next_to(G[-1], LEFT, SMALL_BUFF, DOWN) plus_plus = TexMobject("++") plus_plus.set_stroke(width = 1) plus_plus.next_to(G, RIGHT, SMALL_BUFF) return VGroup(kilo, G, plus_plus)
def get_axis_labels(self, x_label = "x", y_label = "y"): x_axis, y_axis = self.get_axes().split() x_label_mob = TexMobject(x_label) y_label_mob = TexMobject(y_label) x_label_mob.next_to(x_axis, DOWN) x_label_mob.to_edge(RIGHT) y_label_mob.next_to(y_axis, RIGHT) y_label_mob.to_edge(UP) return VMobject(x_label_mob, y_label_mob)
def construct(self, order): if order == 2: result_tex = "(0.125, 0.75)" elif order == 3: result_tex = "(0.0758, 0.6875)" phc, arg, result = TexMobject([ "\\text{PHC}_%d"%order, "(0.3)", "= %s"%result_tex ]).to_edge(UP).split() function = TextMobject("Function", size = "\\normal") function.shift(phc.get_center()+DOWN+2*LEFT) function_arrow = Arrow(function, phc) line = Line(5*LEFT, 5*RIGHT) curve = HilbertCurve(order = order) line.match_colors(curve) grid = Grid(2**order, 2**order) grid.fade() for mob in curve, grid: mob.scale(0.7) index = int(0.3*line.get_num_points()) dot1 = Dot(line.points[index]) arrow1 = Arrow(arg, dot1, buff = 0.1) dot2 = Dot(curve.points[index]) arrow2 = Arrow(result.get_bottom(), dot2, buff = 0.1) self.add(phc) self.play( ShimmerIn(function), ShowCreation(function_arrow) ) self.dither() self.remove(function_arrow, function) self.play(ShowCreation(line)) self.dither() self.play( ShimmerIn(arg), ShowCreation(arrow1), ShowCreation(dot1) ) self.dither() self.remove(arrow1) self.play( FadeIn(grid), Transform(line, curve), Transform(dot1, dot2), run_time = 2 ) self.dither() self.play( ShimmerIn(result), ShowCreation(arrow2) ) self.dither()
def reset(self): time = self.t_expression[-1] faders = [time] + list(self.get_on_screen_pi_creatures()) new_time = TexMobject("0") new_time.next_to(self.t_expression[-2], RIGHT) first_creature = self.get_pi_creatures()[0] self.play(*map(FadeOut, faders)) self.play(*map(FadeIn, [first_creature, new_time])) self.t_expression.submobjects[-1] = new_time
def construct(self): i_to = TexMobject("\\hat{\\imath} \\to").highlight(X_COLOR) j_to = TexMobject("\\hat{\\jmath} \\to").highlight(Y_COLOR) k_to = TexMobject("\\hat{k} \\to").highlight(Z_COLOR) i_array = Matrix(self.col1) j_array = Matrix(self.col2) k_array = Matrix(self.col3) everything = VMobject( i_to, i_array, TexMobject("=").highlight(BLACK), j_to, j_array, TexMobject("=").highlight(BLACK), k_to, k_array, TexMobject("=").highlight(BLACK), ) everything.arrange_submobjects(RIGHT, buff=0.1) everything.scale_to_fit_width(2 * SPACE_WIDTH - 1) everything.to_edge(DOWN) i_array.highlight(X_COLOR) j_array.highlight(Y_COLOR) k_array.highlight(Z_COLOR) arrays = [i_array, j_array, k_array] matrix = Matrix( reduce(lambda a1, a2: np.append(a1, a2, axis=1), [m.copy().get_mob_matrix() for m in arrays])) matrix.to_edge(DOWN) start_entries = reduce(op.add, map(lambda a: a.get_entries().split(), arrays)) target_entries = matrix.get_mob_matrix().transpose().flatten() start_l_bracket = i_array.get_brackets().split()[0] start_r_bracket = k_array.get_brackets().split()[1] start_brackets = VMobject(start_l_bracket, start_r_bracket) target_bracketes = matrix.get_brackets() for mob in everything.split(): self.play(Write(mob, run_time=1)) self.wait() self.play( FadeOut(everything), Transform(VMobject(*start_entries), VMobject(*target_entries)), Transform(start_brackets, target_bracketes)) self.wait()
def show_angles(self, ring): ring_center = ring.get_center() lines, arcs, thetas = [], [], [] counter = it.count(1) for point in self.start_point, self.end_point: line = Line(point, ring_center, color = GREY) angle = np.pi/2-np.abs(np.arctan(line.get_slope())) arc = Arc(angle, radius = 0.5).rotate(np.pi/2) if point is self.end_point: arc.rotate(np.pi) theta = TexMobject("\\theta_%d"%counter.next()) theta.scale(0.5) theta.shift(2*arc.get_center()) arc.shift(ring_center) theta.shift(ring_center) lines.append(line) arcs.append(arc) thetas.append(theta) vert_line = Line(2*UP, 2*DOWN) vert_line.shift(ring_center) top_spring, bottom_spring = self.start_springs.split() self.play( Transform(ring, Point(ring_center)), Transform(top_spring, lines[0]), Transform(bottom_spring, lines[1]) ) self.play(ShowCreation(vert_line)) anims = [] for arc, theta in zip(arcs, thetas): anims += [ ShowCreation(arc), GrowFromCenter(theta) ] self.play(*anims) self.wait()
def construct(self): vect_coords = [-1, 2] t_matrix = np.array([[2, 2], [-2, 1]]) #Draw vectors self.setup() i_label = self.add_transformable_label(self.i_hat, "\\hat{\\imath}", animate=False, direction="right", color=X_COLOR) j_label = self.add_transformable_label(self.j_hat, "\\hat{\\jmath}", animate=False, direction="right", color=Y_COLOR) vect = self.add_vector(vect_coords) vect_array = Matrix(["x", "y"], add_background_rectangles=True) v_equals = TexMobject(["\\vec{\\textbf{v}}", "="]) v_equals.split()[0].highlight(YELLOW) v_equals.next_to(vect_array, LEFT) vect_array.add(v_equals) vect_array.to_edge(UP, buff=0.2) background_rect = BackgroundRectangle(vect_array) vect_array.get_entries().highlight(YELLOW) self.play(ShowCreation(background_rect), Write(vect_array)) self.add_foreground_mobject(background_rect, vect_array) #Show scaled vectors x, y = vect_array.get_entries().split() scaled_i_label = VMobject(x.copy(), i_label) scaled_j_label = VMobject(y.copy(), j_label) scaled_i = self.i_hat.copy().scale(vect_coords[0]) scaled_j = self.j_hat.copy().scale(vect_coords[1]) for mob in scaled_i, scaled_j: mob.fade(0.3) scaled_i_label_target = scaled_i_label.copy() scaled_i_label_target.arrange_submobjects(buff=0.1) scaled_i_label_target.next_to(scaled_i, DOWN) scaled_j_label_target = scaled_j_label.copy() scaled_j_label_target.arrange_submobjects(buff=0.1) scaled_j_label_target.next_to(scaled_j, LEFT) self.show_scaled_vectors(vect_array, vect_coords, i_label, j_label) self.apply_transposed_matrix(t_matrix) self.show_scaled_vectors(vect_array, vect_coords, i_label, j_label) self.record_basis_coordinates(vect_array, vect)
def add_2d_cross_product(self): h_line = DashedLine(ORIGIN, SPACE_WIDTH * RIGHT) h_line.next_to(self.only_3d_text, DOWN, buff=MED_BUFF / 2) h_line.to_edge(RIGHT, buff=0) arrays = np.random.randint(0, 9, (2, 2)) m1, m2 = matrices = map(Matrix, arrays) for m in matrices: for e, color in zip(m.get_entries(), [X_COLOR, Y_COLOR]): e.highlight(color) cross_product = Group(m1, TexMobject("\\times"), m2) cross_product.arrange_submobjects() (x1, x2), (x3, x4) = tuple(m1.get_entries()), tuple(m2.get_entries()) entries = [x1, x2, x3, x4] for entry in entries: entry.target = entry.copy() eq, dot1, minus, dot2 = syms = map(TexMobject, ["=", "\\cdot", "-", "\\cdot"]) result = Group( eq, x1.target, dot1, x4.target, minus, x3.target, dot2, x2.target, ) result.arrange_submobjects(RIGHT) full_cross_product = Group(cross_product, result) full_cross_product.arrange_submobjects(RIGHT) full_cross_product.next_to(h_line, DOWN, buff=MED_BUFF / 2) self.play(ShowCreation(h_line)) self.play(Write(cross_product)) self.play( Write(Group(*syms)), *[Transform(entry.copy(), entry.target) for entry in entries]) self.dither() self.two_d_result = Group(*result[1:])
def put_on_vertex(self, index, value): assert (index in [0, 1, 2]) if value is None: value = VectorizedPoint() if isinstance(value, numbers.Number): value = str(value) if isinstance(value, str): value = TexMobject(value) if isinstance(value, TOP): return self.put_top_on_vertix(index, value) self.rescale_corner_mobject(value) value.center() if index == 0: offset = -value.get_corner(UP + RIGHT) elif index == 1: offset = -value.get_bottom() elif index == 2: offset = -value.get_corner(UP + LEFT) value.shift(self.offset_multiple * offset) anchors = self.triangle.get_anchors_and_handles()[0] value.shift(anchors[index]) return value
def matrix_multiplication(): return TexMobject(""" \\left[ \\begin{array}{cc} a & b \\\\ c & d \\end{array} \\right] \\left[ \\begin{array}{cc} e & f \\\\ g & h \\end{array} \\right] = \\left[ \\begin{array}{cc} ae + bg & af + bh \\\\ ce + dg & cf + dh \\end{array} \\right] """)
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: num_pair[index] = val point = self.num_pair_to_point(num_pair) num = TexMobject(str(val)) num.scale_to_fit_height( self.written_coordinate_height ) num.shift( point-num.get_corner(UP+LEFT), self.written_coordinate_nudge ) result.append(num) return result
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)) numbers += [ complex(0, y) for y in range(-int(self.y_radius), int(self.y_radius)) ] for number in numbers: point = self.number_to_point(number) if number == 0: num_str = "0" else: num_str = str(number).replace("j", "i") num = TexMobject(num_str) num.scale(self.number_scale_factor) num.shift(point-num.get_corner(UP+LEFT)+nudge) result.add(num) return result
def get_df_box_labels(self, df_boxes): bottom_box, corner_box, right_box = df_boxes result = VGroup() quads = [ (right_box, UP, self.top_func_nudge_label, LEFT), (corner_box, RIGHT, self.side_func_nudge_label, ORIGIN), ] for box, vect, label_tex, aligned_edge in quads: brace = Brace(box, vect) label = TexMobject(label_tex) label.next_to(brace, vect, aligned_edge=aligned_edge, buff=SMALL_BUFF) label.highlight(df_boxes[0].get_color()) result.add(VGroup(brace, label)) return result
def get_graph_label( self, graph, label="f(x)", x_val=None, direction=RIGHT, buff=MED_SMALL_BUFF, color=None, ): label = TexMobject(label) color = color or graph.get_color() label.highlight(color) if x_val is None: #Search from right to left for x in np.linspace(self.x_max, self.x_min, 100): point = self.input_to_graph_point(x, graph) if point[1] < SPACE_HEIGHT: break x_val = x label.next_to(self.input_to_graph_point(x_val, graph), direction, buff=buff) label.shift_onto_screen() return label
def try_specific_dt_values(self): expressions = [] for num_zeros in [1, 2, 4, 7]: dt_str = "0." + num_zeros * "0" + "1" dt_num = float(dt_str) output_num = (self.base**dt_num - 1) / dt_num output_str = "%.7f\\dots" % output_num expression = TexMobject("{%s^" % self.base_str, "{%s}" % dt_str, "-1", "\\over \\,", "%s}" % dt_str, "=", output_str) expression.highlight_by_tex(dt_str, GREEN) expression.highlight_by_tex(output_str, BLUE) expression.to_corner(UP + RIGHT) expressions.append(expression) curr_expression = expressions[0] self.play(Write(curr_expression), self.pi_creature.change_mode, "pondering") self.dither(2) for expression in expressions[1:]: self.play(Transform(curr_expression, expression)) self.dither(2) return curr_expression[-1]
def shift_to_good_and_back(self): sum2 = self.sum1.copy() sigma = sum2.submobjects[1] plus = TexMobject("+").replace(sigma) sum2.submobjects[1] = plus prod2 = self.prod1.copy() pi = prod2.submobjects[0] times = TexMobject("\\times").replace(pi) prod2.submobjects[0] = times new_sin, new_cos, new_tan = [ VMobject().set_anchor_points(corners, mode="corners").replace( trig_part.split()[0]) for corners, trig_part in zip([ [RIGHT, RIGHT + UP, LEFT], [RIGHT + UP, LEFT, RIGHT], [RIGHT + UP, RIGHT, LEFT], ], self.trigs1.split()) ] x1, x2, x3 = [ trig_part.split()[1] for trig_part in self.trigs1.split() ] trigs2 = VMobject( VMobject(new_sin, x1), VMobject(new_cos, x2), VMobject(new_tan, x3), ) x, arrow, y = TexMobject("x \\rightarrow y").split() f = TexMobject("f") f.next_to(arrow, UP) func2 = VMobject(f, VMobject(), x, VMobject(), arrow, y) func2.scale(0.5) func2.shift(self.func1.get_center()) good_symbols = VMobject(sum2, prod2, trigs2, func2) bad_symbols = self.symbols.copy() self.play(Transform(self.symbols, good_symbols, path_arc=np.pi)) self.wait(3) self.play(Transform(self.symbols, bad_symbols, path_arc=np.pi)) self.wait()
def write_second_derivative(self): second_deriv = TexMobject("\\frac{d^2 f}{dx^2}") second_deriv.next_to(self.deriv, DOWN, MED_LARGE_BUFF) second_deriv.highlight(self.second_deriv_color) points = [ self.input_to_graph_point(x, self.graph) for x in self.x2, self.x3 ] words = TextMobject("Change to \\\\ slope") words.next_to( center_of_mass(points), UP, 1.5*LARGE_BUFF ) arrows = [ Arrow(words.get_bottom(), p, color = WHITE) for p in points ] self.play(Write(second_deriv)) self.wait() self.play( Write(words), ShowCreation( arrows[0], rate_func = squish_rate_func(smooth, 0.5, 1) ), run_time = 2 ) self.animate_secant_slope_group_change( self.ss_group, target_x = self.x3, run_time = 3, added_anims = [ Transform( *arrows, run_time = 3, path_arc = 0.75*np.pi ), ] ) self.play(FadeOut(arrows[0])) self.animate_secant_slope_group_change( self.ss_group, target_x = self.x2, run_time = 3, ) self.second_deriv_words = words self.second_deriv = second_deriv
def add_tex(self): tex = TexMobject("f", "(A, B)", "=", "(x, y, z)") tex.to_edge(UP) tex.shift(LEFT) ab_brace = Brace(tex[1]) xyz_brace = Brace(tex[-1], RIGHT) ab_brace.add(ab_brace.get_text("Pair of points on the loop")) xyz_brace.add(xyz_brace.get_text("Point in 3d space")) ab_brace.gradient_highlight(MAROON_B, PURPLE_B) xyz_brace.highlight(BLUE) self.add(tex) self.play(Write(ab_brace)) self.dither() self.play(Write(xyz_brace)) self.dither()
def kilo_google(self): self.create_four_billion_copies(1, Laptop()) google = self.get_google_logo() google.next_to(self.group_of_four_billion_things, UP, buff=LARGE_BUFF, aligned_edge=LEFT) google.shift(RIGHT) millions = TextMobject("$\\sim$ Millions of servers") millions.next_to(google, RIGHT) plus_plus = TexMobject("++") plus_plus.next_to(google, RIGHT, SMALL_BUFF) plus_plus.set_stroke(width=2) kilo = TextMobject("Kilo") kilo.scale(1.5) kilo.next_to(google[-1], LEFT, SMALL_BUFF, DOWN) kilogoogle = VGroup(kilo, google, plus_plus) four_billion = self.four_billions[1] laptop, h_line, target_kilogoogle = self.get_fraction( 1, Laptop(), self.get_kilogoogle()) self.revert_to_original_skipping_status() self.play(DrawBorderThenFill(google)) self.dither(2) self.play(Write(millions)) self.dither(2) self.play( LaggedStart( Indicate, self.group_of_four_billion_things, run_time=4, rate_func=there_and_back, lag_ratio=0.25, )) self.play(FadeOut(millions), FadeIn(plus_plus)) self.play(Write(kilo)) self.dither() self.play(four_billion.restore, FadeOut(self.group_of_four_billion_things)) self.play( Transform(kilogoogle, target_kilogoogle), FadeIn(laptop), FadeIn(h_line), ) self.dither()
def get_number_mobjects(self, *numbers, **kwargs): #TODO, handle decimals if len(numbers) == 0: numbers = self.default_numbers_to_display() if "force_integers" in kwargs and kwargs["force_integers"]: numbers = map(int, numbers) result = VGroup() for number in numbers: mob = TexMobject(str(number)) mob.scale(self.number_scale_val) mob.next_to( self.number_to_point(number), self.line_to_number_vect, self.line_to_number_buff, ) result.add(mob) return result
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): dated_events = [{ "date": 1696, "text": "Johann Bernoulli poses Brachistochrone problem", "picture": "Johann_Bernoulli2" }, { "date": 1662, "text": "Fermat states his principle of least time", "picture": "Pierre_de_Fermat" }] speical_dates = [2016] + [obj["date"] for obj in dated_events] centuries = range(1600, 2100, 100) timeline = NumberLine(numerical_radius=300, number_at_center=1800, unit_length_to_spatial_width=SPACE_WIDTH / 100, tick_frequency=10, numbers_with_elongated_ticks=centuries) timeline.add_numbers(*centuries) centers = [ Point(timeline.number_to_point(year)) for year in speical_dates ] timeline.add(*centers) timeline.shift(-centers[0].get_center()) self.add(timeline) self.wait() run_times = iter([3, 1]) for point, event in zip(centers[1:], dated_events): self.play( ApplyMethod(timeline.shift, -point.get_center(), run_time=run_times.next())) picture = ImageMobject(event["picture"], invert=False) picture.scale_to_fit_width(2) picture.to_corner(UP + RIGHT) event_mob = TextMobject(event["text"]) event_mob.shift(2 * LEFT + 2 * UP) date_mob = TexMobject(str(event["date"])) date_mob.scale(0.5) date_mob.shift(0.6 * UP) line = Line(event_mob.get_bottom(), 0.2 * UP) self.play(ShimmerIn(event_mob), ShowCreation(line), ShimmerIn(date_mob)) self.play(FadeIn(picture)) self.wait(3) self.play(*map(FadeOut, [event_mob, date_mob, line, picture]))
def construct(self): randy = Randolph().to_corner() bubble = SpeechBubble().pin_to(randy) words = TextMobject("No one will actually do this...") tau_v_pi = TexMobject("\\tau > \\pi").scale(2) morty = Mortimer("speaking").to_corner(DOWN + RIGHT) morty_bubble = SpeechBubble(direction=RIGHT, height=4) morty_bubble.pin_to(morty) final_words = TextMobject( "If this war is won, it will \\\\ not be won with that attitude") lil_thought_bubble = ThoughtBubble(height=3, width=5) lil_thought_bubble.set_fill(BLACK, 1.0) lil_thought_bubble.pin_to(randy) lil_thought_bubble.write( "Okay buddy, calm down, it's notation \\\\ we're talking about not war." ) lil_thought_bubble.show() self.add(randy) self.play(ApplyMethod(randy.change_mode, "sassy"), ShowCreation(bubble)) bubble.add_content(words) self.play(Write(words), run_time=2) self.play(Blink(randy)) bubble.add_content(tau_v_pi) self.play(FadeOut(words), GrowFromCenter(tau_v_pi), ApplyMethod(randy.change_mode, "speaking")) self.remove(words) self.play(Blink(randy)) self.wait(2) self.play(FadeOut(bubble), FadeIn(morty), ShowCreation(morty_bubble), ApplyMethod(randy.change_mode, "plain")) morty_bubble.add_content(final_words) self.play(Write(final_words)) self.wait() self.play(Blink(morty)) self.wait(2) self.play(ShowCreation(lil_thought_bubble))
def construct(self): matrix_rule = TexMobject(""" \\left[ \\begin{array}{c} x \\\\ y \\end{array} \\right] \\rightarrow \\left[ \\begin{array}{c} 2x + y \\\\ y + 2x \\end{array} \\right] """) self.setup() pi_creature = PiCreature(color = PINK).scale(0.5) pi_creature.shift(-pi_creature.get_corner(DOWN+LEFT)) self.plane.prepare_for_nonlinear_transform() self.play(ShowCreation( self.plane, submobject_mode = "one_at_a_time", run_time = 2 )) self.play(FadeIn(pi_creature)) self.play(Blink(pi_creature)) self.plane.add(pi_creature) self.play(Homotopy(plane_wave_homotopy, self.plane, run_time = 3)) self.wait(2) self.apply_matrix([[2, 1], [1, 2]]) self.wait() self.play( FadeOut(self.plane), Write(matrix_rule), run_time = 2 ) self.wait()
def construct(self): analysis = get_image("Analysis_page_showing_pi") analysis.scale_to_fit_height(2 * SPACE_HEIGHT) analysis.to_edge(LEFT, buff=0) text = TextMobject("``\\dots set the radius of", "the circle\\dots to be = 1, \\dots \\\\", "through approximations the", "semicircumference \\\\", "of said circle", "has been found to be", "$= 3.14159\\dots$,\\\\", "for which number, for the sake of", "brevity, \\\\ I will write", "$\pi$\\dots''", alignment='') pi_formula = TexMobject("\\pi", "=", "{ \\text{semicircumference}", "\\over", "\\text{radius}}") text.scale_to_fit_width(SPACE_WIDTH) text.next_to(analysis, RIGHT, LARGE_BUFF) text.to_edge(UP) HIGHLIGHT_COLOR = GREEN for mob in text, pi_formula: mob.highlight_by_tex_to_color_map({ "semicircumference": HIGHLIGHT_COLOR, "3.14": HIGHLIGHT_COLOR, "\pi": HIGHLIGHT_COLOR }) terms, generate_anims1, generate_anims2 = get_circle_drawing_terms( radius=1, positioning_func=lambda circ: circ.next_to(text, DOWN, LARGE_BUFF)) terms[0].highlight(HIGHLIGHT_COLOR) terms[-1].highlight(HIGHLIGHT_COLOR) pi_formula.next_to(terms, DOWN, buff=0) pi_formula.align_to(text, alignment_vect=RIGHT) pi_formula[0].scale(2, about_edge=RIGHT) self.add(analysis) self.play(*generate_anims2(), rate_func=lambda t: 0.5 * smooth(t)) self.play(LaggedStart(FadeIn, text), run_time=5) self.play(FadeIn(pi_formula)) self.wait()
def construct(self): hilbert_curves, snake_curves = [[ CurveClass(order=n) for n in range(2, 7) ] for CurveClass in HilbertCurve, SnakeCurve] for curve in hilbert_curves + snake_curves: curve.scale(0.8) for curve in hilbert_curves: curve.to_edge(LEFT) for curve in snake_curves: curve.to_edge(RIGHT) greater_than = TexMobject(">") question_mark = TextMobject("?") question_mark.next_to(greater_than, UP) self.add(greater_than, question_mark) hilbert_curve = hilbert_curves[0] snake_curve = snake_curves[0] for new_hc, new_sc in zip(hilbert_curves[1:], snake_curves[1:]): self.play(*[ Transform(hilbert_curve, new_hc), Transform(snake_curve, new_sc) ]) self.dither()
def construct(self): matrix = Matrix([ [2, 0], [-1, 1], [-2, 1], ]) matrix.highlight_columns(X_COLOR, Y_COLOR) brace = Brace(matrix) words = VMobject(TextMobject("Span", "of columns"), TexMobject("\\Updownarrow"), TextMobject("``Column space''")) words.arrange_submobjects(DOWN, buff=0.1) words.next_to(brace, DOWN) words[0][0].highlight(PINK) words[2].highlight(TEAL) words[0].add_background_rectangle() words[2].add_background_rectangle() VMobject(matrix, brace, words).center() self.add(matrix) self.play(GrowFromCenter(brace), Write(words, run_time=2)) self.dither()
def construct(self, index): equation = get_equation(index) equation.to_corner(UP + LEFT) top = TOP(2, 3, 8) new_top = top.copy() equals = TexMobject("=").scale(1.5) new_top.next_to(equals, LEFT, buff=1) new_top.values[index].next_to(equals, RIGHT, buff=1) circle = Circle(radius=1.7 * top.radius, color=OPERATION_COLORS[index]) self.add(equation, top) self.wait() self.play(Transform(top, new_top), ShowCreation(equals)) circle.shift(new_top.triangle.get_center_of_mass()) new_circle = circle.copy() new_top.put_on_vertex(index, new_circle) self.wait() self.play(ShowCreation(circle)) self.wait() self.play(Transform(circle, new_circle), ApplyMethod(new_top.values[index].highlight, circle.color)) self.wait()
def __init__(self, **kwargs): Mobject.__init__(self, **kwargs) for part_name in self.PART_NAMES: mob = ImageMobject(part_name_to_directory(part_name), should_center=False) if part_name not in self.WHITE_PART_NAMES: mob.highlight(self.color) setattr(self, part_name, mob) self.eyes = Mobject(self.left_eye, self.right_eye) self.legs = Mobject(self.left_leg, self.right_leg) mouth_center = self.get_mouth_center() self.mouth.center() self.smile = self.mouth self.frown = self.mouth.copy().rotate(np.pi, RIGHT) self.straight_mouth = TexMobject("-").scale(0.7) for mouth in self.smile, self.frown, self.straight_mouth: mouth.sort_points(lambda p: p[0]) mouth.highlight(self.color) ##to blend into background mouth.shift(mouth_center) self.digest_mobject_attrs() self.give_smile() self.add(self.mouth) self.scale(PI_CREATURE_SCALE_VAL)
def label_graph(self, graph, label="f(x)", proportion=0.7, direction=LEFT, buff=MED_BUFF, color=None, animate=True): label = TexMobject(label) color = color or graph.get_color() label.highlight(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_log_anim(self, center): O_log_n = TexMobject(["O(", "\\log(n)", ")"]) O_log_n.shift(center) log_n = O_log_n.split()[1] #super hacky g = log_n.split()[2] for mob in g.submobjects: mob.is_subpath = False mob.set_fill(BLACK, 1.0) log_n.add(mob) g.submobjects = [] #end hack top = TOP(2, None, "n", radius=0.75) top.scale_to_fit_width(log_n.get_width()) top.shift(log_n.get_center()) new_O_log_n = O_log_n.copy() new_O_log_n.submobjects[1] = top return Transform(O_log_n, new_O_log_n)
def cannot_move_disk_with_crap_on_top(self): not_allowed = TextMobject("Not allowed") not_allowed.to_edge(UP) not_allowed.highlight(RED) cross = TexMobject("\\times") cross.set_fill(RED, opacity = 0.5) disk = self.disks[3] disk.save_state() self.move_disks_to_peg([3], 1, added_anims = [ Transform(self.title, not_allowed) ]) cross.replace(disk, stretch = False) self.play(FadeIn(cross)) self.dither() self.play( FadeOut(cross), disk.restore )
def overall_probability(self): point_mobs = self.point_mobs triangle = self.triangle one_fourth = TexMobject("1/4") one_fourth.highlight(BLUE) one_fourth.next_to(self.question, DOWN) self.triangle_update.update(1) self.play( FadeIn(triangle), Animation(point_mobs) ) self.update_animations.append(self.triangle_update) self.have_p3_jump_around_randomly(8, dither_time = 0.25) self.play(ReplacementTransform( self.proportion.copy(), VGroup(one_fourth) )) self.have_p3_jump_around_randomly(32, dither_time = 0.25)
def show_derivative(self): deriv = TexMobject("\\frac{df}{dx}") deriv.next_to(self.graph_label, DOWN, MED_LARGE_BUFF) deriv.highlight(self.deriv_color) ss_group = self.get_secant_slope_group( 1, self.graph, dx=0.01, secant_line_color=self.deriv_color) self.play(Write(deriv), *map(ShowCreation, ss_group)) self.animate_secant_slope_group_change(ss_group, target_x=self.x3, run_time=5) self.wait() self.animate_secant_slope_group_change(ss_group, target_x=self.x2, run_time=3) self.wait() self.ss_group = ss_group self.deriv = deriv