> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.$FJvTH3C6r$/rev.2
 * 
 * authors: 
 *   (Unnamed author)

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// This sketch builds on a prior work, "Untitled Sketch", created by [unnamed author]
// http://sketchpad.cc/sp/pad/view/ro.cSH7cZc2KZa/rev.2213



class Blob {
    float size;
    PVector vec, pos;

    Blob (float s) {
        size = s;
        vec = new PVector(0, 0, 0);
        pos = new PVector(random(width) - width/2, 150, random(width) - width/2);
    }

    void move() {
        PVector d = vec.get();
        d.mult(0.1);
        pos.add(d);
        float maxWidth=150;
        if (pos.y < height/6) {
            // y = 50 = height/6; maxWidth = width / 2;
            // y = -150 = -height/2; maxWidth = 10;
            maxWidth = (pos.y-height/6)*(4/6)*(width/height) + width/3;
        } else {
            maxWidth = -(pos.y)*(width/height)+(width/2);
        }

        if (pos.x > maxWidth) {
            vec.sub(pos.x - maxWidth, 0, 0);
            pos.x = maxWidth;
        } else if (pos.x < -maxWidth) {
            vec.sub(pos.x + maxWidth, 0, 0);
            pos.x = -maxWidth
        }

        if (pos.z > maxWidth) {
            vec.sub(0, 0, pos.z - maxWidth);
            pos.z = maxWidth;
        } else if (pos.z < -maxWidth) {
            vec.sub(0, 0, pos.z + maxWidth);
            pos.z = -maxWidth
        }

        pos.y = constrain(pos.y, -height/2 + 50, height/2);

        //vec.mult(0.9);
        vec.add(random() - 0.5, random(), random() - 0.5);
        if (pos.y > 0) {
            vec.sub(0, pos.y * random() / 50, 0);
        }
    }

    void draw() {
        pushMatrix();
        translate(pos.x, pos.y, pos.z);
        sphere(size);
        popMatrix();
    }
}

ArrayList blobs;
void setup() {
    size(100, 300, P3D);
    blobs = new ArrayList();

    for (int i = 0; i < 5; i++) {
        blobs.add(new Blob(random(10) + 10));
    }
}

void draw() {
    background(255);
    translate(width/2, height/2);
    noStroke();
    fill(0, 255 - random(20), 0);
    lights();

    for (int i = 0; i < blobs.size(); i++) {
        Blob b = blobs.get(i);
        b.move();
        b.draw();
    }
    //exit();
}