Skip to content

Instantly share code, notes, and snippets.

Created Oct 10, 2016
Embed
What would you like to do?
:)
// by dave bees >:)
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
else
return 1 - 0.5 * pow(2*(1 - p), g);
}
float mn = .5*sqrt(3);
void setup() {
setup_();
result = new int[width*height][3];
}
void draw() {
if (!recording) {
t = mouseX*1.0/width;
c = mouseY*1.0/height;
if (mousePressed)
println(c);
draw_();
} else {
for (int i=0; i<width*height; i++)
for (int a=0; a<3; a++)
result[i][a] = 0;
c = 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 |
int(result[i][0]*1.0/samplesPerFrame) << 16 |
int(result[i][1]*1.0/samplesPerFrame) << 8 |
int(result[i][2]*1.0/samplesPerFrame);
updatePixels();
saveFrame("f###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 4;
int numFrames = 108;
float shutterAngle = .6;
boolean recording = false;
void setup_() {
size(500, 500, P3D);
rectMode(CENTER);
noStroke();
smooth(8);
ortho();
}
float x, y, tt;
int N = 5, n = 64;
float l = 36, h = 240;
float sp = 1.75*l, q;
int in;
void colu() {
noStroke();
for (int a=0; a<4; a++) {
pushMatrix();
rotateY(HALF_PI*a);
translate(0, 0, l/2);
for (int i=0; i<n; i++) {
fill(32+218*pow(map(i, 0, n-1, 0, 1), 2.5));
rect(0, map(i+.5, 0, n, h/2, -h/2), l, h/n);
}
popMatrix();
}
fill(255);
pushMatrix();
translate(0, -h/2, 0);
rotateX(HALF_PI);
rect(0, 0, l, l);
popMatrix();
}
void draw_() {
background(32);
pushMatrix();
translate(width/2, height/2);
scale(.82);
scale(-1,1);
rotateX(-atan(sqrt(.5)));
rotateY(PI+QUARTER_PI);
for (int a=0; a<4; a++) {
pushMatrix();
rotateY(HALF_PI*a);
for (int i=0; i<4; i++) {
in = 4*a + i;
q = in/20.0;
tt = ease(constrain(7*t-5*q-1,0,1),3);
pushMatrix();
translate((i-2)*sp, -100*tt + 100*t + 50, 2*sp);
colu();
popMatrix();
}
popMatrix();
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment