Skip to content

Instantly share code, notes, and snippets.

@typoman
Last active April 26, 2021 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typoman/ad40e98df1f836bcc15cca1d2766207f to your computer and use it in GitHub Desktop.
Save typoman/ad40e98df1f836bcc15cca1d2766207f to your computer and use it in GitHub Desktop.
from fontParts.fontshell.font import RFont
from fontTools.pens.cocoaPen import CocoaPen
f = RFont("expand-stroke.ufo") # a ufo with one line path for a glyph (no closed contours)
canvasSize = 800
numFrames = 200
def getGlyphPath(glyph):
pen = CocoaPen(glyph.font)
glyph.draw(pen)
b = BezierPath()
b.setNSBezierPath(pen.path)
return b
def drawMyPath(b, frame, sx, sy, lines):
translate(150, 165)
a = (frame/numFrames)*360 #angle
with savedState():
for i in reversed(range(lines)):
c = i%2
fill(c, c, c, 1)
strokeWidth(i/10+1)
b2 = b.copy()
b2.rotate(a, (0, 0))
b2.scale(sx, sy, (0, 0))
stroked = b2.expandStroke((i + 3)*3) # this is the new expand stroke method
stroked.scale(1/sx, 1/sy, (0, 0))
stroked.rotate(-a, (0, 0))
drawPath(stroked)
def sineLoop(time, totalFrames):
return (sin(((time-totalFrames/4)/totalFrames*2)*pi)+1)/2
b = getGlyphPath(f["z"])
for frame in range(numFrames):
newPage(canvasSize, canvasSize)
frameDuration(1/25)
sx = sineLoop(frame, numFrames)*3+0.1
sy = sineLoop(frame+(numFrames/2), numFrames)*6+0.1
rect(0,0,canvasSize,canvasSize )
drawMyPath(b, frame, sx, sy, 4)
saveImage('test.gif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment