Skip to content

Instantly share code, notes, and snippets.

Avatar

Just van Rossum justvanrossum

View GitHub Profile
@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
@justvanrossum
justvanrossum / NestedBoxes.py
Last active Aug 6, 2019
DrawBot: create a simple animation with moving squares
View NestedBoxes.py
# http://dailydrawbot.tumblr.com/post/163234641179/nested-boxes
def easeInOutQuad(t):
t *= 2
if t < 1:
return 0.5 * (t ** 2)
else:
t = 2 - t
return 1 - 0.5 * (t ** 2)
@justvanrossum
justvanrossum / Ellipses.py
Last active Oct 28, 2018
DrawBot: create a simple loop of nested ellipses
View Ellipses.py
# 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 / SierpinskiSquare.py
Last active Dec 13, 2017
DrawBot: infinite zoom into a Sierpinski Square (takes a while to render!)
View SierpinskiSquare.py
# Slightly modified from
# https://twitter.com/petrvanblokland/status/860610270410018817
# by Petr van Blokland @petrvanblokland
def drawSierpinskiSquare(px, py, w, maxW, maxH):
if w < 1:
return
for x in range(3):
for y in range(3):
if x == 1 and y == 1:
@justvanrossum
justvanrossum / LissajousGrid.py
Last active Apr 29, 2020
DrawBot: create a grid of Lissajous curve variations.
View LissajousGrid.py
# 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)
You can’t perform that action at this time.