Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2014 23:08
Show Gist options
  • Select an option

  • Save anonymous/47a4fb67dfc50987e071 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/47a4fb67dfc50987e071 to your computer and use it in GitHub Desktop.
twitter gif
int[][] result;
float t;
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);
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("f###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 16;
int numFrames = 240;
float shutterAngle = 1;
boolean recording = false;
void setup_() {
size(700, 500);
noStroke();
}
float x, y, tt;
int N = 128;
float th, d;
float v;
void draw_() {
background(24);
pushMatrix();
translate(width/2, height/2);
rotate(-HALF_PI*ease(t, 2));
for (int i=0; i<N; i++) {
th = i*TWO_PI/N;
fill(255, 255, 0);
d = 35;
v = 5;
if (i%2 == 0) {
fill(220, 0, 200);
d = 65;
v = 4;
}
if (i%4 == 0) {
fill(0, 255, 200);
d = 95;
v = 3;
}
if (i%8 == 0) {
fill(240, 40, 0);
d = 125;
v = 2;
}
if (i%16 == 0) {
fill(255);
d = 155;
v = 1;
}
pushMatrix();
rotate(th);
pushMatrix();
translate(90, 0);
rotate(TWO_PI*v*ease(t, 2.5));
ellipse(d/2, 0, 2+d/18, 2+d/18);
popMatrix();
popMatrix();
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment