Created
July 14, 2014 13:46
-
-
Save anonymous/fe91216793e17a10944c to your computer and use it in GitHub Desktop.
'occult shapes' — http://beesandbombs.tumblr.com/post/91741742904/
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
// by david | |
int[][] result; | |
void setup() { | |
setup_(); | |
result = new int[width*height][3]; | |
} | |
void draw() { | |
if (!recording) { | |
t = mouseX*1.0/width; | |
draw_(); | |
} else { | |
for (int i=0; i<width*height; i++) | |
for (int a=0; a<3; a++) | |
result[i][a] = 0; | |
for (int sa=0; sa<samplesPerFrame; sa++) { | |
t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1); | |
draw_(); | |
loadPixels(); | |
for (int i=0; i<pixels.length; i++) { | |
result[i][0] += pixels[i] >> 16 & 0xff; | |
result[i][1] += pixels[i] >> 8 & 0xff; | |
result[i][2] += pixels[i] & 0xff; | |
} | |
} | |
loadPixels(); | |
for (int i=0; i<pixels.length; i++) | |
pixels[i] = 0xff << 24 | (result[i][0]/samplesPerFrame) << 16 | | |
(result[i][1]/samplesPerFrame) << 8 | (result[i][2]/samplesPerFrame); | |
updatePixels(); | |
saveFrame("f###.gif"); | |
if (frameCount==numFrames) | |
exit(); | |
} | |
} | |
////////////////////////////////////////////////////////////////////////////// | |
int samplesPerFrame = 8; | |
int numFrames = 120; | |
float shutterAngle = .8; | |
boolean recording = true; | |
void setup_() { | |
size(800, 500, P2D); | |
smooth(8); | |
noFill(); | |
} | |
float r(float th, float q) { | |
float pr = cos(PI/3)/cos(th - TWO_PI/3 *floor((3*th + PI)/TWO_PI)); | |
float cr = .69; | |
return lerp(pr, cr, q); | |
} | |
int N = 120; | |
float sc = 185; | |
float x, y; | |
float d, ang; | |
float t; | |
float ph; | |
void figure(float q) { | |
beginShape(); | |
for (int i=0; i<N; i++) { | |
ang = i*TWO_PI/N; | |
d = sc*r(ang, q); | |
x = d*cos(ang); | |
y = d*sin(ang); | |
vertex(x, y); | |
} | |
endShape(CLOSE); | |
} | |
void makeMask() { | |
background(0); | |
fill(255); | |
noStroke(); | |
for (int i=0; i<3; i++) | |
arc(width/2, height/2, 800, 800, (i+.25+.5*t)*TWO_PI/3, (i+.75+.5*t)*TWO_PI/3); | |
} | |
PImage mask, first; | |
float sw = 14; | |
void draw_() { | |
ph = t; | |
for (int i=0; i<3; i++) | |
ph = 3*ph*ph - 2*ph*ph*ph; | |
makeMask(); | |
mask = get(); | |
pushMatrix(); | |
translate(width/2, height/2); | |
rotate(HALF_PI + TWO_PI/6*t); | |
noFill(); | |
background(0); | |
stroke(255); | |
strokeWeight(sw); | |
figure(ph); | |
pushMatrix(); | |
scale(-1, 1); | |
stroke(0); | |
strokeWeight(1.8*sw); | |
figure(1-ph); | |
stroke(255); | |
strokeWeight(sw); | |
figure(1-ph); | |
popMatrix(); | |
first = get(); | |
first.mask(mask); | |
background(0); | |
pushMatrix(); | |
scale(-1, 1); | |
stroke(255); | |
strokeWeight(sw); | |
figure(1-ph); | |
popMatrix(); | |
stroke(0); | |
strokeWeight(1.8*sw); | |
figure(ph); | |
stroke(255); | |
strokeWeight(sw); | |
figure(ph); | |
popMatrix(); | |
image(first, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment