Skip to content

Instantly share code, notes, and snippets.

@rsms
Last active June 9, 2022 19:16
Show Gist options
  • Save rsms/98755619b19cce7cd1236662581b2ce8 to your computer and use it in GitHub Desktop.
Save rsms/98755619b19cce7cd1236662581b2ce8 to your computer and use it in GitHub Desktop.
import math, random, os.path
from perlin_noise import PerlinNoise
from math import pi as PI
def pathtext(text, pos, size, wght, opsz=32, **kwargs):
t = FormattedString(
font="Inter.var.ttf", fontSize=size, align="center",
#openTypeFeatures={},
fontVariations={"wght":wght,"opsz":opsz}, **kwargs)
t.append(text)
path = BezierPath()
path.text(t, pos)
#path.removeOverlap()
return path
def centerPathY(path):
bounds = path.bounds()
path.translate(0, (bounds[3] - bounds[1]) / -2.0)
def rotatePath(path, degrees):
# rotate around its own center
b = path.bounds()
w = b[2] - b[0]
h = b[3] - b[1]
path.rotate(degrees, (b[0] + w*0.5, b[1] + h*0.5))
def drawCircle(pos, radius):
oval(pos[0] - radius, pos[1] - radius, radius*2, radius*2)
def checkRangeStep(r, name=""):
nmax = r[1] - r[0]
step = r[2]
if round(nmax / step) == nmax / step:
return r
step2 = floor(nmax / ceil(nmax/step))
print("%s step %r not an even multiplier of max value %r; using %r instead" % (
name, step, nmax, step2))
return (r[0], r[1], step2)
class Vec2:
def __init__(self, x, y):
self.x = x
self.y = y
class Rect:
def __init__(self, x, y, w, h):
self.x = x
self.y = y
self.w = w
self.h = h
def tuple(self):
return (self.x, self.y, self.w, self.h)
scale = 10
size(110*scale, 110*scale)
w = width()
h = height()
colorSpace("genericRGB")
fill(1, 0.975, 0.93)
rect(0, 0, w, h)
blendMode("multiply")
margin = 30*scale
bounds_yt = 0.9 # % of center on the Y axis (optical center)
margin_y0 = margin*(1 + 1-bounds_yt)
bounds = Rect(
margin, margin_y0,
w - margin*2, h - margin_y0 - margin*bounds_yt )
#stroke(0,0,0,0.2) ; rect(*bounds.tuple()) # viz bounds
opszRange = (16, 32)
wghtRange = (100, 900)
opszCount = 3
wghtCount = 5
fontSize = 120
stroke(None)
fill(None)
for y in range(wghtCount):
y_t = y / (wghtCount - 1)
y = bounds.y + y_t * bounds.h
wght = wghtRange[0] + (wghtRange[1] - wghtRange[0]) * y_t
for x in range(opszCount):
x_t = x / (opszCount - 1)
x = bounds.x + x_t * bounds.w
opsz = opszRange[0] + (opszRange[1] - opszRange[0]) * x_t
tracking = (-3 + 2*x_t)
path = pathtext("Aa", (x, y), fontSize, wght, opsz,
tracking=tracking)
centerPathY(path)
cmykFill(1.0-x_t, 0.03+abs(0.97-y_t), 1.0-cos(y_t+x_t), 0)
drawPath(path)
m = 0.3
cmykFill((1.0-x_t)*m, (0.03+abs(0.97-y_t))*m, (1.0-cos(y_t+x_t))*m, 0)
drawPath(path)
saveImage("out/%s.pdf" % os.path.splitext(os.path.basename(__file__))[0])
@rsms
Copy link
Author

rsms commented Jun 9, 2022

wght-opsz-aa2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment