diff --git a/chp04_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde b/chp04_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde index 935a214d..f9803d76 100644 --- a/chp04_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde +++ b/chp04_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde @@ -3,14 +3,17 @@ // http://natureofcode.com ParticleSystem ps; +PVector current; void setup() { size(640,360); - ps = new ParticleSystem(new PVector(width/2,50)); + PVector origin= new PVector(width/2,50); + ps = new ParticleSystem(origin); } void draw() { background(255); - ps.addParticle(); + current = new PVector(mouseX,mouseY); + ps.addParticle(current); ps.run(); -} +} \ No newline at end of file diff --git a/chp04_systems/NOC_4_03_ParticleSystemClass/Particle.pde b/chp04_systems/NOC_4_03_ParticleSystemClass/Particle.pde index 6bf46b10..b5816173 100644 --- a/chp04_systems/NOC_4_03_ParticleSystemClass/Particle.pde +++ b/chp04_systems/NOC_4_03_ParticleSystemClass/Particle.pde @@ -45,6 +45,4 @@ class Particle { return false; } } -} - - +} \ No newline at end of file diff --git a/chp04_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde b/chp04_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde index 9f2c4b83..20c11377 100644 --- a/chp04_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde +++ b/chp04_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde @@ -13,8 +13,8 @@ class ParticleSystem { particles = new ArrayList(); } - void addParticle() { - particles.add(new Particle(origin)); + void addParticle(PVector position) { + particles.add(new Particle(position.get())); } void run() { @@ -26,8 +26,4 @@ class ParticleSystem { } } } -} - - - - +} \ No newline at end of file diff --git a/chp05_physicslibraries/CollisionsEqualMass/Mover.pde b/chp05_physicslibraries/CollisionsEqualMass/Mover.pde index 04d8807d..8168ebc3 100644 --- a/chp05_physicslibraries/CollisionsEqualMass/Mover.pde +++ b/chp05_physicslibraries/CollisionsEqualMass/Mover.pde @@ -14,7 +14,7 @@ class Mover { Mover(PVector v, PVector l) { vel = v.get(); - loc = l.get(); + pos = l.get(); } // Main method to operate object @@ -56,19 +56,19 @@ class Mover { fill(175,200); ellipse(pos.x,pos.y,r*2,r*2); if (showVectors) { - drawVector(vel,loc,10); + drawVector(vel,pos,10); } } void collideEqualMass(Mover other) { - float d = PVector.dist(loc,other.loc); + float d = PVector.dist(pos,other.pos); float sumR = r + other.r; // Are they colliding? if (!colliding && d < sumR) { // Yes, make new velocities! colliding = true; // Direction of one object another - PVector n = PVector.sub(other.loc,loc); + PVector n = PVector.sub(other.pos,pos); n.normalize(); // Difference of velocities so that we think of one object as stationary @@ -95,6 +95,4 @@ PVector componentVector (PVector vector, PVector directionVector) { directionVector.normalize(); directionVector.mult(vector.dot(directionVector)); return directionVector; -} - - +} \ No newline at end of file