Last active
November 21, 2019 11:52
-
-
Save straversi/69cb0aa25e406662c5ab6a30f047a8cf to your computer and use it in GitHub Desktop.
Draw a variable font grid with DrawBot.
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
# Draw a grid of characters, changing variable font axes along | |
# the X and Y. | |
# Set the uppercased CONSTANT values to customize the output. | |
# For use with DrawBot drawbot.com | |
CONTENT = "A" | |
OUT_FILE_NAME = "./result.svg" | |
COLUMNS = 8 | |
ROWS = 8 | |
COLUMN_WIDTH = 50 | |
ROW_HEIGHT = 60 | |
size((COLUMNS + 1) * COLUMN_WIDTH, | |
(ROWS + 1) * ROW_HEIGHT) | |
# Use to help vertically center the grid. | |
BOTTOM_MARGIN = 40 | |
# "Graduate" font from github.com/etunni/Graduate-Variable-Font | |
FONT_FAMILY = installFont("./GRADUATE.ttf") | |
FONT_SIZE = 60 | |
# Variable font axis to vary along the X | |
# Add small delta, some fonts don't render correctly | |
# when using a boundary value. | |
X_AXIS = "XOPQ" | |
X_MIN = 40 + 0.1 | |
X_MAX = 200 | |
# Variable font axis to vary along the Y | |
# Add small delta, some fonts don't render correctly | |
# when using a boundary value. | |
Y_AXIS = "CNTR" | |
Y_MIN = 0 + 0.1 | |
Y_MAX = 100 | |
for c in range(COLUMNS): | |
x_progress = c / COLUMNS | |
for r in range(ROWS): | |
y_progress = r / ROWS | |
x = (c + 1) * COLUMN_WIDTH | |
y = r * ROW_HEIGHT + BOTTOM_MARGIN | |
variations = { | |
X_AXIS: (X_MAX - X_MIN) * x_progress + X_MIN, | |
Y_AXIS: (Y_MAX - Y_MIN) * y_progress + Y_MIN, | |
} | |
txt = FormattedString( | |
txt=CONTENT, | |
font=FONT_FAMILY, | |
fontSize=FONT_SIZE, | |
fontVariations=variations | |
) | |
path = BezierPath() | |
path.text(txt, (x, y), align="center") | |
drawPath(path) | |
uninstallFont(FONT_FAMILY) | |
saveImage(OUT_FILE_NAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment