Last active
July 25, 2023 02:11
-
-
Save BrianEnigma/b715195bf26c03142271d2a30e651047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import drawsvg as dw | |
# requirements.txt: | |
# drawsvg | |
# cairosvg | |
WIDTH = 25 # millimeters | |
HEIGHT = 30 # millimeters | |
CORNER_RADIUS = 4 # millimeters | |
ACROSS = 7 | |
DOWN = 4 | |
def mm(i:float) ->float: | |
return i * 72 / 25.4 | |
def partial_rectangle(d, x, y): | |
# Top-Left Corner | |
p = dw.Path() | |
d.append(p.M(mm(x), mm(y + CORNER_RADIUS)).Q(mm(x), mm(y), mm(x + CORNER_RADIUS), mm(y))) | |
# Top | |
d.append(dw.Line(mm(x + CORNER_RADIUS), mm(y), mm(x + WIDTH - CORNER_RADIUS), mm(y))) | |
# Top-Right | |
p = dw.Path() | |
d.append(p.M(mm(x + WIDTH - CORNER_RADIUS), mm(y)).Q(mm(x + WIDTH), mm(y), mm(x + WIDTH), mm(y + CORNER_RADIUS))) | |
# Right | |
d.append(dw.Line(mm(x + WIDTH), mm(y + CORNER_RADIUS), mm(x + WIDTH), mm(y + HEIGHT - CORNER_RADIUS))) | |
# Bottom-Right | |
p = dw.Path() | |
d.append(p.M(mm(x + WIDTH), mm(y + HEIGHT - CORNER_RADIUS)).Q(mm(x + WIDTH), mm(y + HEIGHT), mm(x + WIDTH - CORNER_RADIUS), mm(y + HEIGHT))) | |
# Bottom-Left | |
p = dw.Path() | |
d.append(p.M(mm(x + CORNER_RADIUS), mm(y + HEIGHT)).Q(mm(x), mm(y + HEIGHT), mm(x), mm(y + HEIGHT - CORNER_RADIUS))) | |
def left_rectangle(d, x, y): | |
partial_rectangle(d, x, y) | |
# Left | |
d.append(dw.Line(mm(x), mm(y + HEIGHT - CORNER_RADIUS), mm(x), mm(y + CORNER_RADIUS))) | |
def bottom_rectangle(d, x, y): | |
partial_rectangle(d, x, y) | |
# Bottom | |
d.append(dw.Line(mm(x + WIDTH - CORNER_RADIUS), mm(y + HEIGHT), mm(x + CORNER_RADIUS), mm(y + HEIGHT))) | |
def full_rectangle(d, x, y): | |
# Top-Left Corner | |
p = dw.Path() | |
d.append(p.M(mm(x), mm(y + CORNER_RADIUS)).Q(mm(x), mm(y), mm(x + CORNER_RADIUS), mm(y))) | |
# Top | |
d.append(dw.Line(mm(x + CORNER_RADIUS), mm(y), mm(x + WIDTH - CORNER_RADIUS), mm(y))) | |
# Top-Right | |
p = dw.Path() | |
d.append(p.M(mm(x + WIDTH - CORNER_RADIUS), mm(y)).Q(mm(x + WIDTH), mm(y), mm(x + WIDTH), mm(y + CORNER_RADIUS))) | |
# Right | |
d.append(dw.Line(mm(x + WIDTH), mm(y + CORNER_RADIUS), mm(x + WIDTH), mm(y + HEIGHT - CORNER_RADIUS))) | |
# Bottom-Right | |
p = dw.Path() | |
d.append(p.M(mm(x + WIDTH), mm(y + HEIGHT - CORNER_RADIUS)).Q(mm(x + WIDTH), mm(y + HEIGHT), mm(x + WIDTH - CORNER_RADIUS), mm(y + HEIGHT))) | |
# Bottom | |
d.append(dw.Line(mm(x + WIDTH - CORNER_RADIUS), mm(y + HEIGHT), mm(x + CORNER_RADIUS), mm(y + HEIGHT))) | |
# Bottom-Left | |
p = dw.Path() | |
d.append(p.M(mm(x + CORNER_RADIUS), mm(y + HEIGHT)).Q(mm(x), mm(y + HEIGHT), mm(x), mm(y + HEIGHT - CORNER_RADIUS))) | |
# Left | |
d.append(dw.Line(mm(x), mm(y + HEIGHT - CORNER_RADIUS), mm(x), mm(y + CORNER_RADIUS))) | |
d = dw.Drawing(mm(508), mm(308.4), origin=(0,0), id_prefix='d') | |
r = dw.Group(stroke='black', fill='none') | |
for row in range(0, DOWN): | |
for column in range(0, ACROSS): | |
if row == DOWN - 1 and column == 0: | |
full_rectangle(r, 10 + column * WIDTH, 10 + row * HEIGHT) | |
elif column == 0: | |
left_rectangle(r, 10 + column * WIDTH, 10 + row * HEIGHT) | |
elif row == DOWN - 1: | |
bottom_rectangle(r, 10 + column * WIDTH, 10 + row * HEIGHT) | |
else: | |
partial_rectangle(r, 10 + column * WIDTH, 10 + row * HEIGHT) | |
d.append(r) | |
d.save_svg('grid.svg') | |
d.save_png('grid.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment