DecimalNumber

Qualified name: algan.mobs.numeric\_display.DecimalNumber

class DecimalNumber(value, decimal_places=2, integer_places=None, **kwargs)[source]

Bases: Mob

A number drawn on screen, which counts when you assign to it.

value is an animatable attribute, so counter.value = 100 is recorded like a move or a color change and the display counts from wherever it was to 100 over the surrounding context’s runtime. The glyphs are re-typeset each frame rather than morphed into one another, which is what makes 7 become 8 rather than bending into it.

The number is laid out to a fixed width from decimal_places and integer_places, so it does not jitter sideways as digits come and go. Leading-digit slots are added automatically when the value outgrows them.

Animation

Constructing one records nothing; the Mob joins the active Scene unspawned, and spawn() makes it appear. Assigning to value afterwards is recorded and interpolates from the current value over the current context’s runtime (1 second by default) – with Seq(runtime=3): counter.value = 100 to change that, or with Off(): to jump.

Parameters:
  • value – The number shown at construction.

  • decimal_places – Digits after the decimal point. Defaults to 2; 0 shows no decimal point at all.

  • integer_places – Minimum digits before the decimal point. Defaults to None, meaning take it from value (at least 1). More are allocated automatically when the value grows past the reserved width.

  • **kwargs – Passed to Tex, which typesets the digits – notably color and font_size – and on to Mob.

value

The number displayed, shape (*, 1). Assigning to it records a counting animation.

Examples

A counter that runs from 0 to 50 over two seconds:

Example: Example1DecimalNumber

from algan import *

counter = DecimalNumber(0, decimal_places=1).spawn()
with Seq(runtime=2):
    counter.value = 50

Scene.save_video()

Methods

get_value

on_create

Play this Mob's spawn-in animation: a fade from transparent.

set_value

update_display

Attributes

animation_manager

This mob's scene-owned animation manager.

basis

The Mob's orientation and scale, as a flattened 3x3 matrix of shape (*, 9).

casts_shadows

Whether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.

children

The Mobs attached below this one, in attachment order.

closed_shell

Whether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.

draws_descendants

Whether get_render_primitives returns geometry belonging to this Mob's DESCENDANTS as well as its own.

forward

Get the direction the Mob is facing.

lifespan

This mob's [spawn, despawn) interval on its Scene timeline (a Lifespan).

location

The Mob's position in world space, shape (*, 3).

normalized_basis

The Mob's orientation with scale divided out, shape (*, 9).

parents

The Mobs this one is attached to, in attachment order.

receives_shadows

Whether this Mob's surfaces are darkened by shadows cast onto them.

right

Get the Mob's own rightward direction.

scale_coefficient

The Mob's scale along its own right, up and forward axes, shape (*, 3).

two_sided

Whether this Mob's geometry should be lit from whichever side the ray arrives on.

up

Get the Mob's own upward direction.

value

x

The Mob's x coordinate in world units, shape (*, 1).

xy

The Mob's x and y coordinates in world units, shape (*, 2).

y

The Mob's y coordinate in world units, shape (*, 1).

z

The Mob's z coordinate in world units, shape (*, 1).

on_create()[source]

Play this Mob’s spawn-in animation: a fade from transparent.

Called by spawn() when animate=True. Override it in a subclass to give a Mob its own entrance; the override should record its animation the same way, and is free to ignore opacity entirely.

Animation

Recorded as an animation over the current context’s runtime (1 second by default). The opacity write is non-recursive, so descendants run their own on_create.