Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bricks
// :)
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), ia = atan(sqrt(.5));
void push() {
pushMatrix();
pushStyle();
}
void pop() {
popStyle();
popMatrix();
}
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 = 8;
int numFrames = 320;
float shutterAngle = .75;
boolean recording = false;
void setup() {
size(720, 720, P3D);
pixelDensity(recording ? 1 : 2);
smooth(8);
result = new int[width*height][3];
rectMode(CENTER);
stroke(20);
strokeWeight(6);
fill(240, 88, 40);
}
float x, y, z, tt;
int N = 12;
float mt = 140, ma = 2;
void brick(float q) {
push();
translate(random(-mt,mt)*q,random(-mt,mt)*q,random(-mt,mt)*q);
scale(.44);
rotateY(random(-ma,ma)*q);
rotateZ(random(-ma,ma)*q);
rotateX(random(-ma,ma)*q);
box(230, 110, 76);
pop();
}
float r = 220;
float th;
void draw_() {
background(250);
push();
translate(width/2, height/2 - 15);
scale(.7);
rotateX(HALF_PI - .57);
for (int a=-1; a<8; a++) {
for (int i=0; i<N; i++) {
th = TWO_PI*i/N + PI*a/N;
push();
rotate(th);
translate(0, r, 40*a - 120);
tt = map(cos(TWO_PI*t - th),-1,1,0,1);
tt = constrain(1.75*tt-0.75,0,1);
tt = ease(tt,5);
randomSeed(123456*i+23456*a+34560);
brick(tt);
pop();
}
}
pop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.