pythagoras.shape module¶
- class pythagoras.shape.Path(*args: tuple[float, float], zord: int = 0)[source]¶
Bases:
PObjectA 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
Shapeobject 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
Canvasinstance.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
Canvasinstance.args – Properties of the object.
- Returns:
The resulting TikZ code.
- class pythagoras.shape.Polygon(*args: tuple[float, float], zord: int = 0)[source]¶
Bases:
PathA 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
Polygonclass.
- svg(ctx: RenderingContext, *args: POProperty) str[source]¶
Compiles the object into SVG commands.
- Parameters:
ctx – Context associated with the
Canvasinstance.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
Canvasinstance.args – Properties of the object.
- Returns:
The resulting TikZ code.
- 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.