Skip to content

Instantly share code, notes, and snippets.

@mihnor
Forked from anonymous/gist:d4575d3c4242f5f19f95
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save mihnor/214337670e0f40fd6c20 to your computer and use it in GitHub Desktop.

Select an option

Save mihnor/214337670e0f40fd6c20 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jun 14, 2014.
    84 changes: 84 additions & 0 deletions gistfile1.pde
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    // by Dave @ Bees & Bombs >:)

    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();

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

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

    int samplesPerFrame = 32;
    int numFrames = 150;
    float shutterAngle = .6;

    void setup_() {
    size(500, 500, P2D);
    smooth(8);
    stroke(32);
    noFill();
    }

    int N = 12;
    float d = 25, dd;
    float r = 175;
    float sc = .2;
    float th, x, y, t;
    float om;
    int n = 12;
    float spr;

    void draw_() {
    om = 12*pow(time,1.5);
    spr = TWO_PI/N*pow(max(0,1.5*time-0.5),3);
    background(240);
    pushMatrix();

    translate(0,-100);
    translate(width/2, height/2);
    scale(3.8);

    scale(pow(.5*d/r,time));
    translate(0,r + 13.5);

    for (int i=0; i<N; i++) {
    for (int a=0; a<n; a++) {
    th = i*TWO_PI/N + om*time + spr*a/n;
    x = r*cos(th);
    y = r*sin(th);
    dd = lerp(d, 2.5*r/d, t);
    ellipse(x, y, dd, dd);
    strokeWeight(lerp(2.5, dd, sq(time)));
    }
    }
    popMatrix();
    }