lib.printing

 1import drawBot
 2from lib import layout, easing
 3
 4
 5def drawPerforationCircles(
 6    container: tuple,
 7    radius: float = 2,
 8    spacing: float = 80,
 9    count: int = 2,
10    align: tuple[layout.AlignX, layout.AlignY] = ("left", "center"),
11) -> tuple:
12    """
13    Draw a series of perforation circles within a container.
14
15    Args:
16        container: The container coordinates (x, y, w, h).
17        radius: The diameter of each circle in mm. Defaults to 2.
18        spacing: The spacing between circles (center to center) in mm. Defaults to 80.
19        count: The number of circles to draw. Defaults to 2.
20        align: The alignment of the series within the container. Defaults to ("left", "center").
21
22    Returns:
23        The coordinates of the area occupied by the perforation circles.
24    """
25    radius = layout.mm(radius)
26    spacing = layout.mm(spacing)
27    spacing -= radius  # adjust spacing to be center to center
28
29    perfDimensions = radius, radius * count + spacing * (count - 1)
30    perfCoords = layout.align(container, perfDimensions, align)
31    x, y, w, h = perfCoords
32
33    def getPos(locationY):
34        posY = y + h - radius if locationY == "top" else y
35        return x, posY
36
37    startPos, endPos = [getPos(positionY) for positionY in ["top", "bottom"]]
38    positions = easing.interpolate(
39        start=startPos, stop=endPos, steps=count, func=easing.linear
40    )
41
42    for [posX, posY] in positions:
43        drawBot.oval(posX, posY, radius, radius)
44
45    return perfCoords
def drawPerforationCircles( container: tuple, radius: float = 2, spacing: float = 80, count: int = 2, align: tuple[typing.Literal['left', 'center', 'right', 'stretch', None], typing.Literal['top', 'center', 'bottom', 'stretch', None]] = ('left', 'center')) -> tuple:
 6def drawPerforationCircles(
 7    container: tuple,
 8    radius: float = 2,
 9    spacing: float = 80,
10    count: int = 2,
11    align: tuple[layout.AlignX, layout.AlignY] = ("left", "center"),
12) -> tuple:
13    """
14    Draw a series of perforation circles within a container.
15
16    Args:
17        container: The container coordinates (x, y, w, h).
18        radius: The diameter of each circle in mm. Defaults to 2.
19        spacing: The spacing between circles (center to center) in mm. Defaults to 80.
20        count: The number of circles to draw. Defaults to 2.
21        align: The alignment of the series within the container. Defaults to ("left", "center").
22
23    Returns:
24        The coordinates of the area occupied by the perforation circles.
25    """
26    radius = layout.mm(radius)
27    spacing = layout.mm(spacing)
28    spacing -= radius  # adjust spacing to be center to center
29
30    perfDimensions = radius, radius * count + spacing * (count - 1)
31    perfCoords = layout.align(container, perfDimensions, align)
32    x, y, w, h = perfCoords
33
34    def getPos(locationY):
35        posY = y + h - radius if locationY == "top" else y
36        return x, posY
37
38    startPos, endPos = [getPos(positionY) for positionY in ["top", "bottom"]]
39    positions = easing.interpolate(
40        start=startPos, stop=endPos, steps=count, func=easing.linear
41    )
42
43    for [posX, posY] in positions:
44        drawBot.oval(posX, posY, radius, radius)
45
46    return perfCoords

Draw a series of perforation circles within a container.

Arguments:
  • container: The container coordinates (x, y, w, h).
  • radius: The diameter of each circle in mm. Defaults to 2.
  • spacing: The spacing between circles (center to center) in mm. Defaults to 80.
  • count: The number of circles to draw. Defaults to 2.
  • align: The alignment of the series within the container. Defaults to ("left", "center").
Returns:

The coordinates of the area occupied by the perforation circles.