十进制数

限定名称: 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)[source]

基础类: VMobject

一个表示十进制数的对象。

Parameters:
  • number (float) – 要显示的数值。稍后可以使用 set_value() 进行修改。

  • num_decimal_places (int) – 小数点后的位数。值会自动四舍五入。

  • mob_class (VMobject) – 用于渲染数字和单位的类,默认为 MathTex

  • 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 (float)

  • 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"     ext{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"     ext{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

set_value

DecimalNumber的值设置为一个新数字。

属性

animate

用于动画化self的任何方法的应用。

animation_overrides

color

depth

mobject的深度。

fill_color

如果有多种颜色(用于渐变),则返回第一个颜色

font_size

tex mobject 的字体大小。

height

mobject的高度。

n_points_per_curve

sheen_factor

stroke_color

width

mobject的宽度。

_get_formatter(**kwargs)[source]

配置首先基于实例属性,但会被任何关键字参数覆盖。相关的关键字: - 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))。

Parameters:
  • 数字 (浮点数)

  • num_decimal_places (int)

  • mob_class (VMobject)

  • include_sign (bool)

  • group_with_commas (bool)

  • digit_buff_per_font_unit (float)

  • show_ellipsis (bool)

  • 单位 (str | None)

  • unit_buff_per_font_unit (float)

  • include_background_rectangle (bool)

  • edge_to_fix (序列[浮点数])

  • font_size (float)

  • stroke_width (float)

  • fill_opacity (float)

property font_size

tex mobject 的字体大小。

set_value(number)[source]

DecimalNumber的值设置为一个新数字。

Parameters:

number (float) – 将覆盖DecimalNumber当前数字的值。