Skip to content

Instantly share code, notes, and snippets.

@justvanrossum
justvanrossum / SierpinskiSquare.py
Last active December 13, 2017 17:40
DrawBot: infinite zoom into a Sierpinski Square (takes a while to render!)
# 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 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 / GrowingCircles.py
Created September 23, 2016 15:37
DrawBot: Generate a progress-spinner-like animation with growing circles.
# Result:
# http://dailydrawbot.tumblr.com/post/150807743869/growing-circles
def circle(pt, radius):
diameter = 2 * radius
x, y = pt
oval(x - radius, y - radius, diameter, diameter)
nFrames = 50
canvasSize = 500
@justvanrossum
justvanrossum / SquareVsLozenge.py
Created May 3, 2016 19:07
DrawBot: Create a simple animation with a grid of rotating squares.
# http://dailydrawbot.tumblr.com/post/143801148619/square-vs-lozenge
def rotatedSquare(x, y, squareSize, angle):
offsetSin = squareSize * sin(radians(angle))
save()
translate(x + offsetSin, 0)
rotate(angle)
rect(0, 0, squareSize, squareSize)
restore()
@justvanrossum
justvanrossum / OscilloscopeLissajous.py
Last active March 24, 2016 06:42
DrawBot: Generate an animation simulating an oscilloscope showing a Lissajous curve.
# http://dailydrawbot.tumblr.com/post/141565208389/oscilloscope-lissajous
canvasSize = 500
nFrames = 20
nSteps = 20
radius = 195
nEchoes = 20
nScopeLines = 10
xFrequency = 3
yFrequency = 4
@justvanrossum
justvanrossum / PsychoDonut.py
Last active February 10, 2016 12:32
DrawBot: Create an animated flower-like pattern by drawing circles on a donut.
# nCirclesH = 18; nCirclesV = 6:
# http://dailydrawbot.tumblr.com/post/138985675364/psychodonut-2
# nCirclesH = 38; nCirclesV = 28:
# http://dailydrawbot.tumblr.com/post/139047595845/psychodonut-3
def project(x, y, innerR, outerR, phase):
# convert from "donut space" to normal space
angle = 2 * pi * x
f = (cos(phase + pi * y) + 1) / 2
R = innerR + f * (outerR - innerR)
@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 / VasarelyCircles.py
Last active September 24, 2021 09:39
DrawBot: Generate a moving interpretation of works by Victor Vasarely.
# http://dailydrawbot.tumblr.com/post/136811506080/circles-after-victor-vasarely-source-code
#
# Based on works by Victor Vasarely
# https://s-media-cache-ak0.pinimg.com/originals/a6/df/1f/a6df1fc5d2dd07d79a44c3aea5172b59.jpg
# https://s-media-cache-ak0.pinimg.com/736x/1e/38/82/1e38820f1304c8750de216a31a5f5abe.jpg
# http://interiorator.com/wp-content/uploads/2013/07/Vasarely-01.jpg
def circle(pt, radius):
diameter = 2 * radius
x, y = pt
@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 / EllsworthKellySeine.py
Last active January 5, 2016 11:12
DrawBot: A moving tribute to Ellsworth Kelly's "Seine" (1951).
# A moving tribute to Ellsworth Kelly's "Seine" (1951).
from random import seed # seed() allows us to get repeatable pseudo-noise
def expandGrid(pixels):
assert len(pixels) % 2
mid = len(pixels) // 2
midColumn = pixels[mid]
pixels.insert(mid + 1, list(midColumn))
pixels.insert(mid + 0, list(midColumn))