Skip to content

Instantly share code, notes, and snippets.

Avatar

Just van Rossum justvanrossum

View GitHub Profile
@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 / TheBlob.py
Last active Jun 28, 2019
Generate a blobby animated gif with DrawBot.
View TheBlob.py
# FREQUENCY = 1
# http://dailydrawbot.tumblr.com/post/135252661206/the-blob
# FREQUENCY = 2
# http://dailydrawbot.tumblr.com/post/135266061309/the-blob-2
def centerOval(pt, radiusX, radiusY):
x, y = pt
oval(x - radiusX, y - radiusY, 2 * radiusX, 2 * radiusY)
@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 / MarcelDuchampRotoRelief.py
Last active Feb 14, 2018
DrawBot: Emulate some of Marcel Duchamp's Rotoreliefs.
View MarcelDuchampRotoRelief.py
# An interpretation of Marcel Duchamp's Rotoreliefs, as seen in his 1926 movie Anemic Cinema:
# https://www.youtube.com/watch?v=dXINTf8kXCc
def circle(pt, radius):
diameter = 2 * radius
x, y = pt
oval(x - radius, y - radius, diameter, diameter)
canvasSize = 500
nFrames = 64 # 64
@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 / SquareVsLozenge.py
Created May 3, 2016
DrawBot: Create a simple animation with a grid of rotating squares.
View SquareVsLozenge.py
# 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 / GrowingCircles.py
Created Sep 23, 2016
DrawBot: Generate a progress-spinner-like animation with growing circles.
View GrowingCircles.py
# 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 / circlewavegrid.py
Last active Jun 21, 2016
Create a wavy animaton with DrawBot
View circlewavegrid.py
# Physics stolen from:
# http://giphy.com/gifs/wave-circle-point-13ePqdDflwat9e
def blobPos(pt, r, a):
x, y = pt
x += cos(a) * r
y += sin(a) * r
return (x, y)
def drawGrid(cells):
@justvanrossum
justvanrossum / OscilloscopeLissajous.py
Last active Mar 24, 2016
DrawBot: Generate an animation simulating an oscilloscope showing a Lissajous curve.
View OscilloscopeLissajous.py
# 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 Feb 10, 2016
DrawBot: Create an animated flower-like pattern by drawing circles on a donut.
View PsychoDonut.py
# 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)
You can’t perform that action at this time.