class Droplet { // Node management Particle node; boolean onLeaf = false; float yy; Leaf myLeaf; // Constructors /////////////////////////////////////////////////////////////// Droplet() { this(random(0, width), 0); // Start at the top by default } Droplet(float x, float y) { node = ps.makeParticle(random(0.5, 2.0), x, y, 0); } Droplet(float x, float y, float m, float vx, float vy) { node = ps.makeParticle(m, x, y, 0); node.setVelocity(vx, vy, 0); } // Workings /////////////////////////////////////////////////////////////////// void update() { if (node.mass() > 2) onLeaf = false; // Draw the droplet if (onLeaf) { float p = ((yy - node.position().y()) / 2); if (myLeaf.isLeft) { node.moveTo(node.position().x() - p/3, yy + p, 0); } else { node.moveTo(node.position().x() + p/3, yy + p, 0); } fill(1, 105, 201, 60); stroke(1, 151, 253, 30); strokeWeight(8); float n = node.mass() * 4; float w = 0.25; float q = random(-w, w); beginShape(); // Top of the drop curveVertex(node.position().x() + q, node.position().y() - n / 2 + q); curveVertex(node.position().x() + q, node.position().y() - n / 2 + q); // Right-hand side curveVertex(node.position().x() + n * 1.25 + q, node.position().y() + q); // Bottom curveVertex(node.position().x() + q, node.position().y() + n / 2 +q); // Left-hand side curveVertex(node.position().x() - n * 1.25 + q, node.position().y() + q); // Back to the to to finish curveVertex(node.position().x() + q, node.position().y() - n / 2 + q); curveVertex(node.position().x() + q, node.position().y() - n / 2 + q); endShape(); noStroke(); fill(179, 222, 253, 80); ellipse(node.position().x() - (n / 2), node.position().y() - (n / 2), n / 1.5, n / 1.5); } else { fill(1, 105, 201, 60); stroke(1, 151, 253, 30); strokeWeight(8); float n = node.mass() * 4; float w = 0.25; float q = random(-w, w); beginShape(); // Top of the drop curveVertex(node.position().x() + q, node.position().y() - n * (2.5 + q)); curveVertex(node.position().x() + q, node.position().y() - n * (2.5 + q)); // Right-hand side curveVertex(node.position().x() + n + q, node.position().y() + q); // Bottom curveVertex(node.position().x() + q, node.position().y() + n + q); // Left-hand side curveVertex(node.position().x() - n + q, node.position().y() + q); // Back to the top to finish curveVertex(node.position().x() + q, node.position().y() - n * (2.5 + q)); curveVertex(node.position().x() + q, node.position().y() - n * (2.5 + q)); endShape(); noStroke(); fill(179, 222, 253, 80); ellipse(node.position().x() - (n / 2), node.position().y() - (n / 2), n / 1.5, n / 1.5); } } void setOnLeaf(boolean onLeaf, Leaf myLeaf) { if (this.onLeaf == onLeaf) return; this.onLeaf = onLeaf; this.myLeaf = myLeaf; if (onLeaf) { yy = node.position().y() + 1; } } /*void splatter() { System.out.println("SPLATTER"); float nDrops = node.mass() / 0.6; for (int i = 0; i < nDrops; i++) { droplets.add(new Droplet(node.position().x(), node.position().y(), 0.6, random(-2, 2), random(3, 1))); node.kill(); // Mark this drop for removal } }*/ }