本文整理汇总了Python中mobject.tex_mobject.TexMobject.move_to方法的典型用法代码示例。如果您正苦于以下问题:Python TexMobject.move_to方法的具体用法?Python TexMobject.move_to怎么用?Python TexMobject.move_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mobject.tex_mobject.TexMobject
的用法示例。
在下文中一共展示了TexMobject.move_to方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_polygons
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
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
))
示例2: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
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()
示例3: show_symbolic_sum
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
def show_symbolic_sum(self, new_array, vector):
new_mob = TexMobject([
"(%d)\\hat{\\imath}"%self.vector_coords[0],
"+",
"(%d)\\hat{\\jmath}"%self.vector_coords[1]
])
new_mob.move_to(new_array)
new_mob.shift_onto_screen()
i_hat, plus, j_hat = new_mob.split()
i_hat.highlight(X_COLOR)
j_hat.highlight(Y_COLOR)
self.play(Transform(new_array, new_mob))
self.dither()
示例4: write_second_derivative
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
def write_second_derivative(self):
ddf_over_dx_squared = TexMobject(
"{d(df)", "\\over", "(dx)^2}"
)
ddf_over_dx_squared.scale(0.8)
ddf_over_dx_squared.move_to(self.ddf, RIGHT)
ddf_over_dx_squared.highlight_by_tex("df", self.ddf.get_color())
parens = VGroup(
ddf_over_dx_squared[0][1],
ddf_over_dx_squared[0][4],
ddf_over_dx_squared[2][0],
ddf_over_dx_squared[2][3],
)
right_shifter = ddf_over_dx_squared[0][0]
left_shifter = ddf_over_dx_squared[2][4]
exp_two = TexMobject("2")
exp_two.highlight(self.ddf.get_color())
exp_two.scale(0.5)
exp_two.move_to(right_shifter.get_corner(UP+RIGHT), LEFT)
exp_two.shift(MED_SMALL_BUFF*RIGHT)
pre_exp_two = VGroup(ddf_over_dx_squared[0][2])
self.play(
Write(ddf_over_dx_squared.get_part_by_tex("over")),
*[
ReplacementTransform(
mob,
ddf_over_dx_squared.get_part_by_tex(tex),
path_arc = -np.pi/2,
)
for mob, tex in (self.ddf, "df"), (self.dx_squared, "dx")
]
)
self.dither(2)
self.play(FadeOut(parens))
self.play(
left_shifter.shift, 0.2*LEFT,
right_shifter.shift, 0.2*RIGHT,
ReplacementTransform(pre_exp_two, exp_two),
ddf_over_dx_squared.get_part_by_tex("over").scale_in_place, 0.8
)
self.dither(2)
示例5: let_one_day_pass
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
def let_one_day_pass(self, run_time = 2):
all_creatures = self.get_pi_creatures()
on_screen_creatures = self.get_on_screen_pi_creatures()
low_i = len(on_screen_creatures)
high_i = min(2*low_i, len(all_creatures))
new_creatures = VGroup(*all_creatures[low_i:high_i])
to_children_anims = []
growing_anims = []
for old_pi, pi in zip(on_screen_creatures, new_creatures):
pi.save_state()
child = pi.copy()
child.scale(0.25, about_point = child.get_bottom())
child.eyes.scale(1.5, about_point = child.eyes.get_bottom())
pi.move_to(old_pi)
pi.set_fill(opacity = 0)
index = list(new_creatures).index(pi)
prop = float(index)/len(new_creatures)
alpha = np.clip(len(new_creatures)/8.0, 0, 0.5)
rate_func = squish_rate_func(
smooth, alpha*prop, alpha*prop+(1-alpha)
)
to_child_anim = Transform(pi, child, rate_func = rate_func)
to_child_anim.update(1)
growing_anim = ApplyMethod(pi.restore, rate_func = rate_func)
to_child_anim.update(0)
to_children_anims.append(to_child_anim)
growing_anims.append(growing_anim)
time = self.t_expression[-1]
total_new_creatures = len(on_screen_creatures) + len(new_creatures)
new_time = TexMobject(str(int(np.log2(total_new_creatures))))
new_time.move_to(time, LEFT)
growing_anims.append(Transform(time, new_time))
self.play(*to_children_anims, run_time = run_time/2.0)
self.play(*growing_anims, run_time = run_time/2.0)
示例6: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
def construct(self):
tri1 = VGroup(
Line(ORIGIN, 2*RIGHT, color = BLUE),
Line(2*RIGHT, 3*UP, color = YELLOW),
Line(3*UP, ORIGIN, color = MAROON_B),
)
tri1.shift(2.5*(DOWN+LEFT))
tri2, tri3, tri4 = copies = [
tri1.copy().rotate(-i*np.pi/2)
for i in range(1, 4)
]
a = TexMobject("a").next_to(tri1[0], DOWN, buff = MED_BUFF)
b = TexMobject("b").next_to(tri1[2], LEFT, buff = MED_BUFF)
c = TexMobject("c").next_to(tri1[1].get_center(), UP+RIGHT)
c_square = Polygon(*[
tri[1].get_end()
for tri in [tri1] + copies
])
c_square.set_stroke(width = 0)
c_square.set_fill(color = YELLOW, opacity = 0.5)
c_square_tex = TexMobject("c^2")
big_square = Polygon(*[
tri[0].get_start()
for tri in [tri1] + copies
])
big_square.highlight(WHITE)
a_square = Square(side_length = 2)
a_square.shift(1.5*(LEFT+UP))
a_square.set_stroke(width = 0)
a_square.set_fill(color = BLUE, opacity = 0.5)
a_square_tex = TexMobject("a^2")
a_square_tex.move_to(a_square)
b_square = Square(side_length = 3)
b_square.move_to(
a_square.get_corner(DOWN+RIGHT),
aligned_edge = UP+LEFT
)
b_square.set_stroke(width = 0)
b_square.set_fill(color = MAROON_B, opacity = 0.5)
b_square_tex = TexMobject("b^2")
b_square_tex.move_to(b_square)
self.play(ShowCreation(tri1, run_time = 2))
self.play(*map(Write, [a, b, c]))
self.dither()
self.play(
FadeIn(c_square),
Animation(c)
)
self.play(Transform(c, c_square_tex))
self.dither(2)
mover = tri1.copy()
for copy in copies:
self.play(Transform(
mover, copy,
path_arc = -np.pi/2
))
self.add(copy)
self.remove(mover)
self.add(big_square, *[tri1]+copies)
self.dither(2)
self.play(*map(FadeOut, [a, b, c, c_square]))
self.play(
tri3.shift,
tri1.get_corner(UP+LEFT) -\
tri3.get_corner(UP+LEFT)
)
self.play(tri2.shift, 2*RIGHT)
self.play(tri4.shift, 3*UP)
self.dither()
self.play(FadeIn(a_square))
self.play(FadeIn(b_square))
self.play(Write(a_square_tex))
self.play(Write(b_square_tex))
self.dither(2)
示例7: construct
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
def construct(self):
base_str = self.base_str
func_def = TexMobject("M(", "t", ")", "= ", "%s^"%base_str, "t")
func_def.to_corner(UP+LEFT)
self.add(func_def)
ratio = TexMobject(
"{ {%s^"%base_str, "{t", "+", "dt}", "-",
"%s^"%base_str, "t}",
"\\over \\,", "dt}"
)
ratio.shift(UP+LEFT)
lhs = TexMobject("{dM", "\\over \\,", "dt}", "(", "t", ")", "=")
lhs.next_to(ratio, LEFT)
two_to_t_plus_dt = VGroup(*ratio[:4])
two_to_t = VGroup(*ratio[5:7])
two_to_t_two_to_dt = TexMobject(
"%s^"%base_str, "t",
"%s^"%base_str, "{dt}"
)
two_to_t_two_to_dt.move_to(two_to_t_plus_dt, DOWN+LEFT)
exp_prop_brace = Brace(two_to_t_two_to_dt, UP)
one = TexMobject("1")
one.move_to(ratio[5], DOWN)
lp, rp = parens = TexMobject("()")
parens.stretch(1.3, 1)
parens.scale_to_fit_height(ratio.get_height())
lp.next_to(ratio, LEFT, buff = 0)
rp.next_to(ratio, RIGHT, buff = 0)
extracted_two_to_t = TexMobject("%s^"%base_str, "t")
extracted_two_to_t.next_to(lp, LEFT, buff = SMALL_BUFF)
expressions = [
ratio, two_to_t_two_to_dt,
extracted_two_to_t, lhs, func_def
]
for expression in expressions:
expression.highlight_by_tex("t", YELLOW)
expression.highlight_by_tex("dt", GREEN)
#Apply exponential property
self.play(
Write(ratio), Write(lhs),
self.pi_creature.change_mode, "raise_right_hand"
)
self.dither(2)
self.play(
two_to_t_plus_dt.next_to, exp_prop_brace, UP,
self.pi_creature.change_mode, "pondering"
)
self.play(
ReplacementTransform(
two_to_t_plus_dt.copy(), two_to_t_two_to_dt,
run_time = 2,
path_arc = np.pi,
),
FadeIn(exp_prop_brace)
)
self.dither(2)
#Talk about exponential property
add_exp_rect, mult_rect = rects = [
Rectangle(
stroke_color = BLUE,
stroke_width = 2,
).replace(mob).scale_in_place(1.1)
for mob in [
VGroup(*two_to_t_plus_dt[1:]),
two_to_t_two_to_dt
]
]
words = VGroup(*[
TextMobject(s, " ideas")
for s in "Additive", "Multiplicative"
])
words[0].move_to(words[1], LEFT)
words.highlight(BLUE)
words.next_to(two_to_t_plus_dt, RIGHT, buff = 1.5*LARGE_BUFF)
arrows = VGroup(*[
Arrow(word.get_left(), rect, color = words.get_color())
for word, rect in zip(words, rects)
])
self.play(ShowCreation(add_exp_rect))
self.dither()
self.play(ReplacementTransform(
add_exp_rect.copy(), mult_rect
))
self.dither()
self.change_mode("happy")
self.play(Write(words[0], run_time = 2))
self.play(ShowCreation(arrows[0]))
self.dither()
self.play(
#.........这里部分代码省略.........
示例8: relate_growth_rate_to_pop_size
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import move_to [as 别名]
def relate_growth_rate_to_pop_size(self):
false_deriv = TexMobject(
"{d(2^t) ", "\\over dt}", "= 2^t"
)
difference_eq = TexMobject(
"{ {2^{t+1} - 2^t} \\over", "1}", "= 2^t"
)
real_deriv = TexMobject(
"{ {2^{t+dt} - 2^t} \\over", "dt}", "= \\, ???"
)
VGroup(
false_deriv[0][3],
false_deriv[2][-1],
difference_eq[0][1],
difference_eq[0][-2],
difference_eq[2][-1],
difference_eq[2][-1],
real_deriv[0][1],
real_deriv[0][-2],
).highlight(YELLOW)
VGroup(
difference_eq[0][3],
difference_eq[1][-1],
real_deriv[0][3],
real_deriv[0][4],
real_deriv[1][-2],
real_deriv[1][-1],
).highlight(GREEN)
expressions = [false_deriv, difference_eq, real_deriv]
text_arg_list = [
("Tempting", "...",),
("Rate of change", "\\\\ over one full day"),
("Rate of change", "\\\\ in a small time"),
]
for expression, text_args in zip(expressions, text_arg_list):
expression.next_to(
self.function, DOWN,
buff = LARGE_BUFF,
aligned_edge = LEFT,
)
expression.brace = Brace(expression, DOWN)
expression.brace_text = expression.brace.get_text(*text_args)
time = self.t_expression[-1]
new_time = TexMobject("3")
new_time.move_to(time, LEFT)
fading_creatures = VGroup(*self.get_on_screen_pi_creatures()[8:])
self.play(*map(FadeIn, [
false_deriv, false_deriv.brace, false_deriv.brace_text
]))
self.dither()
self.play(
Transform(time, new_time),
FadeOut(fading_creatures)
)
self.dither()
for x in range(3):
self.let_one_day_pass(run_time = 2)
self.dither(2)
for expression in difference_eq, real_deriv:
expression.brace_text[1].highlight(GREEN)
self.play(
Transform(false_deriv, expression),
Transform(false_deriv.brace, expression.brace),
Transform(false_deriv.brace_text, expression.brace_text),
)
self.dither(3)
self.reset()
for x in range(self.get_num_days()):
self.let_one_day_pass()
self.dither()
rect = Rectangle(color = YELLOW)
rect.replace(real_deriv)
rect.stretch_to_fit_width(rect.get_width()+MED_SMALL_BUFF)
rect.stretch_to_fit_height(rect.get_height()+MED_SMALL_BUFF)
self.play(*map(FadeOut, [
false_deriv.brace, false_deriv.brace_text
]))
self.play(ShowCreation(rect))
self.play(*[
ApplyFunction(
lambda pi : pi.change_mode("pondering").look_at(real_deriv),
pi,
run_time = 2,
rate_func = squish_rate_func(smooth, a, a+0.5)
)
for pi in self.get_pi_creatures()
for a in [0.5*random.random()]
])
self.dither(3)