-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDecovarBanner.py
More file actions
112 lines (95 loc) · 4.32 KB
/
DecovarBanner.py
File metadata and controls
112 lines (95 loc) · 4.32 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -----------------------------------------------------------------------------
# Copyright (c) 2016+ Buro Petr van Blokland + Claudia Mens
# www.pagebot.io
#
# P A G E B O T
#
# Licensed under MIT conditions
#
# Supporting DrawBot, www.drawbot.com
# Supporting Flat, xxyxyz.org/flat
# -----------------------------------------------------------------------------
#
from random import random
from math import sin, cos, radians
from pagebot.fonttoolbox.objects.font import findFont
from pagebot.elements.vf.animationframe import AnimationFrame
from pagebot.document import Document
from pagebot.constants import Letter, RIGHT
from pagebot.contexts.drawbotcontext import DrawBotContext
from pagebot.conditions import *
from pagebot.toolbox.color import Color, color, blackColor
from pagebot.toolbox.units import em
class AnimatedBannerFrame(AnimationFrame):
def drawAnimatedFrame(self, view, origin):
"""Draw the content of the element, responding to size, styles, font and content.
Create 2 columns for the self.fontSizes ranges that show the text with and without [opsz]
if the axis exists.
"""
ox, oy, _ = origin
c = self.context
style = self.style.copy()
instance = self.vfFont.getInstance({}) # Get neutral instance
style['font'] = instance.path
style['textFill'] = Color(0.5, 0.5, 0.5, 0.7) # Opaque gray as background
bs = c.newString(self.sampleText, style=style)
tw, th = bs.size
c.text(bs, (self.w/2 - tw/2, self.h/3+20))
# Now make instance and draw over regular and add to new copy of the style
style = self.style.copy()
instance = self.vfFont.getInstance(self.style['variableLocation'])
style['font'] = instance.path
#print(self.frameIndex, style['font'])
#style['fontSize'] = self.h/3
bs = c.newString(self.sampleText, style=style)
tw, th = bs.size
c.text(bs, (self.w/2 - tw/2, self.h/3+20))
c = DrawBotContext()
w, h = 2040, 1020 # Type Network banners
font = findFont('DecovarAlpha-VF')
# Decovar axes to select from
# 'BLDA' Inline
# 'TRMG' Serif terminals
# 'BLDB' Turning flourishes
# 'SKLA' Blocked inside
# 'SKLD' Striped stems
# 'TRMA' Rounded
# 'SKLB' Turning round flourishes
# 'TRMC' Round terminal serifs
# 'TRMB' Sharp terminal serifs
# 'TRME' Split sharp terminal serifs
# 'TRMD' Angled terminals
# 'WMX2' Contrast width black
# 'TRMF' Plus terminals
# 'TRMK' Rectangle inside terminal
# 'TRML' Diamond inside terminal
# Define tag list for axes to be part of the animation as sequence
sequenceAxes = ['TRMC', 'SKLD', 'TRMG', 'BLDB']
#sequenceAxes = ['SKLD', 'BLDB', 'TRMK', 'BLDA']
sequenceLength = 3 # Seconds per sequence
sequences = len(sequenceAxes) # Amount of sequences, one per axis
duration = sequenceLength * len(sequenceAxes) # Total duration of the animation in seconds
framesPerSecond = 10
frameCnt = duration * framesPerSecond # Total number of frames
axisFrames = sequenceLength * framesPerSecond # Number of frames per axis sequence.
# Create a new doc, with the right amount of frames/pages.
doc = Document(w=w, h=h, originTop=False, frameDuration=1.0/framesPerSecond,
autoPages=frameCnt, context=c)
# Sample text to show in the animation
sample = font.info.familyName #'Decovar'
frameIndex = 1 # Same as page index in the document
for axisTag in sequenceAxes:
minValue, defaultValue, maxValue = font.axes[axisTag]
for axisFrameIndex in range(axisFrames):
page = doc[frameIndex] # Get the current frame-page
axisRange = maxValue - minValue
phisin = sin(radians(axisFrameIndex/axisFrames * 360+3/4*360))*0.5+0.5
# Variable Font location for this frame sample
variableLocation = {axisTag: phisin*axisRange+minValue}
# Overall style for the frame
style = dict(leading=em(1.4), fontSize=400, xTextAlign=RIGHT, textFill=color(1),
fill=blackColor, variableLocation=variableLocation)
af = AnimatedBannerFrame(sample, font, frameCnt, frameIndex, parent=page, padding=0, style=style,
w=page.w, h=page.h, context=c)
frameIndex += 1 # Prepare for the next frame
doc.export('images/%s_%s.gif' % (font.info.familyName, sample))