Last active
March 24, 2016 06:42
-
-
Save justvanrossum/54bf8d52abbc07150ebe to your computer and use it in GitHub Desktop.
DrawBot: Generate an animation simulating an oscilloscope showing a Lissajous curve.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://dailydrawbot.tumblr.com/post/141565208389/oscilloscope-lissajous | |
canvasSize = 500 | |
nFrames = 20 | |
nSteps = 20 | |
radius = 195 | |
nEchoes = 20 | |
nScopeLines = 10 | |
xFrequency = 3 | |
yFrequency = 4 | |
for frame in range(nFrames): | |
newPage(canvasSize, canvasSize) | |
frameDuration(1/30) | |
fill(0.0, 0.1, 0.02) | |
rect(0, 0, canvasSize, canvasSize) | |
translate(canvasSize/2, canvasSize/2) | |
fill(None) | |
strokeWidth(2) | |
for e in range(nEchoes): | |
framePhase = (frame + e) / nFrames | |
alpha = (e + 1) / nEchoes | |
stroke(0, 0.9, 0.2, alpha) | |
bez = None | |
for i in range(nSteps + 1): | |
angle = 2 * pi * (framePhase + i / (nSteps * nFrames)) | |
x = radius * cos(xFrequency * angle) | |
y = radius * sin(yFrequency * angle) | |
if bez is None: | |
bez = BezierPath() | |
bez.moveTo((x, y)) | |
else: | |
bez.lineTo((x, y)) | |
drawPath(bez) | |
# Draw scope grid | |
stroke(0, 0.7) | |
strokeWidth(0.7) | |
for i in range(nScopeLines + 1): | |
pos = canvasSize * (i / nScopeLines - 0.5) | |
line((pos, -canvasSize/2), (pos, canvasSize/2)) | |
line((-canvasSize/2, pos), (canvasSize/2, pos)) | |
saveImage("LissajousOscilloscope.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment