Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
justvanrossum / Jellyfish.py
Last active March 10, 2020 17:11
DrawBot: Generate a jellyfish-like pulsating blobby animation.
# Generate a jellyfish-like pulsating blobby animation.
from random import seed
def varyPoint(pt, radius, phase):
x, y = pt
dx = radius * cos(phase)
dy = radius * sin(phase)
return x + dx, y + dy
@justvanrossum
justvanrossum / PaulBrownPattern.py
Last active March 11, 2020 21:19
DrawBot script to recreate 'Untitled Computer Assisted Drawing' by Paul Brown from 1975
# 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 / Puzzle.py
Created April 9, 2020 15:04
Jigsaw puzzle generator for DrawBot
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 / MEHRINGDAMM.py
Created April 16, 2020 19:18
MEHRINGDAMM: Spacing by bounding box
# 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 / LissajousGrid.py
Last active April 29, 2020 16:51
DrawBot: create a grid of Lissajous curve variations.
# http://dailydrawbot.tumblr.com/post/160078796339/lissajous-grid
# remade from https://twitter.com/fermatslibrary/status/857580490425020416
def lissajous(a, b, phase, radius):
numSteps = 340
points = []
for i in range(numSteps):
angle = 2 * pi * i / numSteps
x = radius * sin(a * angle + phase)
y = -radius * sin(b * angle)
@justvanrossum
justvanrossum / generateOTTagsModule.py
Last active August 20, 2020 08:50
Scrape OT tag definitions and descriptions from OT spec site (script, language and feature tags)
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 / SphericalSpiral.py
Created February 4, 2016 07:08
DrawBot: An Archimedean Spherical Spiral animation.
# This borrows heavily from:
# http://jsfiddle.net/Rebug/5uLr7s6o/
#
# Resulting gif:
# http://dailydrawbot.tumblr.com/post/134989689114/an-archimedean-spherical-spiral
import math
import colorsys
def circle(pt, radius):
@justvanrossum
justvanrossum / Ellipses.py
Last active October 4, 2020 23:36
DrawBot: create a simple loop of nested ellipses
# Result:
# http://dailydrawbot.tumblr.com/post/160364438359/ellipses
def drawEllipses(cx, cy, rx, ry, dx, dy, n, bw=0):
for i in range(n):
fill(bw)
oval(cx - rx, cy - ry, 2 * rx, 2 * ry)
rx -= dx
ry -= dy
bw = 1 - bw
@justvanrossum
justvanrossum / cubic_evaluator.py
Created December 3, 2020 14:29
Example of using a nested function to create a cubic Bézier evaluator
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
# 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):