animation¶
- class janim.anims.animation.Animation(*, at: float = 0, duration: float | ForeverType = 1, rate_func: RateFunc = <function smooth>, name: str | None = None)¶
Bases:
objectBase class of animations
Creates an animation from
attoat + durationdurationcan beFOREVER(generally used forDisplay, and in special cases forDataUpdater, etc., butAnimGroupand its derived classes cannot acceptFOREVER)Specifies the interpolation function
rate_func, default isjanim.utils.rate_functions.smooth()for smooth interpolationSetting
namedisplays 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 tot=0)
- finalize() None¶
- get_alpha_on_global_t(global_t: float) float¶
- global_t_ctx: ContextVar[float] = <ContextVar name='Animation.global_t_ctx'>¶
- 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_ttodataWhere
- 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:
objectIdentifies the time period starting at
atand lasting forduration.endcan also beFOREVER- 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. Ifend=FOREVER, raisesAssertionErrorSee also
num_duration()
- property num_duration: float¶
When
endis notFOREVER, same asduration()When
endisFOREVER, returns0
(This is used for
AnimGroupto handle child animations withend=FOREVER, i.e., treating such child animations asend=atfor time calculation)
- property num_end: float¶
When
endis notFOREVER, returnsendWhen
endisFOREVER, returnsat
(This is used for
AnimGroupto handle child animations withend=FOREVER, i.e., treating such child animations asend=atfor 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 tot=0)
- contains(t: float) bool¶
- class janim.anims.animation.TimeAligner¶
Bases:
objectDue 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
TimeRangeintervals fit perfectly- align(anim: Animation) None¶
Normalize the time-range of
anim, i.e., performalign_t()operations on.t_range.atand.t_range.endrespectively
- align_t(t: float) float¶
Align time
t, ensuring that similar time points are normalized to the same value, returns the normalized time value