DecimalNumber¶
限定名称: manim.mobject.text.numbers.DecimalNumber
- class DecimalNumber(number=0, num_decimal_places=2, mob_class=<class 'manim.mobject.text.tex_mobject.MathTex'>, include_sign=False, group_with_commas=True, digit_buff_per_font_unit=0.001, show_ellipsis=False, unit=None, unit_buff_per_font_unit=0, include_background_rectangle=False, edge_to_fix=array([-1., 0., 0.]), font_size=48, stroke_width=0, fill_opacity=1.0, **kwargs)[源代码]¶
基类:
VMobject
表示十进制数的 Mobject。
- 参数:
number (float) – 要显示的数值。它可以使用
set_value()
稍后修改。num_decimal_places (int) – 小数点后的位数。数值会自动四舍五入。
include_sign (bool) – 设置为
True
以包含正数和零的符号。group_with_commas (bool) – 当
True
时,千位组用逗号分隔,以提高可读性。digit_buff_per_font_unit (float) – 数字之间的额外间距。与字体大小成比例缩放。
show_ellipsis (bool) – 当数字因四舍五入被截断时,用省略号 (
...
) 表示。unit (str | None) – 可放置在数值右侧的单位字符串。
unit_buff_per_font_unit (float) – 数值与单位之间的额外间距。值为
unit_buff_per_font_unit=0.003
可提供合适的间距。与字体大小成比例缩放。include_background_rectangle (bool) – 添加背景矩形以在繁忙场景中增加对比度。
edge_to_fix (Sequence[float]) – 确保完整对象的右对齐或左对齐。
font_size (float) – 字体大小。
stroke_width (浮点数)
fill_opacity (float)
示例
示例: MovingSquareWithUpdaters ¶
from manim import * class MovingSquareWithUpdaters(Scene): def construct(self): decimal = DecimalNumber( 0, show_ellipsis=True, num_decimal_places=3, include_sign=True, unit=r"\text{M-Units}", unit_buff_per_font_unit=0.003 ) square = Square().to_edge(UP) decimal.add_updater(lambda d: d.next_to(square, RIGHT)) decimal.add_updater(lambda d: d.set_value(square.get_center()[1])) self.add(square, decimal) self.play( square.animate.to_edge(DOWN), rate_func=there_and_back, run_time=5, ) self.wait()
class MovingSquareWithUpdaters(Scene): def construct(self): decimal = DecimalNumber( 0, show_ellipsis=True, num_decimal_places=3, include_sign=True, unit=r"\text{M-Units}", unit_buff_per_font_unit=0.003 ) square = Square().to_edge(UP) decimal.add_updater(lambda d: d.next_to(square, RIGHT)) decimal.add_updater(lambda d: d.set_value(square.get_center()[1])) self.add(square, decimal) self.play( square.animate.to_edge(DOWN), rate_func=there_and_back, run_time=5, ) self.wait()
方法
get_value
increment_value
将
DecimalNumber
的值设置为新数字。属性
animate (动画)
用于动画化
self
的任何方法的应用。animation_overrides (动画覆盖)
颜色
depth (深度)
mobject 的深度。
fill_color (填充颜色)
如果存在多种颜色(用于渐变),则返回第一种颜色
tex mobject 的字体大小。
height (高度)
mobject 的高度。
n_points_per_curve (每条曲线的点数)
sheen_factor (光泽因子)
stroke_color (描边颜色)
width (宽度)
mobject 的宽度。
- _get_formatter(**kwargs)[源代码]¶
配置首先基于实例属性,但会被任何关键字参数覆盖。相关关键字: - include_sign - group_with_commas - num_decimal_places - field_name(例如 0 或 0.real)
- _original__init__(number=0, num_decimal_places=2, mob_class=<class 'manim.mobject.text.tex_mobject.MathTex'>, include_sign=False, group_with_commas=True, digit_buff_per_font_unit=0.001, show_ellipsis=False, unit=None, unit_buff_per_font_unit=0, include_background_rectangle=False, edge_to_fix=array([-1., 0., 0.]), font_size=48, stroke_width=0, fill_opacity=1.0, **kwargs)¶
初始化自身。有关准确签名,请参阅 help(type(self))。
- 参数:
number (float)
num_decimal_places (int)
mob_class (VMobject)
include_sign (bool)
group_with_commas (bool)
digit_buff_per_font_unit (float)
show_ellipsis (bool)
unit (str | None)
unit_buff_per_font_unit (float)
include_background_rectangle (bool)
edge_to_fix (Sequence[float])
font_size (float)
stroke_width (浮点数)
fill_opacity (float)
- property font_size¶
tex mobject 的字体大小。
- set_value(number)[源代码]¶
将
DecimalNumber
的值设置为新数字。- 参数:
number (float) – 将覆盖
DecimalNumber
当前值的数值。