Shape#
- class random_shapes.Shape(curve: CurvedPolygon)[source]#
Bases:
object
A wrapper class of bezier.CurvedPolygon for creating random bezier shapes and convertion to other formats.
- classmethod from_points(points: list[Point], edgy: float, r: float) Self [source]#
Get a bezier shape from a list of points.
- Parameters:
points (list[Point]) – A list of points.
edgy (float, optional) – A number between 0 and 1 to steer the edgyness / weiredness of the shape.
r (float, optional) – A number between 0 and 1 to steer the roundness of the shape-edges.
- classmethod random(n: int = 5, r: float = 0.3, edgy: float = 0, scale: float = 0.8, mindst: float | None = None, rec: int = 0) Self [source]#
Create a random shape.
- Parameters:
n (int, optional) – Number of points. Defaults to 5.
edgy (float, optional) – Steers the edgyness / weiredness of the shape. Defaults to 0.
r (float, optional) – Steers the roundness of the shape-edges. Defaults to 0.3.
scale (float, optional) – Scaling factor. Defaults to 0.8.
mindst (float, optional) – Minimum distance between points. Defaults to None.
rec (int, optional) – Recursion counter for the random generation of points. Defaults to 0.
- Returns:
A random shape.
- Return type:
bezier.CurvedPolygon
- rasterize(w: int, h: int, pts_per_edge: int = 20) ndarray [source]#
Convert a bezier shape to a binary image.
- Parameters:
shape (bezier.CurvedPolygon) – A bezier shape.
w (int) – Width of the image.
h (int) – Height of the image.
pts_per_edge (int, optional) – Number of points per edge. Defaults to 20.
- Returns:
A binary image of the shape.
- Return type:
np.ndarray