// cell class // adapted from shiffman's Thing code import noc.*; class Cells { Vector3D loc; Vector3D vel; Vector3D acc; float mass; float max_vel; float bounce = 1.0f; // How "elastic" is the object boolean sc; Cells(Vector3D a, Vector3D v, Vector3D l, float m_) { acc = a.copy(); vel = v.copy(); loc = l.copy(); mass = m_; max_vel = 20.0f; sc = false; } Vector3D getLoc() { return loc; } Vector3D getVel() { return vel; } float getMass() { return mass; } void add_force(Vector3D force) { force.div(mass); acc.add(force); if (showVectors) { drawVector(force,loc,1000); } } // Main method to operate object void go() { update(); borders(); if (sc == true && sick == true){ renderSick(); } else render(); } // Method to update location void update() { vel.add(acc); vel.limit(max_vel); loc.add(vel); acc.setXYZ(0.0f,0.0f, 0.0f); } void borders() { if ((loc.y > height + 50) || (loc.y < -50)) { vel.y *= -1; } if ((loc.x < -50) || (loc.x > width +50)) { vel.x *= -1; } } // Method to display void renderSick() { ellipseMode(CENTER); stroke(50, 50, 50); fill(250,240,240); ellipse(loc.x,loc.y,mass*3,mass*2); fill(210, 200, 200); ellipse(loc.x,loc.y-2,mass*2, mass*0.8); if (showVectors) { drawVector(vel,loc,20); drawVector(acc,loc,10000); } } // Method to display void render() { ellipseMode(CENTER); stroke(250, 250, 250); fill(200,20,30); ellipse(loc.x,loc.y,mass*3,mass*2); fill(150, 15, 10); ellipse(loc.x,loc.y-2,mass*2, mass*0.5); if (showVectors) { drawVector(vel,loc,20); drawVector(acc,loc,10000); } } }