Jellyfish.py
This file contains hidden or 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
Show hidden characters
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
def drawBlob(blobPhase, blobRadius):
points = [] # list of off curve points forming the blob.
for i in range(numBlobPoints):
a = 2 * pi * i / numBlobPoints
x = blobRadius * cos(a)
y = blobRadius * sin(a)
rPhase, rSign = randomPhases[i]
points.append(varyPoint((x, y), 0.2 * blobRadius, rPhase + rSign * 2 * pi * blobPhase))
points.append(None)
bezPath = BezierPath()
bezPath.qCurveTo(*points)
bezPath.closePath()
drawPath(bezPath)
seed(0) # Ok ok, make this animation predictable.
numBlobPoints = 5
randomPhases = [(2 * pi * random(), choice([-1, 1])) for i in range(numBlobPoints)] canvasSize = 500
nBlobs = 24
nFrames = 95
for frame in range(nFrames):
framePhase = frame / nFrames
newPage(canvasSize, canvasSize)
frameDuration(1/20)
fill(0)
rect(0, 0, canvasSize, canvasSize)
translate(canvasSize/2, canvasSize/2)
strokeWidth(2)
stroke(1)
fill(None)
for i in range(nBlobs):
blobPhase = i / nBlobs
radius = 5 + i * 10
drawBlob(framePhase + blobPhase * 0.75, radius)
saveImage("Jellyfish.gif")