Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hexagon/star — tmblr.co/ZOLwww1Oatoyp
// by dw @ bees & bombs >:)
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 = 120;
float shutterAngle = .8;
boolean recording = false;
void setup_() {
size(500, 500, P2D);
smooth(8);
noFill();
strokeWeight(3.5);
stroke(32);
strokeWeight(5.5);
colorMode(HSB, 1);
}
float R = 140, r;
float r1, r2;
float th;
float t1, t2, tt;
float ease(float q) {
return 3*q*q - 2*q*q*q;
}
PImage blurred;
void drawFigure() {
beginShape();
for (int i=0; i<12; i++) {
th = i*TWO_PI/12;
if (i%2 == 0)
vertex(lerp(r1, r1/2, t2)*cos(th), lerp(r1, r1/2, t2)*sin(th));
else {
vertex(r2*cos(th), r2*sin(th));
}
}
endShape(CLOSE);
for (int i=0; i<12; i++) {
th = i*TWO_PI/12;
if (i%2 != 0)
line(r2*cos(th), r2*sin(th), r2*lerp(cos(th), cos(th+TWO_PI/6), t1*t1), r2*lerp(sin(th), sin(th+TWO_PI/6), t1*t1));
}
}
void draw_() {
t1 = ease(constrain(2*t, 0, 1));
t2 = ease(constrain(2*t-1, 0, 1));
r = R*pow(sqrt(3), t);
r1 = r;
r2 = r*lerp(.5*sqrt(3), 1/sqrt(3), t1);
background(0);
stroke(t, 1, .75);
strokeWeight(12);
pushMatrix();
translate(width/2, height/2);
rotate(TWO_PI*t/12);
drawFigure();
filter(BLUR, 2);
blurred = get();
background(0);
stroke(1);
strokeWeight(5);
drawFigure();
blend(blurred, 0, 0, width, height, 0, 0, width, height, ADD);
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment