Skip to content

Instantly share code, notes, and snippets.

@eqx
Created August 29, 2016 00:01
Show Gist options
  • Save eqx/5209e8f7d4f12258e33f5b581604f16b to your computer and use it in GitHub Desktop.
Save eqx/5209e8f7d4f12258e33f5b581604f16b to your computer and use it in GitHub Desktop.
// by dave whyte; drop me a line if you use this!
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 |
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("g###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 16;
int numFrames = 120;
float shutterAngle = .5;
boolean recording = false;
void setup_() {
size(800, 600, P3D);
smooth(8);
noFill();
strokeWeight(3.2);
stroke(250);
}
float ease(float q){
return 3*q*q - 2*q*q*q;
}
float R = 230, r = 130;
int N = 12, M = 200;
float x, y, z;
float th, ph;
float tw;
float tt;
void draw_() {
background(91,171,162);
pushMatrix();
translate(width/2, height/2 - 68, -300);
rotateX(-.8);
rotateY(PI*t);
tw = map(cos(TWO_PI*t), 1, -1, 0, 1);
tw = PI*2/3*ease(tw);
tt = constrain(1.8*t-0.4,0,1);
tt = ease(tt);
for (int a=0; a<N; a++) {
pushMatrix();
beginShape();
for (int i=0; i<M; i++) {
th = i*TWO_PI/M;
ph = HALF_PI + (a+2*tt)*TWO_PI/N + tw*cos(2*th);
x = (R + r*cos(ph))*cos(th);
y = r*sin(ph);
z = (R + r*cos(ph))*sin(th);
vertex(x, y, z);
}
endShape(CLOSE);
popMatrix();
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment