Last active
September 24, 2021 09:39
-
-
Save justvanrossum/c5e017ac5524e2adad6b to your computer and use it in GitHub Desktop.
DrawBot: Generate a moving interpretation of works by Victor Vasarely.
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/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 | |
oval(x - radius, y - radius, diameter, diameter) | |
def interpolateColor(color1, color2, f): | |
assert len(color1) == len(color2) | |
return tuple(ch1 + f * (ch2 - ch1) for ch1, ch2 in zip(color1, color2)) | |
canvasSize = 500 | |
nFrames = 64 | |
colors1 = [(1, 0.3, 0.3), (0, 0, 0)] | |
colors2 = [(0, 0, 0), (0.3, 0.3, 1)] | |
for frame in range(nFrames): | |
framePhase = frame/nFrames | |
newPage(canvasSize, canvasSize) | |
frameDuration(1/20) | |
rect(0, 0, canvasSize, canvasSize) | |
translate(canvasSize/2, canvasSize/2) | |
radius = 0.97 * canvasSize/2 | |
nCircles = 22 | |
stepSize = radius / nCircles | |
whichColor = 0 | |
for i in range(nCircles): | |
f = i / (nCircles - 1) | |
fill(*interpolateColor(colors1[whichColor], colors2[whichColor], f)) | |
x = sin(2 * pi * framePhase) * 68 * sin(pi * f) | |
circle((x, 0), radius) | |
whichColor = 1 - whichColor | |
radius -= stepSize | |
saveImage("VasarelyCircles.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment