Created
June 24, 2014 23:18
-
-
Save anonymous/73d147ed64bd04cf32a4 to your computer and use it in GitHub Desktop.
'weaves'
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
// Processing motion blur | |
// 'time' runs from 0 to 1 | |
// ignore everything above the ///////// | |
// by Dave @ beesandbombs | |
int[][] result; | |
float time; | |
void setup() { | |
setup_(); | |
result = new int[width*height][3]; | |
} | |
void draw() { | |
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++) { | |
time = 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 = 16; | |
int numFrames = 96; | |
float shutterAngle = .6; | |
void setup_() { | |
size(500, 500, P2D); | |
smooth(8); | |
rectMode(CENTER); | |
background(0); | |
fill(255); | |
noStroke(); | |
pushMatrix(); | |
translate(width/2,height/2); | |
rotate(QUARTER_PI); | |
for (int i=-N; i<=N; i++) { | |
for (int j=-N; j<=N; j++) { | |
x = i*sp; | |
y = j*sp; | |
if ((i+j)%2 == 0) | |
rect(x, y, sp, sp); | |
} | |
} | |
popMatrix(); | |
msk = get(); | |
} | |
int N = 6; | |
float w = 11, h = 265, o = 50, sp = 16; | |
float t; | |
float x, y; | |
PImage msk, fr; | |
void draw_() { | |
t = time; | |
background(16); | |
pushMatrix(); | |
translate(width/2,height/2); | |
rotate(QUARTER_PI); | |
for (int i=-N; i<=N; i++) { | |
x = i*sp; | |
y = o*sin(TWO_PI*i/(2*N+1) - TWO_PI*t); | |
fill(240, 0, 0); | |
rect(x, y, w, h, 3); | |
} | |
for (int i=-N; i<=N; i++) { | |
y = i*sp; | |
x = o*sin(TWO_PI*i/(2*N+1) - TWO_PI*t); | |
fill(16, 80); | |
rect(x+1, y+1, h+2, w+2, 4); | |
fill(220); | |
rect(x, y, h, w, 3); | |
} | |
fr = get(); | |
fr.mask(msk); | |
background(16); | |
for (int i=-N; i<=N; i++) { | |
y = i*sp; | |
x = o*sin(TWO_PI*i/(2*N+1) - TWO_PI*t); | |
rect(x, y, h, w, 3); | |
} | |
fill(255, 0, 0); | |
for (int i=-N; i<=N; i++) { | |
x = i*sp; | |
y = o*sin(TWO_PI*i/(2*N+1) - TWO_PI*t); | |
fill(16, 80); | |
rect(x+1, y+1, w+2, h+2, 4); | |
fill(240, 0, 0); | |
rect(x, y, w, h, 3); | |
} | |
popMatrix(); | |
image(fr, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment