-
-
Save arrowtype/6a6c194c45e3ba8c9e89309c95800ec3 to your computer and use it in GitHub Desktop.
Example on how to show a given letter’s off-curve points in 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
# it’s easy to access a letter’s contours through a BezierPath object: | |
bp = BezierPath() | |
bp.text( | |
's', | |
font='.SFNSDisplayCondensed-Black', | |
fontSize=1200) | |
# Fill the letter, and offset the whole canvas so it sits in the middle. | |
fill(1, 1, 0) | |
letter_width = bp.bounds()[-2] - bp.bounds()[0] | |
x_offset = (width() - letter_width) / 2 | |
translate(x_offset, 160) | |
drawPath(bp) | |
previous_oncurve = None | |
# draw the lines | |
lineDash(5) | |
stroke(0) | |
strokeWidth(3) | |
# go through the contours: | |
for contour in bp: | |
for segment in contour: | |
if len(segment) == 3: | |
# this is a curveTo. Draw the lines. | |
offcurve_1, offcurve_2, oncurve = segment | |
line(previous_oncurve, offcurve_1) | |
line(offcurve_2, oncurve) | |
else: | |
# it is a lineTo. No drawing needed here. | |
oncurve = segment[-1] | |
previous_oncurve = oncurve | |
# offset everything a bit lower, because the lemons sit | |
# on the baseline | |
translate(0, -10) | |
# draw the lemons, same way as we’ve been drawing the contours: | |
# size of lemons: | |
fontSize(35) | |
for contour in bp: | |
for segment in contour: | |
if len(segment) == 3: | |
offcurve_1, offcurve_2, oncurve = segment | |
text('🍊', offcurve_1, align='center') | |
text('🍊', offcurve_2, align='center') | |
else: | |
oncurve = segment[-1] | |
text('🍋', oncurve, align='center') | |
previous_oncurve = oncurve | |
saveImage('~/Desktop/lemon.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment