Skip to content

Instantly share code, notes, and snippets.

@LettError
Created October 29, 2023 07:30
Show Gist options
  • Save LettError/c6c10c930d3a8788cac2e7029772a920 to your computer and use it in GitHub Desktop.
Save LettError/c6c10c930d3a8788cac2e7029772a920 to your computer and use it in GitHub Desktop.
Drawbot animation with LTR NCND Variable.
# another animation generator
# for NCND fun only
# 2023 letterror.com
# the number of frames for this animation
frames = 25
# margin, in pixels
margin = 20
# the size, it is a square video.
dim = 600
# the name of this font
xvf = "NCNDVF-Regular"
# cute lil interplation function
def ip(a,b,f):
return a+f*(b-a)
# this calculates a point size for the number of columns
# that have to fit on the width of the animation.
def colCalc(cols):
ptwidth = (width()-2*margin)/cols
return 1000*ptwidth/550
# this calculates the number of columns (see colCalc)
# needed for the text
def maxCols(t):
lines= t.split('\n')
lines = [l.replace("~", "") for l in lines]
return max([len(l) for l in lines])
# this returns a reandom weight for LTR NCNDVF
def varWeight(wght, d = 40):
return max(min(wght+randint(-d, d), 900),250)
texts = [
("awesome-typewriter", "LtrNCND\n|spooky\n| type\nwriter!", 50),
]
def url():
with savedState():
font(xvf)
fontSize(30)
fontVariations(wght=800)
fill(0.8,0,0)
text("A variable typewriter:\nLearn more: LettError.com/ncnd", (20, 50,))
clrName = "white"
for name, t, tuck_y in texts:
for count in range(frames+1):
cols = maxCols(t)
newPage(dim, dim)
fill(1)
rect(0,0,width(),height())
lc = len(t.split("\n"))+1
fsz = colCalc(cols)
factor = count/frames
fs = FormattedString()
fs.font(xvf)
fs.fontSize(fsz)
fs.lineHeight((height()-2*margin)/(lc))
fs.openTypeFeatures(ss01=True, lnum=True, zero=True)
if factor < .5:
wghtValue = ip(250, 950, 2*factor)
fs.fontVariations(wght=ip(250, 950, 2*factor))
else:
wghtValue = ip(250, 950, 2*(1-factor))
fs.fontVariations(wght=ip(250, 950, 2*(1-factor)))
for l in t.split("\n"):
fs.fill(0)
for c in l:
cw = varWeight(wghtValue)
fs.fontVariations(wght=cw)
fs.append(c)
fs.append("\n")
rc = (margin, margin, width()-2*margin, height()-2*margin-tuck_y)
textBox(fs, rc)
url()
saveImage(f"LTR_NCND_{name}_{clrName}.mp4")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment