pythagoras.shape module

class pythagoras.shape.Path(*args: tuple[float, float], zord: int = 0)[source]

Bases: PObject

A sequence of connected points forming an open path.

Variables:
  • *args – Points specified as (x, y) pairs defining the path.

  • zord – Drawing order; higher values are drawn later.

extrema() list[tuple[float, float]][source]

Computes the furthermost points of the figure.

Returns:

A list with the bounding points of the object.

points: list[tuple[float, float]]
rotate(point: tuple[float, float], theta: float) None[source]

Rotates all the points of the Shape object by a given angle around some point, and consequently the shape itself.

Parameters:
  • point – Center of rotation.

  • theta – Angle of rotation.

svg(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into SVG commands.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The corresponding SVG code.

tikz(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into a sequence of TikZ instructions.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The resulting TikZ code.

class pythagoras.shape.Polygon(*args: tuple[float, float], zord: int = 0)[source]

Bases: Path

A closed polygonal shape.

Notes

The polygon is drawn by connecting the provided points and closing the path (the first point is repeated for SVG output).

classmethod regular(x: float, y: float, r: float, n: int, zord: int = 0) Self[source]

Constructor for a regular polygon.

Parameters:
  • x\(x\)-coordinate of the center.

  • y\(y\)-coordinate of the center.

  • r – Radius of the polygon (distance from the center to a vertex).

  • n – Number of sides.

  • zord – Rendering priority.

Returns:

An instance of the Polygon class.

svg(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into SVG commands.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The corresponding SVG code.

tikz(ctx: RenderingContext, *args: POProperty) str[source]

Compiles the object into a sequence of TikZ instructions.

Parameters:
  • ctx – Context associated with the Canvas instance.

  • args – Properties of the object.

Returns:

The resulting TikZ code.

classmethod triangle_from_lengths(a: float, b: float, c: float, zord: int = 0) Self[source]

Construct a triangle from the lengths of its sides.

Parameters:
  • a – Length of the first side.

  • b – Length of the second side.

  • c – Length of the third side.

Returns:

An instance of the Polygon class.

pythagoras.shape.grid(start: tuple[float, float], end: tuple[float, float], step: tuple[float, float], zord: int = 0) Iterator[Path][source]

Creates a sequence of segments forming a grid.

Parameters:
  • start – Leftmost bottom point of the grid.

  • end – Rightmost top point of the grid.

  • step – Increments in the \(x\) and \(y\) axes.

Returns:

An iterable of lines shaping a grid.