animation

class janim.anims.animation.Animation(*, at: float = 0, duration: float | ForeverType = 1, rate_func: RateFunc = <function smooth>, name: str | None = None)

Bases: object

Base class of animations

  • Creates an animation from at to at + duration

  • duration can be FOREVER (generally used for Display, and in special cases for DataUpdater, etc., but AnimGroup and its derived classes cannot accept FOREVER)

  • Specifies the interpolation function rate_func, default is janim.utils.rate_functions.smooth() for smooth interpolation

  • Setting name displays text on the timeline label in the preview interface, does not affect rendering (if not set, defaults to class name)

Warning

Animation objects cannot be reused, for example, this will cause unexpected behavior:

class Test(Timeline):
    def construct(self):
        a = Square()
        b = Circle()
        anim1 = Transform(a, b)
        anim2 = Transform(b, a)
        self.play(anim1)
        self.play(anim2)
        self.play(anim1)

Correct way:

class Test(Timeline):
    def construct(self):
        a = Square()
        b = Circle()
        self.play(Transform(a, b))
        self.play(Transform(b, a))
        self.play(Transform(a, b))
label_color: tuple[float, float, float] = (192, 198, 205)
shift_range(delta: float) Self

Shift the time-range by delta

scale_range(k: float) Self

Scale the time-range by factor k (scaled relative to t=0)

finalize() None
get_alpha_on_global_t(global_t: float) float
transfer_params(other: Animation) None
global_t_ctx: ContextVar[float] = <ContextVar name='Animation.global_t_ctx'>
schedule_show_and_hide(item: Item, show_at_begin: bool, hide_at_end: bool) None
class janim.anims.animation.ItemAnimation(item: Item, *, show_at_begin: bool = True, hide_at_end: bool = False, **kwargs)

Bases: Animation

auto_detect = True
class ApplyParams(global_t: 'float', anims: 'list[ItemAnimation]', index: 'int')

Bases: object

global_t: float
anims: list[ItemAnimation]
index: int
apply(data: Item, p: ApplyParams) None
apply(data: None, p: ApplyParams) Item

Apply the animation effect at global_t to data

Where

  • For Display, data is None, and the return value is a Item object

  • For most others, data is the result of the previous animation, and the return value is None

class janim.anims.animation.ApplyAligner(item: Item, stacks: list[AnimStack], **kwargs)

Bases: ItemAnimation

pre_apply(data: Item, p: ApplyParams) None
class janim.anims.animation.TimeRange(at: float, end: float | ForeverType)

Bases: object

Identifies the time period starting at at and lasting for duration.

end can also be FOREVER

at: float

Start time of the time-range

end: float | ForeverType

End time of the time-range

property duration: float

Duration of the time-range, i.e., end - at. If end=FOREVER, raises AssertionError

See also num_duration()

property num_duration: float
  • When end is not FOREVER, same as duration()

  • When end is FOREVER, returns 0

(This is used for AnimGroup to handle child animations with end=FOREVER, i.e., treating such child animations as end=at for time calculation)

property num_end: float
  • When end is not FOREVER, returns end

  • When end is FOREVER, returns at

(This is used for AnimGroup to handle child animations with end=FOREVER, i.e., treating such child animations as end=at for time calculation)

set(at: float, end: float | ForeverType) None

Set the range of this time-range

shift(delta: float) None

Shift the time-range by delta

scale(k: float) None

Scale the time-range by factor k (scaled relative to t=0)

copy() TimeRange
contains(t: float) bool
class janim.anims.animation.TimeAligner

Bases: object

Due to floating-point precision issues, it is possible that two animations designed to be connected end-to-end may have misaligned judgments

This class is used to normalize similar floating-point numbers to the same value, ensuring that TimeRange intervals fit perfectly

align(anim: Animation) None

Normalize the time-range of anim, i.e., perform align_t() operations on .t_range.at and .t_range.end respectively

align_t(t: float) float

Align time t, ensuring that similar time points are normalized to the same value, returns the normalized time value

align_t_for_render(t: float) float

Similar to align_t(), but differs in that

  • This method does not record the value of t after searching

class janim.anims.animation.TimeSegments(iterable: Iterable[T], key: Callable[[T], TimeRange | Iterable[TimeRange]], *, step: float = 4)

Bases: Generic

get(t: float) list[T]