Skip to content

Instantly share code, notes, and snippets.

@frankrolf
Last active April 21, 2023 09:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frankrolf/f7066309d094157eae69c0fe68dfeba5 to your computer and use it in GitHub Desktop.
Save frankrolf/f7066309d094157eae69c0fe68dfeba5 to your computer and use it in GitHub Desktop.
Example on how to show a given letter’s off-curve points in DrawBot
# it’s easy to access a letter’s contours through a BezierPath object:
bp = BezierPath()
bp.text(
's',
font='SFProDisplay-Heavy',
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