public class Body{ Vector3D location; Vector3D velocity; Vector3D acceleration; float mass; float density; color bodyColor; boolean dead = false; int type; Body(Vector3D _location, float _mass, float _density, color _color, int _type){ location = _location.copy(); mass = _mass; density = _density; bodyColor = _color; velocity = new Vector3D(0,0); location = _location.copy(); acceleration = new Vector3D(0,0); type = _type; } void attract(Vector3D _attraction, float _mass){ Vector3D distance = Vector3D.sub(_attraction, location); Vector3D gravity = distance.copy(); gravity.normalize(); gravity.div(sq(distance.magnitude())); gravity.mult(_mass); acceleration = Vector3D.add(acceleration, gravity); //gas pressure is dependent on temperature and concentration... //but lets see how it works with just some wacky cumulative distance Vector3D pressure = distance.copy(); pressure.normalize(); float temperature = 40; //distance.magnitude(); pressure.mult(-temperature); pressure.div(sq(distance.magnitude())*distance.magnitude()); acceleration = Vector3D.add(acceleration, pressure); } void initializeVelocity(Vector3D _attraction, float _mass){ Vector3D distance = Vector3D.sub(_attraction, location); float theta = atan2(distance.x, distance.y); theta += PI/2; float velocitymagnitude = _mass * 0.1 /sqrt(distance.magnitude()); velocity.setX(velocitymagnitude * sin(theta)); velocity.setY(velocitymagnitude * cos(theta)); // println(velocity.magnitude()); if (random(1) < 0.5){ velocity.mult(-1); } } void changeVelocity(float _increment){ print(velocity.magnitude() + "\t"); Vector3D increment = velocity.copy(); increment.normalize(); increment.mult(_increment/3); velocity.add(increment); println(velocity.magnitude()); } void update(){ velocity.add(acceleration); location.add(velocity); acceleration.mult(0); } void display(){ strokeWeight(1); stroke(bodyColor); fill(bodyColor); ellipse(location.x, location.y, max(1,sqrt(mass)/density), max(1,sqrt(mass)/density)); } Vector3D getLocation(){ return location.copy(); } float getRadius(){ return sqrt(mass)/(2*density); } void setDead(boolean _dead){ dead = _dead; } boolean checkDeath(){ return dead; } } //XXXXXXX public class Button{ String message; int xPos; int yPos; int buttonWidth; int buttonHeight; int yOffset; PFont font; Button(int _x, int _y, int _width, int _height, String _string, int _offset){ font = loadFont("AmericanTypewriter-48.vlw"); message = _string; xPos = _x; yPos = _y; buttonWidth = _width; buttonHeight = _height; yOffset = _offset; } void display() { stroke(15, 6, 0, 250); strokeWeight(4); fill(252, 252, 249, 127); rect(xPos, yPos, buttonWidth, buttonHeight); textFont(font, 16); fill(15, 6, 0); textAlign(CENTER); text(message, xPos + buttonWidth/2, yPos + yOffset); } boolean inButton(int _x, int _y){ if (_x > xPos && _x < xPos + buttonWidth && _y > yPos && _y < yPos + buttonHeight){ return true; } else{ return false; } } void selectButton(){ stroke(15, 6, 0, 250); strokeWeight(4); fill(60, 51, 45); rect(xPos - 2, yPos - 2, buttonWidth + 4, buttonHeight + 4); textFont(font, 18); fill(252, 252, 249); textAlign(CENTER); text(message, xPos + buttonWidth/2, yPos + yOffset); } }