Last active
March 29, 2016 08:42
-
-
Save jsundram/9337a13938de41b8d22e to your computer and use it in GitHub Desktop.
Skeleton code for CMYK Fractal experiments (see https://twitter.com/search?q=%23CMYKfractal) ; many modifications and tweaks have been made to shapes / layouts angles along the way, this is just the starting point.
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
import time | |
# could MD5 code for unique id, but... | |
# lets assume we want to save every run. | |
v = hex(int(time.time())).upper().replace('0X', 'v') | |
filename = 'circle_%s' % v | |
def setup(): | |
size(1680, 800, P2D) | |
blendMode(SUBTRACT) | |
rectMode(CENTER) # switch between ellipse and rect easier this way | |
randomSeed(int(time.time())) | |
noLoop() | |
def draw(): | |
background(255) | |
paint(width / 2, height / 2, .5*height, level=int(random(4))) | |
if frameCount == 1: # Save once. | |
saveFrame(filename + '.png') | |
def paint(x, y, radius, level=0): | |
noStroke() | |
# Set up colors: | |
a = map(radius, height, 0, 30, 255) # alpha | |
# RGB + alpha | |
colors = map(lambda c: color(*c), [(255, 0, 0, a), (0, 255, 0, a), (0, 0, 255, a)]) | |
# color based on level; karate-style | |
fill(colors[level % len(colors)]) | |
ellipse(x, y, radius, radius) | |
# Need to stop drawing when we get down to be about the size of a pixel. | |
if 2 < radius: | |
# ok to recurse! | |
nr = radius / 2 | |
paint(x + nr, y, nr, level + 1) | |
paint(x - nr, y, nr, level + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment