Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// by dw @ beesandbombs
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 = 16;
int numFrames = 110;
float shutterAngle = .6;
boolean recording = false;
void setup_() {
size(500, 500);
noStroke();
}
void hexx() {
beginShape();
for (int i=0; i<6; i++)
vertex(r*cos(TWO_PI*i/6), r*sin(TWO_PI*i/6));
endShape(CLOSE);
}
int N = 5;
color c1 = #A8DBA8, c2 = #79BD9A, c3 = #3B8686;
float r = 34, sp = 3*r, tt;
float x, y;
float pp = 1.5; // this is how fast the big hexagons twist.
float tt(){ // tt() is an offset version of time which depends on position.
float hd = max(abs(y),abs(.866*x+.5*y)); // hd is kinda like distance from the centre,
hd = max(hd,abs(.866*x-.5*y)); // except in a more hexagonal way
float an = constrain(1.6*t - 0.0017*hd,0,1); // offset time depending on hd
return 3*an*an - 2*an*an*an; // and ease a lil bit
}
void draw_() {
background(c2); // best to use one of the colours in case any leaks through between the shapes >:)
pushMatrix();
translate(width/2, height/2);
scale(pow(sqrt(3),-t)); // shrink exponentially rather than linearly!! looks smoother.
rotate(TWO_PI*t/12);
// do the small hexagons first
for (int i=-N; i<=N; i++) {
for (int j=-N; j<=N; j++) {
fill(c1);
x = i*sp;
y = j*.5*sqrt(3)*sp;
if (j%2 != 0)
x += .5*sp;
pushMatrix();
translate(x, y);
hexx();
popMatrix();
fill(c2);
y = (j-2/3.0)*.5*sqrt(3)*sp;
pushMatrix();
translate(x, y);
hexx();
popMatrix();
fill(c3);
y = (j+2/3.0)*.5*sqrt(3)*sp;
pushMatrix();
translate(x, y);
hexx();
popMatrix();
}
}
// then the big ones!
pushMatrix();
rotate(-TWO_PI/12);
scale(sqrt(3));
for (int i=-N; i<=N; i++) {
for (int j=-N; j<=N; j++) {
fill(c1);
x = i*sp;
y = j*.5*sqrt(3)*sp;
if (j%2 != 0)
x += .5*sp;
pushMatrix();
translate(x, y);
scale(tt());
rotate(TWO_PI/12 + TWO_PI/12*pow(tt(),pp));
hexx();
popMatrix();
fill(c2);
y = (j-2/3.0)*.5*sqrt(3)*sp;
pushMatrix();
translate(x, y);
scale(tt());
rotate(TWO_PI/12 + TWO_PI/12*pow(tt(),pp));
hexx();
popMatrix();
fill(c3);
y = (j+2/3.0)*.5*sqrt(3)*sp;
pushMatrix();
translate(x, y);
scale(tt());
rotate(TWO_PI/12 + TWO_PI/12*pow(tt(),pp));
hexx();
popMatrix();
}
}
popMatrix();
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment