Skip to content

Path

Inherits: Shape

Draws a path with given elements with the given paint.

Whether this shape is filled, stroked, or both, is controlled by paint.style. If the path is filled, then sub-paths within it are implicitly closed (see Path.Close).

Properties

Properties#

elements class-attribute instance-attribute #

elements: list[PathElement] = field(default_factory=list)

The list of path elements.

paint class-attribute instance-attribute #

paint: Paint = field(default_factory=lambda: Paint())

A style to draw a path with.

Classes#

Arc dataclass #

Inherits: PathElement

Adds a new sub-path with one arc segment that consists of the arc that follows the edge of the oval bounded by the given rectangle with top left corner at x and y and dimensions width and height, from start_angle radians around the oval up to start_angle + sweep_angle radians around the oval, with zero radians being the point on the right hand side of the oval that crosses the horizontal line that intersects the center of the rectangle and with positive angles going clockwise around the oval.

Properties

  • height(float) –

    Height of the rectangle bounding the arc.

  • start_angle(float) –

    Starting angle in radians of the arc.

  • sweep_angle(float) –

    Sweep angle in radians from start_angle.

  • width(float) –

    Width of the rectangle bounding the arc.

  • x(float) –

    Top-left corner x of the rectangle bounding the arc.

  • y(float) –

    Top-left corner y of the rectangle bounding the arc.

Properties#

height instance-attribute #
height: float

Height of the rectangle bounding the arc.

start_angle instance-attribute #
start_angle: float

Starting angle in radians of the arc.

sweep_angle instance-attribute #
sweep_angle: float

Sweep angle in radians from start_angle.

width instance-attribute #
width: float

Width of the rectangle bounding the arc.

x instance-attribute #
x: float

Top-left corner x of the rectangle bounding the arc.

y instance-attribute #
y: float

Top-left corner y of the rectangle bounding the arc.

ArcTo dataclass #

Inherits: PathElement

Appends up to four conic curves weighted to describe an oval of radius and rotated by rotation (measured in degrees and clockwise).

The first curve begins from the last point in the path and the last ends at x and y. The curves follow a path in a direction determined by clockwise (bool) and large_arc (bool) in such a way that the sweep angle is always less than 360 degrees.

A simple line is appended if either radius is zero or the last point in the path (x,y). The radii are scaled to fit the last path point if both are greater than zero but too small to describe an arc.

Properties

  • clockwise(bool) –

    Whether the arc should be drawn clockwise.

  • large_arc(bool) –

    Whether to use the large arc sweep.

  • radius(float) –

    Radius of the arc.

  • rotation(float) –

    Rotation of the arc in degrees.

  • x(float) –

    Destination x coordinate of arc endpoint.

  • y(float) –

    Destination y coordinate of arc endpoint.

Properties#

clockwise class-attribute instance-attribute #
clockwise: bool = True

Whether the arc should be drawn clockwise.

large_arc class-attribute instance-attribute #
large_arc: bool = False

Whether to use the large arc sweep.

radius class-attribute instance-attribute #
radius: float = 0

Radius of the arc.

rotation class-attribute instance-attribute #
rotation: float = 0

Rotation of the arc in degrees.

x instance-attribute #
x: float

Destination x coordinate of arc endpoint.

y instance-attribute #
y: float

Destination y coordinate of arc endpoint.

Close dataclass #

Inherits: PathElement

Closes the last sub-path, as if a straight line had been drawn from the current point to the first point of the sub-path.

CubicTo dataclass #

Inherits: PathElement

Adds a cubic bezier segment that curves from the current point to the given point (x,y), using the control points (cp1x,cp1y) and (cp2x,cp2y).

Properties

Properties#

cp1x instance-attribute #
cp1x: float
cp1y instance-attribute #
cp1y: float
cp2x instance-attribute #
cp2x: float
cp2y instance-attribute #
cp2y: float
x instance-attribute #
x: float
y instance-attribute #
y: float

LineTo dataclass #

Inherits: PathElement

Adds a straight line segment from the current point to the given point (x,y).

Properties

Properties#

x instance-attribute #
x: float
y instance-attribute #
y: float

MoveTo dataclass #

Inherits: PathElement

Starts a new sub-path at the given point (x,y).

Properties

Properties#

x instance-attribute #
x: float
y instance-attribute #
y: float

Oval dataclass #

Inherits: PathElement

Adds a new sub-path that consists of a curve that forms the ellipse that fills the given rectangle.

Properties

  • height(float) –

    Height of the bounding rectangle.

  • width(float) –

    Width of the bounding rectangle.

  • x(float) –

    The x-axis coordinate of the top-left of the bounding rectangle.

  • y(float) –

    The y-axis coordinate of the top-left of the bounding rectangle.

Properties#

height instance-attribute #
height: float

Height of the bounding rectangle.

width instance-attribute #
width: float

Width of the bounding rectangle.

x instance-attribute #
x: float

The x-axis coordinate of the top-left of the bounding rectangle.

y instance-attribute #
y: float

The y-axis coordinate of the top-left of the bounding rectangle.

PathElement dataclass #

QuadraticTo dataclass #

Inherits: PathElement

Adds a bezier segment that curves from the current point to the given point (x,y), using the control points (cp1x,cp1y) and the weight w.

Properties

Properties#

cp1x instance-attribute #
cp1x: float
cp1y instance-attribute #
cp1y: float
w class-attribute instance-attribute #
w: float = 1

If the weight is greater than 1, then the curve is a hyperbola; if the weight equals 1, it's a parabola; and if it is less than 1, it is an ellipse.

x instance-attribute #
x: float
y instance-attribute #
y: float

Rect dataclass #

Inherits: PathElement

Adds a rectangle as a new sub-path.

Properties

  • border_radius(BorderRadiusValue | None) –

    Optional border radius to round rectangle corners.

  • height(float) –

    Height of the rectangle.

  • width(float) –

    Width of the rectangle.

  • x(float) –

    The x-axis coordinate of the top-left of the rectangle.

  • y(float) –

    The y-axis coordinate of the top-left of the rectangle.

Properties#

border_radius class-attribute instance-attribute #
border_radius: BorderRadiusValue | None = None

Optional border radius to round rectangle corners.

height instance-attribute #
height: float

Height of the rectangle.

width instance-attribute #
width: float

Width of the rectangle.

x instance-attribute #
x: float

The x-axis coordinate of the top-left of the rectangle.

y instance-attribute #
y: float

The y-axis coordinate of the top-left of the rectangle.

SubPath dataclass #

Inherits: PathElement

Adds the sub-path described by elements to the given point (x,y).

Properties

Properties#

elements instance-attribute #
elements: list[PathElement]
x instance-attribute #
x: float
y instance-attribute #
y: float