Skip to content

Instantly share code, notes, and snippets.

Created December 1, 2014 17:38
Show Gist options
  • Select an option

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

Select an option

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

Revisions

  1. @invalid-email-address Anonymous created this gist Dec 1, 2014.
    117 changes: 117 additions & 0 deletions gistfile1.pde
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,117 @@
    // by dave @beeesandbombs

    int[][] result;
    float t, c;

    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;
    c = mouseY*1.0/height;
    if(mousePressed)
    println(c);
    draw_();
    }

    else {
    for (int i=0; i<width*height; i++)
    for (int a=0; a<3; a++)
    result[i][a] = 0;

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

    boolean recording = false;

    void setup_() {
    size(500,500,P3D);
    rectMode(CENTER);
    fill(0,200,0);
    noStroke();
    }

    float x, y, z, tt;
    int N = 1600;
    float r = 130, rr, d;
    float th, ph;

    void draw_() {
    background(250);
    lights();
    pushMatrix();
    translate(width/2, height/2);
    rotateX(-.2);
    rotateY(.3);
    rotate(HALF_PI);
    for(int i=0; i<N; i++){
    fill(32);
    if(i%150 < 75)
    fill(240,32,32);
    if(i%150 < 15)
    fill(240,210,32);
    if(i%150 > 74 && i%150 < 90)
    fill(240,210,32);
    d = 4 + 5.0*i/N;
    th = i*PI/N + TWO_PI*t;
    rr = map(sin(th),.875,-1,0,r);
    rr = constrain(rr,0,r);
    ph = 12*th + 2*TWO_PI*t;
    x = rr*cos(ph)*sin(th);
    z = rr*sin(ph)*sin(th);
    y = r*cos(th);
    pushMatrix();
    translate(x,y,z);
    sphere(d);
    popMatrix();
    }
    popMatrix();
    noLights();
    }