Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
justvanrossum / Kapitzki.py
Last active Mar 10, 2021
Animated tribute to a work by Herbert W. Kapitzki (DrawBot script)
View Kapitzki.py
# Based on a work by Herbert W. Kapitzki
# https://twitter.com/Lett_Arc/status/1369712193063780352
# from fontTools.misc.vector import Vector
from fontTools.misc.arrayTools import Vector
def pairs(iterable):
it = iter(iterable)
first = next(it)
@justvanrossum
justvanrossum / filename_proposal.py
Last active Jan 30, 2021
Test implementation for new proposed reversible glyph name to file name scheme
View filename_proposal.py
# test implementation for https://github.com/unified-font-object/ufo-spec/issues/164
from urllib.parse import unquote
import string
separatorChar = "^"
# TODO: [insert references]
View CircleOfSquares.py
# boring version of https://twitter.com/beesandbombs/status/1334541858366775298
# <3 beesandbombs!
canvasSize = 800
numFrames = 50
numSquares = 50
radius = 0.3 * canvasSize
squareSize = 0.2 * canvasSize
for frame in range(numFrames):
@justvanrossum
justvanrossum / cubic_evaluator.py
Created Dec 3, 2020
Example of using a nested function to create a cubic Bézier evaluator
View cubic_evaluator.py
from fontTools.misc.bezierTools import calcCubicParameters
def cubic(*cubic_points):
(ax, ay), (bx, by), (cx, cy), (dx, dy) = calcCubicParameters(*cubic_points)
def evaluate(t):
ttt = t * t * t
tt = t * t
x = ax * ttt + bx * tt + cx * t + dx
y = ay * ttt + by * tt + cy * t + dy
return x, y
@justvanrossum
justvanrossum / MEHRINGDAMM.py
Created Apr 16, 2020
MEHRINGDAMM: Spacing by bounding box
View MEHRINGDAMM.py
# Image from https://twitter.com/Berlin_Type/status/1250742042004766730
imagePath = "MEHRINGDAMM.jpeg"
w, h = imageSize(imagePath)
size(w, h)
with savedState():
rotate(0.1)
image(imagePath, (0, 0), 0.6)
@justvanrossum
justvanrossum / Puzzle.py
Created Apr 9, 2020
Jigsaw puzzle generator for DrawBot
View Puzzle.py
def translatePoints(points, dx, dy):
return [(x + dx, y + dy) for x, y in points]
def transposePoints(points):
return [(y, x) for x, y in points]
def pairs(seq):
it = iter(seq)
prev = next(it)
for item in it:
@justvanrossum
justvanrossum / animated_color_grid.py
Created Apr 5, 2020
Animated Color Grid with DrawBot
View animated_color_grid.py
canvasSize = 500
numSquares = 25
squareSize = canvasSize / numSquares
numFrames = 50
for frame in range(numFrames):
t = frame / numFrames
newPage(canvasSize, canvasSize)
frameDuration(1/25)
@justvanrossum
justvanrossum / generateOTTagsModule.py
Last active Aug 20, 2020
Scrape OT tag definitions and descriptions from OT spec site (script, language and feature tags)
View generateOTTagsModule.py
import os
import re
def parse(data):
start = data.find("<tbody>")
end = data.find("</tbody>")
data = data[start+7:end]
for chunk in re.findall(r"<tr>.+?</tr>", data, re.DOTALL):
fields = re.findall(r"<td>(.+?)</td>", chunk, re.DOTALL)
@justvanrossum
justvanrossum / PaulBrownPattern.py
Last active Mar 11, 2020
DrawBot script to recreate 'Untitled Computer Assisted Drawing' by Paul Brown from 1975
View PaulBrownPattern.py
# Original:
# Paul Brown, 'Untitled Computer Assisted Drawing' (1975)
# The program was written in Fortran and drawn with Calcomp's drum pen plotter.
# https://twitter.com/satoshi_aizawa/status/1218786881631965186
def drawArc(center, radius, startAngle, endAngle):
bez = BezierPath()
bez.arc(center, radius, startAngle, endAngle, False)
drawPath(bez)
@justvanrossum
justvanrossum / screen_info.py
Created Jun 6, 2019
macOS/Python: Get dimension info about active screens
View screen_info.py
from AppKit import NSScreen, NSDeviceSize, NSDeviceResolution
from Quartz import CGDisplayScreenSize
for i, screen in enumerate(NSScreen.screens(), 1):
description = screen.deviceDescription()
pw, ph = description[NSDeviceSize].sizeValue()
rx, ry = description[NSDeviceResolution].sizeValue()
mmw, mmh = CGDisplayScreenSize(description["NSScreenNumber"])
scaleFactor = screen.backingScaleFactor()
pw *= scaleFactor