animator.entity.Group¶
- class animator.entity.Group(child_blender: Optional[Union[animator.skia.BlendMode, animator.skia.Blender, Literal['source-over', 'source-in', 'source-out', 'source-atop', 'destination-over', 'destination-in', 'destination-out', 'destination-atop', 'lighter', 'copy', 'xor', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity']]] = None, **kwargs)¶
Bases:
animator.entity.entity.Entity
A
Group
does not draw anything itself, so it’sstroke_paint
andfill_paint
are ignored. It is useful for grouping entities together, especially if you want to apply some style to all of them at once. While you can add children to any entity, a group behaves a bit differently on how it draws its children.Normally, an entity’s
clip
andfinal_paint
only apply to itself. However, a group will apply itsclip
andfinal_paint
to all of its children. The bounds of a group is the union of all of its children’s bounds. The group can also be used to blend its children.- __init__(child_blender: Optional[Union[animator.skia.BlendMode, animator.skia.Blender, Literal['source-over', 'source-in', 'source-out', 'source-atop', 'destination-over', 'destination-in', 'destination-out', 'destination-atop', 'lighter', 'copy', 'xor', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity']]] = None, **kwargs)¶
- Parameters
child_blender – If not
None
, the blender is used for all children on top of their own blend mode.
Methods
__init__
([child_blender])- param child_blender
If not
None
, the blender is used for all children on top of their own blend mode.
add
(*children)Add one or more children to this entity.
align
(pos)Shifts the entity so that its offset is aligned with the relative pos.
center
()Shifts the entity so that its offset is aligned with the center of the entity.
clear
()Clear the children of this entity.
do_fill
(canvas)Draw the fill.
do_stroke
(canvas)Draw the stroke.
draw
([canvas])Draw the entity and its children.
get_bounds
([transformed])Get the bounding box of this entity.
get_dimensions
([transformed])Get the width and height of this entity.
move
([dx, dy])Move the entity by a given amount.
on_draw
(canvas)Draw the entity.
Reset the transformation matrix to the identity matrix.
rotate
([degrees])Rotate the entity by the given amount.
scale
([sx, sy])Scale the entity by the given amount.
set_relative_pos
(pos[, anchor, padding])Set the position of this entity relative to its scene.
set_relative_to_entity
(other, pos[, anchor, ...])Set the position of this entity relative to another entity.
set_scene
(scene)Set the scene of this entity and all its children.
set_visibility
([visible])Set the visibility of this entity and all its children.
shift
([dx, dy])Shift the entity by the given amount.
skew
([kx, ky])Skew the entity by the given amount.
transform
(mat)Apply the given transformation matrix to the entity.
translate
([dx, dy])Translate the entity by the given amount.
Attributes
The absolute position of this entity in the scene, after applying its parent's transformation.
The total transformation of this entity, including its parent's transformation.
The z-index of the entity.
- property absolute_position: animator.skia.Point¶
The absolute position of this entity in the scene, after applying its parent’s transformation.
- add(*children: animator.entity.entity.Entity) None ¶
Add one or more children to this entity.
- align(pos: RelativePosition) ET ¶
Shifts the entity so that its offset is aligned with the relative pos.
- Parameters
pos – The position relative to the entity, a 2 element numpy array [x, y]. The coordinates are between -1 and 1, where -1 is the left/top of the entity and 1 is the right/bottom of the entity.
- center() ET ¶
Shifts the entity so that its offset is aligned with the center of the entity.
- do_fill(canvas: animator.skia.Canvas) None ¶
Draw the fill. This method can be overridden by subclasses to change the fill behavior.
- do_stroke(canvas: animator.skia.Canvas) None ¶
Draw the stroke. This method can be overridden by subclasses to change the stroke behavior.
- draw(canvas: Optional[animator.skia.Canvas] = None) None ¶
Draw the entity and its children.
- get_bounds(transformed: bool = False) animator.skia.Rect ¶
Get the bounding box of this entity.
- Parameters
transformed – Whether to apply the entity’s transformation to the bounding box.
- get_dimensions(transformed: bool = False) animator.skia.Size ¶
Get the width and height of this entity.
- Parameters
transformed – Whether to apply the entity’s transformation to the dimensions.
- move(dx: float = 0, dy: float = 0) ET ¶
Move the entity by a given amount. This changes pos.
- Parameters
dx – The amount to move in the x direction.
dy – The amount to move in the y direction.
- on_draw(canvas: animator.skia.Canvas) None ¶
Draw the entity. This method can be overridden by subclasses to change the drawing behavior.
- reset_transform() ET ¶
Reset the transformation matrix to the identity matrix.
- rotate(degrees: float = 0) ET ¶
Rotate the entity by the given amount.
- Parameters
degrees – The amount to rotate in degrees.
- scale(sx: float = 1, sy: float | None = None) ET ¶
Scale the entity by the given amount.
- Parameters
sx – The amount to scale in the x direction.
sy – The amount to scale in the y direction. If
None
, sx is used.
- set_relative_pos(pos: RelativePosition, anchor: RelativePosition | None = None, padding: float = 25) ET ¶
Set the position of this entity relative to its scene.
- Parameters
pos – The position of the entity relative to the scene, a 2 element numpy array [x, y]. The coordinates are between -1 and 1, where -1 is the left/top of the scene and 1 is the right/bottom of the scene.
anchor – The anchor point of the entity in relative coordinates, which will be positioned at pos. If
None
, it’ll be same as pos.padding – The extra space around the scene, in pixels.
- set_relative_to_entity(other: Entity, pos: RelativePosition, anchor: RelativePosition | None = None, padding: float = 25) ET ¶
Set the position of this entity relative to another entity.
- Parameters
other – The entity to which the position is relative.
pos – The position of the entity relative to other, a 2 element numpy array [x, y]. The coordinates are between -1 and 1, where -1 is the left/top of the entity and 1 is the right/bottom of the entity.
anchor – The anchor point of the entity in relative coordinates, which will be positioned at pos. If
None
, it’ll be same as pos.padding – The extra space around the entity, in pixels.
- set_visibility(visible: Optional[bool] = None) None ¶
Set the visibility of this entity and all its children. To change the visibility without affecting the children, set
Entity.visible
instead.- Parameters
visible – Whether the entity is visible. If
None
, the entity’s visibility is toggled.
- shift(dx: float = 0, dy: float = 0) ET ¶
Shift the entity by the given amount. This changes offset.
- Parameters
dx – The amount to shift in the x direction.
dy – The amount to shift in the y direction.
- skew(kx: float = 0, ky: float = 0) ET ¶
Skew the entity by the given amount.
- Parameters
kx – The amount (in degrees) to skew in the x direction.
ky – The amount (in degrees) to skew in the y direction.
- property total_transformation: animator.skia.Matrix¶
The total transformation of this entity, including its parent’s transformation.
- transform(mat: skia.Matrix) ET ¶
Apply the given transformation matrix to the entity.
- Parameters
mat – The transformation matrix.