本文整理汇总了Python中mobject.tex_mobject.TextMobject.next_to方法的典型用法代码示例。如果您正苦于以下问题:Python TextMobject.next_to方法的具体用法?Python TextMobject.next_to怎么用?Python TextMobject.next_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mobject.tex_mobject.TextMobject
的用法示例。
在下文中一共展示了TextMobject.next_to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self):
low_res = ImageMobject("low_resolution_lion", invert = False)
high_res = ImageMobject("Lion", invert = False)
grid = get_grid().scale(0.8)
for mob in low_res, high_res:
mob.replace(grid, stretch = True)
side_brace = Brace(low_res, LEFT)
top_brace = Brace(low_res, UP)
top_words = TextMobject("256 Px", size = "\\normal")
side_words = top_words.copy().rotate(np.pi/2)
top_words.next_to(top_brace, UP)
side_words.next_to(side_brace, LEFT)
self.add(high_res)
self.dither()
self.play(DelayByOrder(Transform(high_res, low_res)))
self.dither()
self.play(
GrowFromCenter(top_brace),
GrowFromCenter(side_brace),
ShimmerIn(top_words),
ShimmerIn(side_words)
)
self.dither()
for mob in grid, high_res:
mob.sort_points(np.linalg.norm)
self.play(DelayByOrder(Transform(high_res, grid)))
self.dither()
示例2: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self):
logo = ImageMobject("LogoGeneration", invert = False)
name_mob = TextMobject("3Blue1Brown").center()
name_mob.highlight("grey")
name_mob.shift(2*DOWN)
self.add(name_mob, logo)
new_text = TextMobject(["with ", "Steven Strogatz"])
new_text.next_to(name_mob, DOWN)
self.play(*[
ShimmerIn(part)
for part in new_text.split()
])
self.dither()
with_word, steve = new_text.split()
steve_copy = steve.copy().center().to_edge(UP)
# logo.sort_points(lambda p : -np.linalg.norm(p))
sort_by_color(logo)
self.play(
Transform(steve, steve_copy),
DelayByOrder(Transform(logo, Point())),
FadeOut(with_word),
FadeOut(name_mob),
run_time = 3
)
示例3: add_title
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def add_title(self, title = "Sample space", buff = MED_SMALL_BUFF):
title_mob = TextMobject(title)
if title_mob.get_width() > self.get_width():
title_mob.scale_to_fit_width(self.get_width())
title_mob.next_to(self.full_space, UP, buff = buff)
self.title = title_mob
self.add(title_mob)
示例4: snells_law_at_every_point
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def snells_law_at_every_point(self, cycloid, chopped_cycloid):
square = Square(side_length = 0.2, color = WHITE)
words = TextMobject(["Snell's law ", "everywhere"])
snells, rest = words.split()
colon = TextMobject(":")
words.next_to(square)
words.shift(0.3*UP)
combo = Mobject(square, words)
combo.get_center = lambda : square.get_center()
new_snells = snells.copy().center().to_edge(UP, buff = 1.5)
colon.next_to(new_snells)
colon.shift(0.05*DOWN)
self.play(MoveAlongPath(
combo, cycloid,
run_time = 5
))
self.play(MoveAlongPath(
combo, chopped_cycloid,
run_time = 4
))
dot = Dot(combo.get_center())
self.play(Transform(square, dot))
self.play(
Transform(snells, new_snells),
Transform(rest, colon)
)
self.dither()
return colon
示例5: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self):
self.knob = Circle(color = BLUE_D)
self.knob.add_line(UP, DOWN)
self.knob.to_corner(UP+RIGHT)
self.knob.shift(0.5*DOWN)
self.last_angle = np.pi/2
arrow = Vector(ORIGIN, RIGHT)
arrow.next_to(self.knob, LEFT)
words = TextMobject("Turn this knob over time to define the curve")
words.next_to(arrow, LEFT)
self.path = self.get_path()
self.path.shift(1.5*DOWN)
self.path.show()
self.path.highlight(BLACK)
randy = Randolph()
randy.scale(RANDY_SCALE_VAL)
randy.shift(-randy.get_bottom())
self.play(ShimmerIn(words))
self.play(ShowCreation(arrow))
self.play(ShowCreation(self.knob))
self.dither()
self.add(self.path)
self.slide(randy, self.path)
self.dither()
示例6: show_pendulum
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def show_pendulum(self, arc_angle = np.pi, arc_color = GREEN):
words = TextMobject(": Instantaneous center of rotation")
words.next_to(self.c_label)
line = Line(self.p_point, self.c_point)
line_angle = line.get_angle()+np.pi
line_length = line.get_length()
line.add(self.p_dot.copy())
line.get_center = lambda : self.c_point
tangent_line = Line(3*LEFT, 3*RIGHT)
tangent_line.rotate(line_angle-np.pi/2)
tangent_line.shift(self.p_point)
tangent_line.highlight(arc_color)
right_angle_symbol = Mobject(
Line(UP, UP+RIGHT),
Line(UP+RIGHT, RIGHT)
)
right_angle_symbol.scale(0.3)
right_angle_symbol.rotate(tangent_line.get_angle()+np.pi)
right_angle_symbol.shift(self.p_point)
self.play(ShowCreation(line))
self.play(ShimmerIn(words))
self.dither()
pairs = [
(line_angle, arc_angle/2),
(line_angle+arc_angle/2, -arc_angle),
(line_angle-arc_angle/2, arc_angle/2),
]
arcs = []
for start, angle in pairs:
arc = Arc(
angle = angle,
radius = line_length,
start_angle = start,
color = GREEN
)
arc.shift(self.c_point)
self.play(
ShowCreation(arc),
ApplyMethod(
line.rotate_in_place,
angle,
path_func = path_along_arc(angle)
),
run_time = 2
)
arcs.append(arc)
self.dither()
self.play(Transform(arcs[1], tangent_line))
self.add(tangent_line)
self.play(ShowCreation(right_angle_symbol))
self.dither()
self.tangent_line = tangent_line
self.right_angle_symbol = right_angle_symbol
self.pc_line = line
self.remove(words, *arcs)
示例7: rearrange
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def rearrange(self):
sqrt_nudge = 0.2*LEFT
y, equals = self.y_equals.split()
d, sin, squared, theta = self.y_expression.split()
y_sqrt = TexMobject("\\sqrt{\\phantom{y}}")
d_sqrt = y_sqrt.copy()
y_sqrt.shift(y.get_center()+sqrt_nudge)
d_sqrt.shift(d.get_center()+sqrt_nudge)
self.play(
ShimmerIn(y_sqrt),
ShimmerIn(d_sqrt),
ApplyMethod(squared.shift, 4*UP),
ApplyMethod(theta.shift, 1.5* squared.get_width()*LEFT)
)
self.dither()
y_sqrt.add(y)
d_sqrt.add(d)
sin.add(theta)
sin_over = TexMobject("\\dfrac{\\phantom{\\sin(\\theta)}}{\\quad}")
sin_over.next_to(sin, DOWN, 0.15)
new_eq = equals.copy()
new_eq.next_to(sin_over, LEFT)
one_over = TexMobject("\\dfrac{1}{\\quad}")
one_over.next_to(new_eq, LEFT)
one_over.shift(
(sin_over.get_bottom()[1]-one_over.get_bottom()[1])*UP
)
self.play(
Transform(equals, new_eq),
ShimmerIn(sin_over),
ShimmerIn(one_over),
ApplyMethod(
d_sqrt.next_to, one_over, DOWN,
path_func = path_along_arc(-np.pi)
),
ApplyMethod(
y_sqrt.next_to, sin_over, DOWN,
path_func = path_along_arc(-np.pi)
),
run_time = 2
)
self.dither()
brace = Brace(d_sqrt, DOWN)
constant = TextMobject("Constant")
constant.next_to(brace, DOWN)
self.play(
GrowFromCenter(brace),
ShimmerIn(constant)
)
示例8: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self, with_words):
CycloidScene.construct(self)
randy = Randolph()
randy.scale(RANDY_SCALE_VAL)
randy.shift(-randy.get_bottom())
central_randy = randy.copy()
start_randy = self.adjust_mobject_to_index(
randy.copy(), 1, self.cycloid.points
)
if with_words:
words1 = TextMobject("Trajectory due to gravity")
arrow = TexMobject("\\leftrightarrow")
words2 = TextMobject("Trajectory due \\emph{constantly} rotating wheel")
words1.next_to(arrow, LEFT)
words2.next_to(arrow, RIGHT)
words = Mobject(words1, arrow, words2)
words.scale_to_fit_width(2*SPACE_WIDTH-1)
words.to_edge(UP, buff = 0.2)
words.to_edge(LEFT)
self.play(ShowCreation(self.cycloid.copy()))
self.slide(randy, self.cycloid)
self.add(self.slider)
self.dither()
self.grow_parts()
self.draw_cycloid()
self.dither()
self.play(Transform(self.slider, start_randy))
self.dither()
self.roll_back()
self.dither()
if with_words:
self.play(*map(ShimmerIn, [words1, arrow, words2]))
self.dither()
self.remove(self.circle)
start_time = len(self.frames)*self.frame_duration
self.remove(self.slider)
self.slide(central_randy, self.cycloid)
end_time = len(self.frames)*self.frame_duration
self.play_over_time_range(
start_time,
end_time,
RollAlongVector(
self.circle,
self.cycloid.points[-1]-self.cycloid.points[0],
run_time = end_time-start_time,
rate_func = None
)
)
self.add(self.circle, self.slider)
self.dither()
示例9: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self):
left_words = TextMobject("Infinite result")
right_words = TextMobject("Finite world")
for words in left_words, right_words:
words.scale(0.8)
left_formula = TexMobject(
"\\sum_{n = 0}^{\\infty} 2^n = -1"
)
right_formula = TexMobject("111\\cdots111")
for formula in left_formula, right_formula:
formula.add(
Brace(formula, UP),
)
formula.ingest_sub_mobjects()
right_overwords = TextMobject(
"\\substack{\
\\text{How computers} \\\\ \
\\text{represent $-1$}\
}"
).scale(1.5)
left_mobs = [left_words, left_formula]
right_mobs = [right_words, right_formula]
for mob in left_mobs:
mob.to_edge(RIGHT, buff = 1)
mob.shift(SPACE_WIDTH*LEFT)
for mob in right_mobs:
mob.to_edge(LEFT, buff = 1)
mob.shift(SPACE_WIDTH*RIGHT)
arrow = Arrow(left_words, right_words)
right_overwords.next_to(right_formula, UP)
self.play(ShimmerIn(left_words))
self.play(ShowCreation(arrow))
self.play(ShimmerIn(right_words))
self.dither()
self.play(
ShimmerIn(left_formula),
ApplyMethod(left_words.next_to, left_formula, UP)
)
self.dither()
self.play(
ShimmerIn(right_formula),
Transform(right_words, right_overwords)
)
self.dither()
self.finite_analog(
Mobject(left_formula, left_words),
arrow,
Mobject(right_formula, right_words)
)
示例10: add_rod_and_ring
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def add_rod_and_ring(self, rod, ring):
rod_word = TextMobject("Rod")
rod_word.next_to(Point(), UP)
ring_word = TextMobject("Ring")
ring_word.next_to(ring, UP)
self.dither()
self.add(rod)
self.play(ShimmerIn(rod_word))
self.dither()
self.remove(rod_word)
self.play(ShowCreation(ring))
self.play(ShimmerIn(ring_word))
self.dither()
self.remove(ring_word)
示例11: finite_analog
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def finite_analog(self, left_mob, arrow, right_mob):
self.clear()
self.add(left_mob, arrow, right_mob)
ex = TextMobject("\\times")
ex.highlight(RED)
# ex.shift(arrow.get_center())
middle = TexMobject(
"\\sum_{n=0}^N 2^n \\equiv -1 \\mod 2^{N+1}"
)
finite_analog = TextMobject("Finite analog")
finite_analog.scale(0.8)
brace = Brace(middle, UP)
finite_analog.next_to(brace, UP)
new_left = left_mob.copy().to_edge(LEFT)
new_right = right_mob.copy().to_edge(RIGHT)
left_arrow, right_arrow = [
Arrow(
mob1.get_right()[0]*RIGHT,
mob2.get_left()[0]*RIGHT,
buff = 0
)
for mob1, mob2 in [
(new_left, middle),
(middle, new_right)
]
]
for mob in ex, middle:
mob.sort_points(np.linalg.norm)
self.play(GrowFromCenter(ex))
self.dither()
self.play(
Transform(left_mob, new_left),
Transform(arrow.copy(), left_arrow),
DelayByOrder(Transform(ex, middle)),
Transform(arrow, right_arrow),
Transform(right_mob, new_right)
)
self.play(
GrowFromCenter(brace),
ShimmerIn(finite_analog)
)
self.dither()
self.equivalence(
left_mob,
left_arrow,
Mobject(middle, brace, finite_analog)
)
示例12: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self):
r_range = np.arange(0.5, 2, 0.25)
cycloids = Mobject(*[
Cycloid(radius = r, end_theta=2*np.pi)
for r in r_range
])
lower_left = 2*DOWN+6*LEFT
lines = Mobject(*[
Line(
lower_left,
lower_left+5*r*np.cos(np.arctan(r))*RIGHT+2*r*np.sin(np.arctan(r))*UP
)
for r in r_range
])
nl = NumberLine(numbers_with_elongated_ticks = [])
x_axis = nl.copy().shift(3*UP)
y_axis = nl.copy().rotate(np.pi/2).shift(6*LEFT)
t_axis = nl.copy().shift(2*DOWN)
x_label = TexMobject("x")
x_label.next_to(x_axis, DOWN)
x_label.to_edge(RIGHT)
y_label = TexMobject("y")
y_label.next_to(y_axis, RIGHT)
y_label.shift(2*DOWN)
t_label = TexMobject("t")
t_label.next_to(t_axis, UP)
t_label.to_edge(RIGHT)
theta_label = TexMobject("\\theta")
theta_label.next_to(y_axis, RIGHT)
theta_label.to_edge(UP)
words = TextMobject("Boundary conditions?")
words.next_to(lines, RIGHT)
words.shift(2*UP)
self.play(ShowCreation(x_axis), ShimmerIn(x_label))
self.play(ShowCreation(y_axis), ShimmerIn(y_label))
self.play(ShowCreation(cycloids))
self.dither()
self.play(
Transform(cycloids, lines),
Transform(x_axis, t_axis),
Transform(x_label, t_label),
Transform(y_label, theta_label),
run_time = 2
)
self.dither()
self.play(ShimmerIn(words))
self.dither()
示例13: setup_axes
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def setup_axes(self, animate = True):
x_num_range = float(self.x_max - self.x_min)
x_axis = NumberLine(
x_min = self.x_min,
x_max = self.x_max,
space_unit_to_num = self.x_axis_width/x_num_range,
tick_frequency = self.x_tick_frequency,
leftmost_tick = self.x_leftmost_tick or self.x_min,
numbers_with_elongated_ticks = self.x_labeled_nums,
color = self.axes_color
)
x_axis.shift(self.graph_origin - x_axis.number_to_point(0))
if self.x_labeled_nums:
x_axis.add_numbers(*self.x_labeled_nums)
x_label = TextMobject(self.x_axis_label)
x_label.next_to(x_axis, RIGHT+UP, buff = SMALL_BUFF)
x_label.shift_onto_screen()
x_axis.add(x_label)
self.x_axis_label_mob = x_label
y_num_range = float(self.y_max - self.y_min)
y_axis = NumberLine(
x_min = self.y_min,
x_max = self.y_max,
space_unit_to_num = self.y_axis_height/y_num_range,
tick_frequency = self.y_tick_frequency,
leftmost_tick = self.y_bottom_tick or self.y_min,
numbers_with_elongated_ticks = self.y_labeled_nums,
color = self.axes_color
)
y_axis.shift(self.graph_origin-y_axis.number_to_point(0))
y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0))
if self.y_labeled_nums:
y_axis.add_numbers(*self.y_labeled_nums)
y_axis.numbers.shift(self.y_axis_numbers_nudge)
y_label = TextMobject(self.y_axis_label)
y_label.next_to(y_axis.get_top(), RIGHT, buff = 2*MED_BUFF)
y_label.shift_onto_screen()
y_axis.add(y_label)
self.y_axis_label_mob = y_label
if animate:
self.play(Write(VGroup(x_axis, y_axis)))
else:
selfe.add(x_axis, y_axis_label)
self.x_axis, self.y_axis = x_axis, y_axis
示例14: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self):
curve = PeanoCurve(order = 5)
curve.stretch_to_fit_width(2*SPACE_WIDTH)
curve.stretch_to_fit_height(2*SPACE_HEIGHT)
curve_start = curve.copy()
curve_start.apply_over_attr_arrays(
lambda arr : arr[:200]
)
time_line = get_time_line()
time_line.shift(-time_line.number_to_point(2000))
self.add(time_line)
self.play(ApplyMethod(
time_line.shift,
-time_line.number_to_point(1900),
run_time = 3
))
brace = Brace(
Mobject(
Point(time_line.number_to_point(1865)),
Point(time_line.number_to_point(1888)),
),
UP
)
words = TextMobject("""
Cantor drives himself (and the \\\\
mathematical community at large) \\\\
crazy with research on infinity.
""")
words.next_to(brace, UP)
self.play(
GrowFromCenter(brace),
ShimmerIn(words)
)
self.dither()
self.play(
Transform(time_line, curve_start),
FadeOut(brace),
FadeOut(words)
)
self.play(ShowCreation(
curve,
run_time = 5,
rate_func = None
))
self.dither()
示例15: construct
# 需要导入模块: from mobject.tex_mobject import TextMobject [as 别名]
# 或者: from mobject.tex_mobject.TextMobject import next_to [as 别名]
def construct(self):
kwargs = {"size" : "\\Large"}
left = TextMobject("Speed of light is constant", **kwargs)
arrow = TexMobject("\\Rightarrow", **kwargs)
right = TextMobject("Staight path is fastest", **kwargs)
left.next_to(arrow, LEFT)
right.next_to(arrow, RIGHT)
squaggle, line = self.get_paths()
self.play(*map(ShimmerIn, [left, arrow, right]))
self.play(ShowCreation(squaggle))
self.play(self.photon_run_along_path(
squaggle, run_time = 2, rate_func = None
))
self.play(Transform(
squaggle, line,
path_func = path_along_arc(np.pi)
))
self.play(self.photon_run_along_path(line, rate_func = None))
self.dither()