Skip to content

Instantly share code, notes, and snippets.

@nimrossum
Forked from anonymous/gist:8656123
Created March 16, 2014 01:07
Show Gist options
  • Save nimrossum/9576829 to your computer and use it in GitHub Desktop.
Save nimrossum/9576829 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jan 27, 2014.
    84 changes: 84 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    int[][] result;
    float time;

    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);
    sample();
    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##.png");
    if (frameCount==numFrames)
    exit();
    }

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

    int samplesPerFrame = 32;
    int numFrames = 42;
    float shutterAngle = .75;

    void setup() {
    size(500, 500);
    result = new int[width*height][3];
    noStroke();
    colorMode(HSB, 1);
    }

    float x, y, th, t, tt, l = 50, w = 6;

    void sample() {
    t = time;
    background(0);
    pushMatrix();
    translate(width/2, height/2);
    for (int i=-10; i<=10; i++) {
    for (int j=-15; j<=15; j++) {
    x = l*i;
    y = l*.866*j;
    if (j%2 != 0)
    x += .5*l;
    tt = t + 10.15 - 0.001*dist(x, y, 0, 0);
    tt %= 1;
    if (tt <= .5) {
    tt = 2*tt;
    tt = 3*tt*tt - 2*tt*tt*tt;
    tt = 3*tt*tt - 2*tt*tt*tt;
    tt = .5*tt + 1.5*tt*tt - tt*tt*tt;
    tt *= .5;
    }
    else {
    tt = 2*tt - 1;
    tt = 3*tt*tt - 2*tt*tt*tt;
    tt = 3*tt*tt - 2*tt*tt*tt;
    tt = .5*tt + 1.5*tt*tt - tt*tt*tt;
    tt = tt*.5 + .5;
    }
    fill(abs(tt-.5), 1, 1);
    for (int k=0; k<3; k++) {
    pushMatrix();
    translate(x, y);
    rotate(k*TWO_PI/3 + tt*TWO_PI/3);
    rect(-w/2, 0, w, l*.575);
    popMatrix();
    }
    }
    }
    popMatrix();
    }