time¶
- class janim.anims_core.time.TimeRange(at: float, end: float | ForeverType)¶
Bases:
objectIdentifies the time period starting at
atand lasting forduration.If
endisFOREVER, it means the duration is infinite- at: float¶
Start time of the time-range
- end: float | ForeverType¶
End time of the time-range
If it is
FOREVER, it means the duration is infinite
- property duration: float¶
Duration of the time range
If
end=FOREVER, raisesAssertionError
- property num_duration: float¶
When
endis notFOREVER, it is the same asdurationWhen
endisFOREVER, returns0
- property num_end: float¶
When
endis notFOREVER, it is the same asendWhen
endisFOREVER, returnsat
- to_tuple() tuple[float, float | ForeverType]¶
- 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)
- copy() Self¶
Creates a copy of this object
- contains(t: float) bool¶
Checks whether
tis within this time range
- class janim.anims_core.time.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 nearby floating-point numbers to the same value, ensuring that
TimeRangeintervals fit together precisely- align_anim_and_record(anim: Animation) None¶
Normalizes the time range of
animand records itThat is, performs
align_and_record()on its.t_range.atand.t_range.endrespectively
- align_and_record(t: float) float¶
Aligns time
tand records it if there is no nearby time pointEnsures that nearby time points are normalized to the same value and returns the normalized time value
- align(t: float) float¶
Attempts to align time
tto a nearby time point without recording it
- class janim.anims_core.time.TimeChunks(iterable: Iterable[T], key: Callable[[T], TimeRange | Iterable[TimeRange]], *, step: float = 4)¶
Bases:
GenericUsed to optimize retrieval of objects with
TimeRangeinformation based on a specific timeMotivation:
There may be a series of objects on the timeline whose “visible times” are scattered. When querying “which objects are visible at a certain time
t”, we do not want to traverse the entire listHowever, since these visible times are represented by intervals, it is inconvenient to optimize using binary search
The purpose of this class is to divide time into chunks, each with a duration of
step, and record which objects are visible in each chunk. When retrieving visible objects at timet, the caller can useget()to obtain all objects in the chunk containingt, then only needs to check visibility among those objects- Parameters:
- get(t: float) list[T]¶
Gets all objects in the chunk containing time
t