Files
manim/manimlib/animation/numbers.py
Grant Sanderson c7ef8404b7 Video work (#2356)
* Only use -no-pdf for xelatex rendering

* Instead of tracking du and dv points on surface, track points off the surface in the normal direction

This means that surface shading will not necessarily work well for arbitrary transformations of the surface. But the existing solution was flimsy anyway, and caused annoying issues with singularity points.

* Have density of anchor points on arcs depend on arc length

* Allow for specifying true normals and orientation of Sphere

* Change miter threshold on stroke shader

* Add get_start_and_end to DashedLine

* Add min_total_width option to DecimalNumber

* Have BackgroundRectangle.set_style absorb (and ignore) added configuration

Note, this feels suboptimal

* Add LineBrace

* Update font_size adjustment in Tex

* Add scale_factor parameter to BulletedList.fade_all_but

* Minor import tweaks

* Add play_sound

* Small if -> elif update

* Always use Group for FadeTransform

* Use time_spanned_alpha in ChangingDecimal

* Change priority of number_config vs. self.decimal_number_config in NumberLine init

* Fix clock animation

* Allow sample_coords to be passed into VectorField
2025-06-10 08:02:32 -07:00

65 lines
1.8 KiB
Python

from __future__ import annotations
from manimlib.animation.animation import Animation
from manimlib.mobject.numbers import DecimalNumber
from manimlib.utils.bezier import interpolate
from manimlib.utils.simple_functions import clip
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Callable
class ChangingDecimal(Animation):
def __init__(
self,
decimal_mob: DecimalNumber,
number_update_func: Callable[[float], float],
suspend_mobject_updating: bool = False,
**kwargs
):
assert isinstance(decimal_mob, DecimalNumber)
self.number_update_func = number_update_func
super().__init__(
decimal_mob,
suspend_mobject_updating=suspend_mobject_updating,
**kwargs
)
self.mobject = decimal_mob
def interpolate_mobject(self, alpha: float) -> None:
true_alpha = self.time_spanned_alpha(alpha)
new_value = self.number_update_func(true_alpha)
self.mobject.set_value(new_value)
class ChangeDecimalToValue(ChangingDecimal):
def __init__(
self,
decimal_mob: DecimalNumber,
target_number: float | complex,
**kwargs
):
start_number = decimal_mob.number
super().__init__(
decimal_mob,
lambda a: interpolate(start_number, target_number, a),
**kwargs
)
class CountInFrom(ChangingDecimal):
def __init__(
self,
decimal_mob: DecimalNumber,
source_number: float | complex = 0,
**kwargs
):
start_number = decimal_mob.get_value()
super().__init__(
decimal_mob,
lambda a: interpolate(source_number, start_number, clip(a, 0, 1)),
**kwargs
)