Created
September 25, 2024 19:34
-
-
Save benkiel/6038c007183d53ab053006ea89bb4220 to your computer and use it in GitHub Desktop.
Draw a glyph in drawbot extension
This file contains hidden or 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
f = CurrentFont() | |
glyphName = "a" | |
size = 1080 | |
newPage (size,size) | |
black = 0,0,0 | |
red = 1,0,0 | |
green = 0,1,0 | |
blue = 0,0,1 | |
white = 1,1,1 | |
pointshape = oval #oval or rect | |
onCurve = 8 | |
onCurvePos = (onCurve/2) | |
offCurve = onCurve | |
offCurvePos = (onCurve/2) | |
glyphStroke = 1 | |
fill(*blue) | |
rect(0,0,1080,1080) | |
# set the glyph stroke | |
strokeWidth(glyphStroke) | |
g = f[glyphName] | |
# position the glyph in the rect | |
translate((size-g.width)/2, 280) | |
# set the glyph's fill & stroke | |
fill(0) | |
stroke(*white) | |
drawGlyph(g) | |
for c in g: | |
for p in c.bPoints: | |
# set the on-curve point fill | |
fill(*white) | |
# set the on-curve point stroke width | |
strokeWidth(glyphStroke) | |
# set the on-curve point stroke colour | |
stroke(*white) | |
(pointshape)(p.anchor[0]-(onCurvePos),p.anchor[1]-(onCurvePos),(onCurve),(onCurve)) | |
# set the off-curve line stroke width | |
# put this before the off-curve points so the points draw over the top, otherwise this will draw over the top of the points | |
strokeWidth(glyphStroke) | |
# set the off-curve line stroke colour | |
stroke(*white) | |
line((p.anchor[0],p.anchor[1]),(p.anchor[0]+p.bcpIn[0],p.anchor[1]+p.bcpIn[1])) | |
line((p.anchor[0],p.anchor[1]),(p.anchor[0]+p.bcpOut[0],p.anchor[1]+p.bcpOut[1])) | |
# set the off-curve point fill | |
fill(*blue) | |
# set the off-curve point stroke width | |
strokeWidth(glyphStroke) | |
# set the off-curve point stroke colour | |
stroke(*white) | |
# set the off-curve point shape, size and position | |
# the anchor position should be 1/2 the size, so it centres correctly | |
if (p.bcpIn[0], p.bcpIn[1]) != (0,0): | |
(pointshape)(p.anchor[0]+p.bcpIn[0]-(offCurvePos),p.anchor[1]+p.bcpIn[1]-(offCurvePos),(offCurve),(offCurve)) | |
if (p.bcpOut[0], p.bcpOut[1]) != (0,0): | |
(pointshape)(p.anchor[0]+p.bcpOut[0]-(offCurvePos),p.anchor[1]+p.bcpOut[1]-(offCurvePos),(offCurve),(offCurve)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment