本文整理汇总了Python中mobject.tex_mobject.TexMobject.highlight方法的典型用法代码示例。如果您正苦于以下问题:Python TexMobject.highlight方法的具体用法?Python TexMobject.highlight怎么用?Python TexMobject.highlight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mobject.tex_mobject.TexMobject
的用法示例。
在下文中一共展示了TexMobject.highlight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_graph_label
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
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
示例2: get_vector_label
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
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
示例3: show_derivative
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
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
示例4: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
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()
示例5: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def construct(self):
top1, top2, top3 = old_tops = [
TOP(None, s, "8")
for s in "x", "y", TexMobject("x?y")
]
q_mark = TexMobject("?").scale(2)
equation = VMobject(
top1, q_mark, top2, TexMobject("="), top3
)
equation.arrange_submobjects(buff = 0.7)
symbols_at_top = VMobject(*[
top.values[1]
for top in top1, top2, top3
])
symbols_at_lower_right = VMobject(*[
top.put_on_vertex(0, top.values[1].copy())
for top in top1, top2, top3
])
old_style_eq1 = TexMobject("\\sqrt[x]{8} ? \\sqrt[y]{8} = \\sqrt[x?y]{8}")
old_style_eq1.highlight(BLUE)
old_style_eq2 = TexMobject("\\log_x(8) ? \\log_y(8) = \\log_{x?y}(8)")
old_style_eq2.highlight(YELLOW)
for eq in old_style_eq1, old_style_eq2:
eq.to_edge(UP)
randy = Randolph()
randy.to_corner()
bubble = ThoughtBubble().pin_to(randy)
bubble.add_content(TOP(None, None, "8"))
self.add(randy, bubble)
self.play(ApplyMethod(randy.change_mode, "pondering"))
self.dither(3)
triangle = bubble.content.triangle
eight = bubble.content.values[2]
bubble.clear()
self.play(
Transform(triangle, equation),
FadeOut(eight),
ApplyPointwiseFunction(
lambda p : (p+2*DOWN)*15/np.linalg.norm(p+2*DOWN),
bubble
),
FadeIn(old_style_eq1),
ApplyMethod(randy.shift, 3*DOWN + 3*LEFT),
run_time = 2
)
self.remove(triangle)
self.add(equation)
self.dither(4)
self.play(
Transform(
symbols_at_top, symbols_at_lower_right,
path_arc = np.pi/2
),
Transform(old_style_eq1, old_style_eq2)
)
self.dither(2)
示例6: get_theta_group
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def get_theta_group(self):
arc = Arc(
self.theta_value,
radius = self.arc_radius,
color = self.theta_color,
)
theta = TexMobject("\\theta")
theta.shift(1.5*arc.point_from_proportion(0.5))
theta.highlight(self.theta_color)
theta.scale_to_fit_height(self.theta_height)
line = Line(ORIGIN, self.get_circle_point())
dot = Dot(line.get_end(), radius = 0.05)
return VGroup(line, arc, theta, dot)
示例7: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def construct(self):
v_mob = TexMobject(get_vect_tex("v"))
v_mob.highlight(V_COLOR)
matrix = Matrix([self.vect_coords])
vector = Matrix(self.vect_coords)
matrix.highlight_columns(X_COLOR, Y_COLOR)
vector.highlight_columns(YELLOW)
_input = Matrix(["x", "y"])
_input.get_entries().gradient_highlight(X_COLOR, Y_COLOR)
left_input, right_input = [_input.copy() for x in range(2)]
dot, equals = map(TexMobject, ["\\cdot", "="])
equation = Group(
vector, dot, left_input, equals,
matrix, right_input
)
equation.arrange_submobjects()
left_brace = Brace(Group(vector, left_input))
right_brace = Brace(matrix, UP)
left_words = left_brace.get_text("Dot product")
right_words = right_brace.get_text("Transform")
right_words.scale_to_fit_width(right_brace.get_width())
right_v_brace = Brace(right_input, UP)
right_v_mob = v_mob.copy()
right_v_brace.put_at_tip(right_v_mob)
right_input.add(right_v_brace, right_v_mob)
left_v_brace = Brace(left_input, UP)
left_v_mob = v_mob.copy()
left_v_brace.put_at_tip(left_v_mob)
left_input.add(left_v_brace, left_v_mob)
self.add(matrix, right_input)
self.play(
GrowFromCenter(right_brace),
Write(right_words, run_time = 1)
)
self.dither()
self.play(
Write(equals),
Write(dot),
Transform(matrix.copy(), vector),
Transform(right_input.copy(), left_input)
)
self.play(
GrowFromCenter(left_brace),
Write(left_words, run_time = 1)
)
self.dither()
示例8: get_number_mob
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def get_number_mob(self, num):
result = VGroup()
place = 0
max_place = self.max_place
while place < max_place:
digit = TexMobject(str(self.get_place_num(num, place)))
if place >= len(self.digit_place_colors):
self.digit_place_colors += self.digit_place_colors
digit.highlight(self.digit_place_colors[place])
digit.scale(self.num_scale_factor)
digit.next_to(result, LEFT, buff = SMALL_BUFF, aligned_edge = DOWN)
result.add(digit)
place += 1
return result
示例9: show_dfs
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def show_dfs(self):
dx_lines = VGroup()
df_lines = VGroup()
df_dx_groups = VGroup()
df_labels = VGroup()
for i, v_line1, v_line2 in zip(it.count(1), self.v_lines, self.v_lines[1:]):
dx_line = Line(
v_line1.get_bottom(),
v_line2.get_bottom(),
color = GREEN
)
dx_line.move_to(v_line1.get_top(), LEFT)
dx_lines.add(dx_line)
df_line = Line(
dx_line.get_right(),
v_line2.get_top(),
color = YELLOW
)
df_lines.add(df_line)
df_label = TexMobject("df_%d"%i)
df_label.highlight(YELLOW)
df_label.scale(0.8)
df_label.next_to(df_line.get_center(), UP+LEFT, MED_LARGE_BUFF)
df_arrow = Arrow(
df_label.get_bottom(),
df_line.get_center(),
buff = SMALL_BUFF,
)
df_line.label = df_label
df_line.arrow = df_arrow
df_labels.add(df_label)
df_dx_groups.add(VGroup(df_line, dx_line))
for brace, dx_line, df_line in zip(self.braces, dx_lines, df_lines):
self.play(
VGroup(brace, brace.dx).next_to,
dx_line, DOWN, SMALL_BUFF,
FadeIn(dx_line),
)
self.play(ShowCreation(df_line))
self.play(
ShowCreation(df_line.arrow),
Write(df_line.label)
)
self.dither(2)
self.df_dx_groups = df_dx_groups
self.df_labels = df_labels
示例10: write_second_derivative
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
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.dither()
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
示例11: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def construct(self):
v = TexMobject("\\vec{\\textbf{v}}")
v.highlight(YELLOW)
nums = map(TexMobject, ["2", "\\dfrac{1}{3}", "-1.8"])
for mob in [v] + nums:
mob.scale(1.5)
self.play(Write(v, run_time = 1))
last = None
for num in nums:
num.next_to(v, LEFT)
if last:
self.play(Transform(last, num))
else:
self.play(FadeIn(num))
last = num
self.dither()
示例12: label_graph
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def label_graph(self, graph, label = "f(x)",
proportion = 0.7,
direction = LEFT,
buff = 2*MED_BUFF,
animate = True
):
label = TexMobject(label)
label.highlight(graph.get_color())
label.next_to(
graph.point_from_proportion(proportion),
direction,
buff = buff
)
if animate:
self.play(Write(label))
self.add(label)
return label
示例13: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
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()
示例14: full_time
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def full_time(self, morty):
new_title = TextMobject("Full time")
new_title.move_to(self.screen_title)
q_mark = TexMobject("?")
q_mark.next_to(self.cross)
q_mark.highlight(GREEN)
self.play(morty.look_at, q_mark)
self.play(Transform(self.screen_title, new_title))
self.play(
Transform(self.cross, q_mark),
morty.change_mode, "confused"
)
self.play(Blink(morty))
self.dither()
self.play(
morty.change_mode, "happy",
morty.look, UP+RIGHT
)
self.play(Blink(morty))
self.dither()
示例15: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import highlight [as 别名]
def construct(self):
assyms_of_top = VMobject(
TextMobject("Asymmetries of "),
TOP("a", "b", "c", radius = 0.75).highlight(BLUE)
).arrange_submobjects()
assyms_of_top.to_edge(UP)
assyms_of_math = TextMobject("""
Asymmetries of
$\\underbrace{a \\cdot a \\cdots a}_{\\text{$b$ times}} = c$
""")
VMobject(*assyms_of_math.split()[13:]).highlight(YELLOW)
assyms_of_math.next_to(assyms_of_top, DOWN, buff = 2)
rad = TexMobject("\\sqrt{\\quad}").to_edge(LEFT).shift(UP)
rad.highlight(RED)
log = TexMobject("\\log").next_to(rad, DOWN)
log.highlight(RED)
self.play(FadeIn(assyms_of_top))
self.dither()
self.play(FadeIn(assyms_of_math))
self.dither()
self.play(Write(VMobject(rad, log)))
self.dither()