-
Notifications
You must be signed in to change notification settings - Fork 11
/
variable-font-specimen.py
75 lines (66 loc) · 1.94 KB
/
variable-font-specimen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# RENDER THIS DOCUMENT WITH DRAWBOT: http://www.drawbot.com
from drawBot import *
import math
# CONSTANTS
W = 1024 # Width
H = 256 # Height
M = 32 # Margin
U = 32 # Unit (Grid Unit)
F = 64 # Frames (Animation)
# REMAP INPUT RANGE TO VARIABLE FONT AXIS RANGE
# (E.G. SINE WAVE(-1,1) to WGHT(100,900))
def remap(value, inputMin, inputMax, outputMin, outputMax):
inputSpan = inputMax - inputMin # FIND INPUT RANGE SPAN
outputSpan = outputMax - outputMin # FIND OUTPUT RANGE SPAN
valueScaled = float(value - inputMin) / float(inputSpan)
return outputMin + (valueScaled * outputSpan)
# DRAWS A GRID
def grid():
strokeWidth(1)
stroke(0.1)
step_X = 0
step_Y = 0
increment_X = U
increment_Y = U
for x in range(31):
polygon( (M+step_X, M), (M+step_X, H-M) )
step_X += increment_X
for y in range(7):
polygon( (M, M+step_Y), (W-M, M+step_Y) )
step_Y += increment_Y
fill(None)
rect(M, M, W-(2*M), H-(2*M))
fill(0.9)
stroke(None)
# NEW PAGE
def new_page():
newPage(W, H)
frameDuration(1/6)
fill(0)
rect(-2, -2, W+2, H+2)
# TEST FONT
font("../../fonts/variable/CaskaydiaCove[wght].ttf")
for axis, data in listFontVariations().items():
print((axis, data))
varWght = 0
step = -1
# MAIN
for frame in range(F-1):
new_page()
font("../../fonts/variable/CaskaydiaCove[wght].ttf")
grid() # Toggle for grid view
fontSize((M*3))
#print("Sine step:", sin(step))
varWght = remap(sin(step),-1,1,200,700)
fontVariations(wght=varWght)
text("Caskaydia Cove", (M, M*4))
fill(0.3)
weight = str(int(varWght))
weightText = '#Weight[wght]:' + weight
fontVariations(wght=400)
text(weightText, (M, M*1))
# MOVES THE ANIMATION FORWARD
step += 0.1
# SAVE THE ANIMATION IN THIS SCRIPT'S DIRECTORY LOCATION
# POST-PROCESS: gifsicle -i variable-font-specimen.gif --optimize=16 -o output.gif
saveImage("variable-font-specimen.gif")