本文整理汇总了Python中mobject.tex_mobject.TexMobject.get_width方法的典型用法代码示例。如果您正苦于以下问题:Python TexMobject.get_width方法的具体用法?Python TexMobject.get_width怎么用?Python TexMobject.get_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mobject.tex_mobject.TexMobject
的用法示例。
在下文中一共展示了TexMobject.get_width方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_points
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import get_width [as 别名]
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
示例2: get_number_mobjects
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import get_width [as 别名]
def get_number_mobjects(self, *numbers):
# TODO, handle decimals
if len(numbers) == 0:
numbers = self.default_numbers_to_display()
result = []
for number in numbers:
mob = TexMobject(str(int(number)))
vert_scale = 2 * self.tick_size / mob.get_height()
hori_scale = self.tick_frequency * self.unit_length_to_spatial_width / mob.get_width()
mob.scale(min(vert_scale, hori_scale))
mob.shift(self.number_to_point(number))
mob.shift(self.get_vertical_number_offset())
result.append(mob)
return result
示例3: generate_n_choose_k_mobs
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import get_width [as 别名]
def generate_n_choose_k_mobs(self):
self.coords_to_n_choose_k = {}
for n, k in self.coords:
nck_mob = TexMobject(r"{%d \choose %d}"%(n, k))
scale_factor = min(
1,
self.portion_to_fill * self.cell_height / nck_mob.get_height(),
self.portion_to_fill * self.cell_width / nck_mob.get_width(),
)
center = self.coords_to_mobs[n][k].get_center()
nck_mob.center().scale(scale_factor).shift(center)
if n not in self.coords_to_n_choose_k:
self.coords_to_n_choose_k[n] = {}
self.coords_to_n_choose_k[n][k] = nck_mob
return self
示例4: scale_vector
# 需要导入模块: from mobject.tex_mobject import TexMobject [as 别名]
# 或者: from mobject.tex_mobject.TexMobject import get_width [as 别名]
def scale_vector(self, v, factor, v_label,
v_name = "v", factor_tex = None):
starting_mobjects = list(self.mobjects)
if factor_tex is None:
factor_tex = str(factor)
scaled_vector = self.add_vector(
factor*v.get_end(), animate = False
)
self.remove(scaled_vector)
label_tex = "%s\\vec{\\textbf{%s}}"%(factor_tex, v_name)
label = self.label_vector(
scaled_vector, label_tex, animate = False,
add_to_vector = False
)
self.remove(label)
factor_mob = TexMobject(factor_tex)
if factor_mob.get_height() > 1:
factor_mob.scale_to_fit_height(0.9)
if factor_mob.get_width() > 1:
factor_mob.scale_to_fit_width(0.9)
factor_mob.shift(1.5*RIGHT+2.5*UP)
num_factor_parts = len(factor_mob.split())
factor_mob_parts_in_label = label.split()[:num_factor_parts]
label_remainder_parts = label.split()[num_factor_parts:]
factor_in_label = VMobject(*factor_mob_parts_in_label)
label_remainder = VMobject(*label_remainder_parts)
self.play(Write(factor_mob, run_time = 1))
self.dither()
self.play(
ApplyMethod(v.copy().highlight, DARK_GREY),
ApplyMethod(v_label.copy().highlight, DARK_GREY),
Transform(factor_mob, factor_in_label),
Transform(v.copy(), scaled_vector),
Transform(v_label.copy(), label_remainder),
)
self.dither(2)
self.clear()
self.add(*starting_mobjects)