animator.graphics.style.Style

class animator.graphics.style.Style

Bases: object

The style of an entity. This class initializes with the default style values, which can be changed.

Variables
  • clip – The clip to be applied to the entity. The clip is applied after transformations.

  • paint_style – Paint style for the entity; if the entity is filled, stroked, or both.

  • optimization – Optimization to apply for the final paint since applying the final paint can be expensive.

__init__()

Methods

__init__()

apply_clip(canvas)

Apply the clip to the canvas.

apply_final_paint(canvas)

Apply the final paint to the canvas.

get_dash()

Get the dash of the stroke.

nothing_to_draw()

Returns True if the style has nothing to draw.

set_blend_mode(mode)

Set the blend mode of the entity.

set_color_filter(filter)

Set the color filter of the entity.

set_dash(intervals[, phase])

Set the dash of the stroke.

set_fill_color(c, *args, **kwargs)

Set the fill color of the entity.

set_fill_color_or_shader(c, *args, **kwargs)

Set the fill color or shader of the entity.

set_fill_shader(shader)

Set the fill shader of the entity.

set_from_kwargs(**kwargs)

Set the style from arguments.

set_glow(sigma[, color, glow_only])

Set a glow emmiting from behind the entity.

set_image_filter(filter)

Set the image filter in the final_paint.

set_mask_filter(filter)

Set the mask filter of the entity.

set_path_effect(effect)

Set the path effect of the entity.

set_shadow(dx, dy[, sx, sy, color, shadow_only])

Set the shadow of the entity.

set_stroke_color(c, *args, **kwargs)

Set the stroke color of the entity.

set_stroke_color_or_shader(c, *args, **kwargs)

Set the stroke color or shader of the entity.

set_stroke_shader(shader)

Set the stroke shader of the entity.

set_trim([start, stop])

Set the trim of the stroke.

Attributes

FILL_COLOR

OPACITY

STROKE_CAP

STROKE_COLOR

STROKE_JOIN

STROKE_MITER

STROKE_WIDTH

anti_alias

Whether the entity is anti-aliased.

fill_paint

The paint used to fill the entity.

final_paint

The final paint used to draw the entity.

opacity

The opacity of the entity.

stroke_cap

The cap of the stroke.

stroke_join

The join of the stroke.

stroke_miter

The miter of the stroke.

stroke_paint

The paint used to stroke the entity.

stroke_width

The width of the stroke.

class FinalPaintOptimization(value)

Bases: enum.Enum

An enumeration.

ALL = 2

Apply all properties from the final paint if present.

ALWAYS = 3

Always apply all properties from the final paint.

NONE = 0

Do not apply any properties from the final paint.

OPACITY_ONLY = 1

Only apply opacity from the final paint if present.

class PaintStyle(value)

Bases: enum.Enum

An enumeration.

FILL_ONLY = 1

Only fill the entity.

FILL_THEN_STROKE = 2

Fill the entity, then stroke it. This is the most common style.

STROKE_ONLY = 0

Only stroke the entity.

STROKE_THEN_FILL = 3

Stroke the entity, then fill it.

property anti_alias: bool

Whether the entity is anti-aliased.

apply_clip(canvas: animator.skia.Canvas) None

Apply the clip to the canvas.

apply_final_paint(canvas: animator.skia.Canvas) None

Apply the final paint to the canvas.

property fill_paint: animator.skia.Paint

The paint used to fill the entity.

property final_paint: animator.skia.Paint

The final paint used to draw the entity.

get_dash() animator.skia.PathEffect.DashInfo | None

Get the dash of the stroke.

nothing_to_draw() bool

Returns True if the style has nothing to draw. However, even if this returns False, the style may not draw anything.

property opacity: float

The opacity of the entity.

set_blend_mode(mode: 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

Set the blend mode of the entity.

Note

Modifies final_paint.

set_color_filter(filter: animator.skia.ColorFilter | animator.skia.ColorMatrix | animator.skia.ColorTable | None) None

Set the color filter of the entity.

Note

Modifies final_paint.

set_dash(intervals: list[float], phase: float = 0) None

Set the dash of the stroke.

Note

Modifies stroke_paint.

set_fill_color(c: Union[animator.skia.Color4f, int, float, Sequence[float], str], *args, **kwargs) None

Set the fill color of the entity. This takes the same arguments as animator.color().

Note

Modifies fill_paint.

set_fill_color_or_shader(c: Union[animator.skia.Color4f, int, float, Sequence[float], str, animator.skia.Shader], *args, **kwargs) None

Set the fill color or shader of the entity.

Note

Modifies fill_paint.

set_fill_shader(shader: animator.skia.Shader) None

Set the fill shader of the entity.

Note

Modifies fill_paint.

set_from_kwargs(**kwargs) None

Set the style from arguments. Supported arguments are the same as the attributes of this class and

  • fill_color: The fill color or shader of the entity. Takes all the arguments of animator.color().

  • stroke_color: The stroke color or shader of the entity. Takes all the arguments of animator.color().

  • image_filter: The image filter of the entity. Can be a skia.ImageFilter, a skia.ColorFilter, a skia.Image, a skia.Picture or a skia.Shader.

  • blend_mode: The blend mode of the entity.

  • mask_filter: The mask filter of the entity. Can be a skia.MaskFilter or a skia.Shader.

  • color_filter: The color filter of the entity. Can be a skia.ColorFilter, a skia.ColorMatrix or a skia.ColorTable.

  • path_effect: The path effect to apply to the entity’s path, intelligently applied to the stroke_paint or fill_paint.

  • dash: The dash of the stroke. Can be None or a list of floats.

  • trim: The trim of the stroke. Can be None or a tuple of (start, end).

  • style: The style of the paint. Can be 'fill', 'stroke', 'fill-stroke' (default) or 'stroke-fill'.

set_glow(sigma: float, color: Optional[Union[animator.skia.Color4f, int, float, Sequence[float], str]] = None, glow_only: bool = False) None

Set a glow emmiting from behind the entity.

Parameters
  • sigma – The sigma of the glow.

  • color – The color of the glow. If None, a translucent fill color will be used.

  • glow_only – Whether the glow should be the only thing drawn.

Note

Modifies final_paint.

set_image_filter(filter: animator.skia.ImageFilter | animator.skia.ColorFilter | animator.skia.Image | animator.skia.Picture | animator.skia.Shader | None) None

Set the image filter in the final_paint.

Note

Modifies final_paint.

set_mask_filter(filter: animator.skia.MaskFilter | animator.skia.Shader | None) None

Set the mask filter of the entity.

Note

Modifies fill_paint.

set_path_effect(effect: animator.skia.PathEffect | None) None

Set the path effect of the entity. The effect is intelligently applied to the stroke_paint or fill_paint depending on its type. It’d make more sense to apply the effect manually to the paint you want to apply it to using style.stroke_paint.setPathEffect(effect) or style.fill_paint.setPathEffect(effect).

Note

Modifies stroke_paint, fill_paint or both.

set_shadow(dx: float, dy: float, sx: float = 0, sy: float = 0, color: Optional[Union[animator.skia.Color4f, int, float, Sequence[float], str]] = None, shadow_only: bool = False) None

Set the shadow of the entity.

Parameters
  • dx – The x offset of the shadow.

  • dy – The y offset of the shadow.

  • sx – The sigma x of the shadow.

  • sy – The sigma y of the shadow.

  • color – The color of the shadow. If None, a translucent fill color will be used.

  • shadow_only – Whether the shadow should be the only thing drawn.

Note

Modifies final_paint.

set_stroke_color(c: Union[animator.skia.Color4f, int, float, Sequence[float], str], *args, **kwargs) None

Set the stroke color of the entity. This takes the same arguments as animator.color().

Note

Modifies stroke_paint.

set_stroke_color_or_shader(c: Union[animator.skia.Color4f, int, float, Sequence[float], str, animator.skia.Shader], *args, **kwargs) None

Set the stroke color or shader of the entity.

Note

Modifies stroke_paint.

set_stroke_shader(shader: animator.skia.Shader) None

Set the stroke shader of the entity.

Note

Modifies stroke_paint.

set_trim(start: float | None = 0, stop: float = 1) None

Set the trim of the stroke.

Note

Modifies stroke_paint.

property stroke_cap: animator.skia.Paint.Cap

The cap of the stroke.

property stroke_join: animator.skia.Paint.Join

The join of the stroke.

property stroke_miter: float

The miter of the stroke.

property stroke_paint: animator.skia.Paint

The paint used to stroke the entity.

property stroke_width: float

The width of the stroke.