Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
int[][] result;
float t;
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 = 4;
int numFrames = 150;
float shutterAngle = .6;
boolean recording = false;
void setup_() {
size(500, 500);
noStroke();
smooth(8);
}
int N = 49;
float rmin, rmax, w;
float rst, ren;
float tt;
void drawDiamonds() {
for (int i=0; i<N; i++) {
pushMatrix();
rotate(-i*TWO_PI/N);
tt = (t + i*25.0/49) % 1;
tt = 3*tt*tt - 2*tt*tt*tt;
rst = map(pow(constrain(3*tt, 0, 1), .5), 0, 1, rmin, rmax);
ren = map(pow(constrain(3*tt-2, 0, 1), 2), 0, 1, rmin, rmax);
beginShape();
vertex(rst, 0);
vertex(.5*(rst+ren), -w/2);
vertex(ren, 0);
vertex(.5*(rst+ren), w/2);
endShape();
popMatrix();
}
}
void draw_() {
w = 7;
rmin = 74;
rmax = 205;
background(0);
fill(0, 200, 150);
pushMatrix();
translate(width/2, height/2);
drawDiamonds();
filter(BLUR, 4);
w -= 2;
rmax -=3;
rmin += 3;
fill(250);
drawDiamonds();
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment