Skip to content

Instantly share code, notes, and snippets.

Created October 15, 2014 20:43
Show Gist options
  • Select an option

  • Save anonymous/8685fe2b31fc78ddc824 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/8685fe2b31fc78ddc824 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Oct 15, 2014.
    138 changes: 138 additions & 0 deletions gistfile1.pde
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,138 @@
    // by dw @ bees & bombs >:)

    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 = 120;
    float shutterAngle = .6;

    boolean recording = false;

    void setup_() {
    size(500, 500, P3D);
    fill(32);
    smooth(8);
    strokeWeight(1.2);
    }

    float x(int i, int j, int k) {
    x = (i-2.5)*sp;
    y = (j-2.5)*sp;
    z = (k-2.5)*sp;

    return x + map(noise(ns*x, ns*y, ns*z), 0, 1, -nm, nm);
    }

    float y(int i, int j, int k) {
    x = (i-2.5)*sp;
    y = (j-2.5)*sp;
    z = (k-2.5)*sp;

    return y + map(noise(ns*x+123, ns*y+456, ns*z+789), 0, 1, -nm, nm);
    }

    float z(int i, int j, int k) {
    x = (i-2.5)*sp;
    y = (j-2.5)*sp;
    z = (k-2.5)*sp;

    return z + map(noise(ns*x+10101, ns*y-3323, ns*z+41414), 0, 1, -nm, nm);
    }


    float x, y, z, tt;
    float x_, y_, z_;
    int N = 6;
    float nm;
    float ns = .02;
    float sp = 45;

    void draw_() {
    nm = map(cos(TWO_PI*t), 1, -1, 0, 1);
    nm = sp*3*ease(nm, 3);
    background(250);
    pushMatrix();
    translate(width/2, height/2);
    rotateY(HALF_PI*t);
    for (int i=0; i<6; i++) {
    for (int j=0; j<6; j++) {
    for (int k=0; k<6; k++) {
    fill(32);
    noStroke();
    pushMatrix();
    translate(x(i, j, k), y(i, j, k), z(i, j, k));
    sphere(2.2);
    popMatrix();

    stroke(32);
    noFill();
    if (i!=N-1)
    line(x(i, j, k), y(i, j, k), z(i, j, k),
    x(i+1, j, k), y(i+1, j, k), z(i+1, j, k));
    if (j!=N-1)
    line(x(i, j, k), y(i, j, k), z(i, j, k),
    x(i, j+1, k), y(i, j+1, k), z(i, j+1, k));
    if (k!=N-1)
    line(x(i, j, k), y(i, j, k), z(i, j, k),
    x(i, j, k+1), y(i, j, k+1), z(i, j, k+1));
    }
    }
    }
    popMatrix();
    }