//sick cell //edited from shiffman's attractor import noc.*; class sickCell { float mass; // Mass, tied to size float G; // Gravitational Constant Vector3D loc; // Location Vector3D vel; Vector3D acc; float max_vel; boolean dragging = false; // Is the object being dragged? boolean rollover = false; // Is the mouse over the ellipse? Vector3D drag; // holds the offset for when object is clicked on sickCell(Vector3D l_,float m_, float g_) { loc = l_; mass = m_; G = g_; max_vel = 20.0f; acc = new Vector3D(0.0,0.0); vel = new Vector3D(random(-3,3),random(-1,1)); loc = new Vector3D(random(width),random(height)); drag = new Vector3D(0.0,0.0); } Vector3D getLoc() { return loc; } float getMass() { return mass; } void go() { update(); borders(); render(); drag(); } Vector3D calcGravForce(Cells t) { Vector3D dir = Vector3D.sub(loc,t.getLoc()); // Calculate direction of force float d = dir.magnitude(); // Distance between objects d = constrain(d,5.0f,25.0f); // Limiting the distance to eliminate "extreme" results for very close or very far objects dir.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction) float force = (G * mass * t.getMass()) / (d * d); // Calculate gravitional force magnitude dir.mult(force); // Get force vector --> magnitude * direction return dir; } // 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) || (loc.y < 0)) { vel.y *= -1; } if ((loc.x < 0) || (loc.x > width)) { vel.x *= -1; } } // Method to display void render() { ellipseMode(CENTER); stroke(50, 0, 0); if (sick == true){ if (dragging) fill (15,170,90); else if (rollover) fill(0,200,30); else fill(20,200,30); ellipse(loc.x,loc.y,mass*3,mass*2); fill(15, 150, 10); ellipse(loc.x,loc.y+3,mass*2, mass*0.8); } else if (sick == false){ if (dragging) fill (170,15,90); else if (rollover) fill(200,0,30); else fill(200,20,30); ellipse(loc.x,loc.y,mass*3,mass*2); fill(150, 15, 10); ellipse(loc.x,loc.y-3,mass*2, mass*0.8); } } // The methods below are for mouse interaction void clicked(int mx, int my) { float d = dist(mx,my,loc.x,loc.y); if (d < mass) { dragging = true; drag.x = loc.x-mx; drag.y = loc.y-my; } } void rollover(int mx, int my) { float d = dist(mx,my,loc.x,loc.y); if (d < mass) { rollover = true; } else { rollover = false; } } void stopDragging() { dragging = false; } void drag() { if (dragging) { loc.x = mouseX + drag.x; loc.y = mouseY + drag.y; } } }