public void drawOrbits(ArrayList alObjectsArchive) { // println("SIZE:" + alObjectsArchive.size()); // ArrayList alObjectsArchive = timeline.getObjectStateArchive(); ArrayList alPrevPos = new ArrayList(); ArrayList alColors = new ArrayList(); alColors.add(color(255, 0, 0)); alColors.add(color(255, 255, 0)); alColors.add(color(255, 0, 255)); // for (int i = timeline.getTimeIdx(); i >= 0 && i > (timeline.getTimeIdx() - 1 - 100); i--) for (int i = 0; i < alObjectsArchive.size(); i++) { ArrayList objects = (ArrayList) alObjectsArchive.get(i); for (int j = 0; j < objects.size(); j++) { CelestialObject obj = (CelestialObject) objects.get(j); // CelestialObject obj = (CelestialObject)objects.get(1); PVector pos = obj.getPosition(); // stroke(0, 0, 255); stroke((Integer) alColors.get(j)); if (alPrevPos.size() == objects.size()) { PVector prevPos = (PVector) alPrevPos.get(j); line(prevPos.x, prevPos.y, pos.x, pos.y); alPrevPos.set(j, pos); } else alPrevPos.add(pos); } } }
public void setup() { size(600, 400); smooth(); f = createFont("Georgia", 12, true); obstacles = new ArrayList(); boids = new ArrayList(); // A little algorithm to pick a bunch of random obstacles that don't overlap for (int i = 0; i < 100; i++) { float x = random(width); float y = random(height); float r = random(50 - i / 2, 50); boolean ok = true; for (int j = 0; j < obstacles.size(); j++) { Obstacle o = (Obstacle) obstacles.get(j); if (dist(x, y, o.loc.x, o.loc.y) < o.radius + r + 20) { ok = false; } } if (ok) obstacles.add(new Obstacle(x, y, r)); } // Starting with three boids boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.2f)); boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.1f)); boids.add(new Boid(new PVector(random(width), random(height)), 2f, 0.05f)); }
public void trace(float x, float y) { println(x); if (frameCounter > 2 && mousePressed) { coords.add(new PVector(x, y)); frameCounter = 0; if (coordCounter > 0) { PVector tempCoord = (PVector) coords.get(coordCounter - 1); line(x, y, tempCoord.x, tempCoord.y); } coordCounter++; } // println(coordCounter); for (int i = 0; i < coords.size(); i++) { PVector tempCoordnear = (PVector) coords.get(i); float coordDist = dist(x, y, tempCoordnear.x, tempCoordnear.y); if (coordDist < distance) { stroke(255, 0, 0); line(x, y, tempCoordnear.x, tempCoordnear.y); } } frameCounter++; }
// Does a deepcopy of an array list public static ArrayList cloneArrayList(ArrayList al) { ArrayList alNew = new ArrayList(al.size()); for (int i = 0; i < al.size(); i++) { alNew.add(((CelestialObject) al.get(i)).clone()); } return alNew; }
public ArrayList getPastObjectStates() { ArrayList alPast = new ArrayList(); for (int i = intTimeIdx; i > 0 && i > intTimeIdx - 100; i--) { alPast.add(this.alObjectStateArchive.get(i)); } return alPast; }
// Does a deepcopy of an array list public ArrayList cloneArrayList(ArrayList al) { ArrayList alNew = new ArrayList(al.size()); for (int i = 0; i < al.size(); i++) { PVector pv = (PVector) al.get(i); alNew.add(new PVector(pv.x, pv.y)); } return alNew; }
public void setup() { size(800, 600); smooth(); strokeWeight(1); skaters = new ArrayList(); skaters.add(new Skater()); }
public ArrayList getFutureObjectStates() { ArrayList alFutureArchive = new ArrayList(); ArrayList alFutureObjects = cloneArrayList(alStatefulObjects); for (int i = 0; i < 100; i++) { sim.calculateForces(alFutureObjects); alFutureArchive.add(cloneArrayList(alFutureObjects)); } return alFutureArchive; }
/** Add a ball to the ArrayList at current mouse position */ public void addBall() { // Store current mouse position x1 = mouseX; y1 = mouseY; // Get a random offset for the ball int xDiff = (int) random(-10, 10); int yDiff = (int) random(-10, 10); // Add the mouse's (x,y) and the random offset int x = mouseX + xDiff; int y = mouseY + yDiff; // Create new ball Ball b = new Ball(x, y, ballSize); b.STEM = stems; b.attract = kelly; balls.add(b); }
public int moveForward() { // println("forward!"); intTimeIdx++; // if the future values have already been calculated, just fetch them instead of calculating // them again if (alObjectStateArchive.size() > intTimeIdx) setCurrentState(cloneArrayList((ArrayList) alObjectStateArchive.get(intTimeIdx))); else { // println("calculating..."); sim.calculateForces(alStatefulObjects); alObjectStateArchive.add(cloneArrayList(alStatefulObjects)); } sliderTimeline.setValue(intTimeIdx); return intTimeIdx; }
public void addPoint(long handId, PVector handPoint) { ArrayList curList = getPointList(handId); curList.add(0, handPoint); if (curList.size() > _maxPoints) curList.remove(curList.size() - 1); }
public void registerStatefulObject(CelestialObject obj) { alStatefulObjects.add(obj); }
public void mousePressed() { boids.add(new Boid(new PVector(mouseX, mouseY), random(2, 5), random(0.05f, 0.2f))); }