Skip to content

Instantly share code, notes, and snippets.

Created November 12, 2014 19:07
Show Gist options
  • Save anonymous/271707d9682ea025cda5 to your computer and use it in GitHub Desktop.
Save anonymous/271707d9682ea025cda5 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Nov 12, 2014.
    126 changes: 126 additions & 0 deletions gistfile1.pde
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,126 @@
    // lol forgive me for this code

    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 = 4;
    int numFrames = 180;
    float shutterAngle = .6;

    boolean recording = true;

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

    float x, y, tt, ttt;
    float l, w;
    int N = 12;
    float d = 40, th;

    void arc_(){
    beginShape();
    for(int i=0; i<=N; i++){
    th = i*HALF_PI/N;
    x = -l/2 + l/2*cos(th);
    y = -w/2 + w/2*sin(th);
    vertex(x,y);
    }
    endShape();
    }

    void draw_() {
    background(250);
    pushMatrix();

    translate(width/2, height/2);
    for (int i=-N; i<=N; i++) {
    for (int j=-N; j<=N; j++) {
    tt = (t + 100 - 0.04*(abs(i)+abs(j)));
    tt %= 1;
    ttt = (2*tt) % 1;
    ttt = min(1,1.4*ttt);
    l = d*ease(pow(ttt,.75),2.5);
    w = d*ease(pow(1-ttt,.75),2.5);
    pushMatrix();
    translate(d*i, d*j);
    if(tt>=.5)
    rotate(HALF_PI);
    arc_();
    pushMatrix();
    scale(1,-1);
    arc_();
    popMatrix();
    pushMatrix();
    scale(-1,1);
    arc_();
    popMatrix();
    pushMatrix();
    scale(-1,-1);
    arc_();
    popMatrix();
    popMatrix();
    }
    }
    popMatrix();
    }