item

janim.items.item.mockable(func)

Allows calling methods decorated with @mockable after .astype

class janim.items.item.Item(*args, children: list[Item] | None = None, **kwargs)

Bases: Relation[Item]

Item is the base class for items

In addition to using item[0] item[1] for subscript indexing, you can also use list indexing and boolean indexing

  • List indexing, for example item[0, 1, 3], which is equivalent to Group(item[0], item[1], item[3])

  • Boolean indexing, for example item[False, True, False, True, True] represents extracting Group(item[1], item[3], item[4]),

    that is, extracting those positions that are True to form a Group

renderer_cls

alias of Renderer

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/down for mark_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 func and returns self for 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 item by 2x and sets it to green

And parameters can be passed to the animation:

self.play(
    item.anim(duration=2, rate_func=linear)
        .points.scale(2).r.color.set('green')
)

.r means returning from component to item, allowing you to call functions of other components

See 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 item two units to the right and sets it to green, with different rate_func for each

replicate(n: int) Group[Self]

Replicates n copies of itself and returns them as a Group

You can use item * n as a shorthand for this method

join(lst: Iterable[T]) Group[Self | T]
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 using group.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)

store(*, _cmpts: dict[str, Component] | None = None)
restore(other: Item) Self
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 .anim using 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:
  • onTrue means keep it fixed on the screen; pass False to 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:
  • onTrue means enable depth testing; False can 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:
  • onTrue means enable distance sorting; False can 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.

class SavedState(state: 'T', root_only: 'bool')

Bases: Generic

state: T
root_only: bool
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 .target item for setting the target state, then uses MoveToTarget to create a transition animation

For 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

create_renderer() Renderer
show(root_only=False) Self

Show item

hide(root_only=False) Self

Hide item