Created
December 18, 2013 22:59
-
-
Save anonymous/8031373 to your computer and use it in GitHub Desktop.
xmas tree gif
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
// motion blur hack starts here | |
int samplesPerFrame = 32; | |
int numFrames = 48; | |
float shutterAngle = 1.0; | |
int[][] result; | |
float time; | |
void setup() { | |
size(500, 500); | |
noStroke(); | |
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); | |
sample(); | |
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] = (result[i][0]/samplesPerFrame) << 16 | | |
(result[i][1]/samplesPerFrame) << 8 | (result[i][2]/samplesPerFrame); | |
updatePixels(); | |
saveFrame("f##.png"); | |
if (frameCount==numFrames) | |
exit(); | |
} | |
// motion blur hack ends here | |
int N = 16; | |
float x, y, d = 18, dd, t, tt; | |
float jj; // it is cool to give variables names like 'dd' and 'jj' | |
void sample() { | |
background(0); | |
for (int i=1; i<N; i++) { // start counting at 1! why not | |
for (int j=-1; j<i+2; j++) { // -1 and 2 for the cheeky extra ones that roll in | |
y = map(i, 1, N-1, 55, height-55); // margin of 55 on the top and bottom i suppose! | |
tt = (time + 50 - 0.016*i)%1; // ?? | |
tt = 3*tt*tt - 2*tt*tt*tt; | |
tt = 3*tt*tt - 2*tt*tt*tt; // cute easing trick that i use all the time now | |
if (i%2 != 0) { | |
fill(64, 220, 32); | |
jj = j+tt; // greens to the right | |
} | |
else { | |
fill(230, 48, 0); | |
jj = j-tt; // and reds to the left. it's a nautical thing | |
} | |
x = width/2 + d*1.4*(jj-.5*i); // who knows | |
dd = d; | |
if (jj<0) | |
dd = max(0, map(jj, -1, 0, 0, d)); // make em grow | |
if (jj>i-1) | |
dd = max(0, map(jj, i, i-1, 0, d)); // or make em shrink | |
ellipse(x, y, dd, dd); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment