item¶
- janim.items.item.mockable(func)¶
Allows calling methods decorated with
@mockableafter.astype
- class janim.items.item.Item(*args, children: list[Item] | None = None, **kwargs)¶
-
Itemis the base class for itemsIn addition to using
item[0]item[1]for subscript indexing, you can also use list indexing and boolean indexingList indexing, for example
item[0, 1, 3], which is equivalent toGroup(item[0], item[1], item[3])Boolean indexing, for example
item[False, True, False, True, True]represents extractingGroup(item[1], item[3], item[4]),that is, extracting those positions that are True to form a
Group
- depth¶
- distance_sort_reference_point: np.ndarray | None = None¶
- init_connect() None¶
- reset_additional_states() None¶
- broadcast_refresh_of_component(cmpt: Component, name: str, recurse_up=False, recurse_down=False) None¶
Handles
recurse_up/downformark_refresh()
- set(**styles) Self¶
Sets the style of the item and its child items. Unlike
apply_styles()which only affects itself, this method also affects all child items
- classmethod get_available_styles() list[str]¶
- apply_style(depth: float | None = None, **kwargs) Self¶
Sets the style of the item itself, does not affect child items
See also:
set()
- do(func: Callable[[Self], Any]) Self¶
Performs an operation on the item using
funcand returnsselffor convenient chain calling
- is_null() bool¶
- property anim: Self¶
For example:
self.play( item.anim.points.scale(2).r.color.set('green') )
This example creates a tween animation that scales
itemby 2x and sets it to greenAnd parameters can be passed to the animation:
self.play( item.anim(duration=2, rate_func=linear) .points.scale(2).r.color.set('green') )
.rmeans returning from component to item, allowing you to call functions of other componentsSee also:
MethodTransform
- property update: Self¶
For example:
self.play( item.update.points.shift(RIGHT * 2), item.update(rate_func=rush_into).color.set(GREEN) )
This example creates an updater that moves
itemtwo units to the right and sets it to green, with differentrate_funcfor each
- replicate(n: int) Group[Self]¶
Replicates n copies of itself and returns them as a
GroupYou can use
item * nas a shorthand for this method
- astype(cls: type[T]) T¶
Allows calling components not present in the current item
Examples:
group = Group( Rect() Circle() )
In this example, you cannot use
group.color.set(BLUE)to set the color of descendant items, but you can achieve this usinggroup.astype(VItem).color.set(BLUE)You can also use the shorthand
group(VItem).color.set(BLUE)
- get_parents()¶
- get_children()¶
- not_changed(other: Self) bool¶
- current(*, as_time: float | None = None, root_only=False) Self¶
Gets the current item from the current time point (considering the result after animation effects)
- copy(*, root_only: bool = False)¶
Copy item
- become(other: Item, *, auto_visible: bool = True) Self¶
Sets the data of this item to be the same as the passed item (by copying, not by reference)
- become_current() Self¶
Using this method can interrupt the animation process, making the item immediately become the result under the current animation effect
Tip
The item itself does not continuously change data with animation
Useful when you need to perform operations like
.animusing the state after animation
- classmethod align_for_interpolate(item1: Item, item2: Item) AlignedData[Self]¶
Performs data alignment for interpolation
- interpolate(item1: ~janim.items.item.Item, item2: ~janim.items.item.Item, alpha: float, *, path_func: PathFunc = <function straight_path>) None¶
Performs interpolation (only on this item, does not include descendant items)
- apart_alpha(n: int) None¶
- fix_in_frame(on: bool = True, *, root_only: bool = False) Self¶
Fixes the item on the screen, meaning even if the camera moves, its position on the screen will not change
- Parameters:
on –
Truemeans keep it fixed on the screen; passFalseto unfix it.root_only – Whether to apply this only to the root item; default is no, so it also applies to all descendant items.
- is_fix_in_frame() bool¶
Checks whether the item is fixed on the screen.
- apply_depth_test(on: bool = True, *, root_only: bool = False) Self¶
Enable depth testing
Enable pixel-level occlusion handling for the item.
For more details, see the tutorial section Handling 3D Occlusion.
- Parameters:
on –
Truemeans enable depth testing;Falsecan be passed to disable it.root_only – Whether to apply this only to the root item; default is no, so it also applies to all descendant items.
- is_applied_depth_test() bool¶
Checks whether the item has depth testing enabled.
- apply_distance_sort(on: bool = True, *, root_only: bool = False) Self¶
Enable distance sorting
Sort the rendering order by distance from the camera during rendering.
For more details, see the tutorial section Handling 3D Occlusion.
- Parameters:
on –
Truemeans enable distance sorting;Falsecan be passed to disable it.root_only – Whether to apply this only to the root item; default is no, so it also applies to all descendant items.
- is_applied_distance_sort() bool¶
Checks whether the item has distance sorting enabled.
- save_state(key: str = '', root_only: bool = False) Self¶
Saves the item state, which can later be restored using
load_state(), for example:item.save_state() # ... item.load_state()
Or create a restoration animation:
self.play(item.anim.load_state())
For example, it can be used to save the initial camera state and restore the camera position after complex animations
NumberPlane((-2, 2), (-2, 2), faded_line_ratio=1).show() self.camera.save_state() self.play( self.camera.anim.points.rotate(40 * DEGREES) ) self.play( self.camera.anim.points.rotate(70 * DEGREES, axis=UP) ) self.play( self.camera.anim.load_state() )
- load_state(key: str = '') Self¶
Restores the item state, see
save_state()for details
- generate_target() Self¶
Copies and generates a
.targetitem for setting the target state, then usesMoveToTargetto create a transition animationFor example:
txt = Text('A Matrix') mat = TypstMatrix([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) self.play(Write(txt)) Group(txt.generate_target(), mat).points.arrange(DOWN) self.play( MoveToTarget(txt), FadeIn(mat, UP) ) self.forward()
See also:
MoveToTarget
- show(root_only=False) Self¶
Show item
- hide(root_only=False) Self¶
Hide item