Skip to content

Instantly share code, notes, and snippets.

Created April 15, 2014 17:40
Show Gist options
  • Save anonymous/10751349 to your computer and use it in GitHub Desktop.
Save anonymous/10751349 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Apr 15, 2014.
    108 changes: 108 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,108 @@
    // by dave @ beesandbombs.tumblr.com
    ////////////////////////////////////

    int[][] result;
    float time;

    void setup() {
    setup_();
    result = new int[width*height][3];
    }

    void draw() {
    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++) {
    time = 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();

    filter(INVERT);

    saveFrame("f##.gif");
    if (frameCount==numFrames)
    exit();
    }

    //////////////////////////////////////////////////////////////////////////////

    int samplesPerFrame = 8;
    int numFrames = 40;
    float shutterAngle = .67;

    void setup_() {
    size(500, 500, P2D);
    smooth(8);
    blendMode(ADD);
    noStroke();
    }


    float x, y, t, d = 30, sp = 2.3*d;
    int N = 12;

    void draw_() {
    t = (2*time)%1;
    t = 3*t*t - 2*t*t*t;
    t = 3*t*t - 2*t*t*t;
    t = .5*t;
    if(time >= .5)
    t += .5;
    background(0);
    pushMatrix();
    translate(width/2, height/2);
    fill(0,20,255);
    for (int i=-N; i<=N; i++) {
    for (int j=-N; j<=N; j++) {
    x = -sp*(i+t); y = sp*.866*j;
    if(j%2 != 0){
    x += .5*sp;
    x *= -1;
    }
    ellipse(x,y,d,d);
    }
    }
    fill(20,255,0);
    pushMatrix();
    rotate(TWO_PI/3);
    for (int i=-N; i<=N; i++) {
    for (int j=-N; j<=N; j++) {
    x = -sp*(i+t); y = sp*.866*j;
    if(j%2 != 0){
    x += .5*sp;
    x *= -1;
    }
    ellipse(x,y,d,d);
    }
    }
    popMatrix();
    fill(255,10,35);
    pushMatrix();
    rotate(TWO_PI*2/3);
    for (int i=-N; i<=N; i++) {
    for (int j=-N; j<=N; j++) {
    x = -sp*(i+t); y = sp*.866*j;
    if(j%2 != 0){
    x += .5*sp;
    x *= -1;
    }
    ellipse(x,y,d,d);
    }
    }
    popMatrix();
    popMatrix();
    }