animator.entity.Entity¶
- class animator.entity.Entity(pos: Optional[Union[animator.skia.Point, Tuple[float, float]]] = None, **kwargs: Any)¶
Bases:
object
The base entity class.
- Variables
pos – The position of the entity. This is the origin of the entity.
mat – The transformation matrix of the entity.
transformation – Convenience object for applying transformations to the entity.
offset – The extra offset to draw the entity at after applying the entity’s transformation.
visible – Whether the entity is drawn. This does not affect the entity’s children.
style – The
Style
of the entity.children – The children of this entity.
_is_dirty – Entities may cache some values for performance. This flag is set to
True
when the entity needs to recalculate its cached values. Subclasses may implement methods to automatically detect when this flag needs to be set.
- __init__(pos: Optional[Union[animator.skia.Point, Tuple[float, float]]] = None, **kwargs: Any) None ¶
- Parameters
pos – The position of the entity.
kwargs – Arguments to pass to
transformation
andstyle
. See theirset_from_args()
method for more info.
Methods
__init__
([pos])- param pos
The position of the entity.
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.