From 12199e65b102503c42087428fc91fd2f375bfa00 Mon Sep 17 00:00:00 2001 From: arastogi1997 Date: Sun, 23 Jul 2017 21:06:32 +0530 Subject: [PATCH 1/3] Fixes Issue #83 : variable naming in Collision Equal Mass --- .../CollisionsEqualMass/Mover.pde | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/chp05_physicslibraries/CollisionsEqualMass/Mover.pde b/chp05_physicslibraries/CollisionsEqualMass/Mover.pde index 04d8807d..5161ca71 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,29 +56,29 @@ 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! + // Yes, make new veposities! 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 + // Difference of veposities so that we think of one object as stationary PVector u = PVector.sub(vel,other.vel); // Separate out components -- one in direction of normal PVector un = componentVector(u,n); // Other component u.sub(un); - // These are the new velocities plus the velocity of the object we consider as stastionary + // These are the new veposities plus the veposity of the object we consider as stastionary vel = PVector.add(u,other.vel); other.vel = PVector.add(un,other.vel); } @@ -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 From b9b1068dd4e29da1d0c4968f1630f07cfe876b16 Mon Sep 17 00:00:00 2001 From: arastogi1997 Date: Sun, 23 Jul 2017 21:45:13 +0530 Subject: [PATCH 2/3] changed comments back to original, fixing issue #83 --- chp05_physicslibraries/CollisionsEqualMass/Mover.pde | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chp05_physicslibraries/CollisionsEqualMass/Mover.pde b/chp05_physicslibraries/CollisionsEqualMass/Mover.pde index 5161ca71..8168ebc3 100644 --- a/chp05_physicslibraries/CollisionsEqualMass/Mover.pde +++ b/chp05_physicslibraries/CollisionsEqualMass/Mover.pde @@ -65,20 +65,20 @@ class Mover { float sumR = r + other.r; // Are they colliding? if (!colliding && d < sumR) { - // Yes, make new veposities! + // Yes, make new velocities! colliding = true; // Direction of one object another PVector n = PVector.sub(other.pos,pos); n.normalize(); - // Difference of veposities so that we think of one object as stationary + // Difference of velocities so that we think of one object as stationary PVector u = PVector.sub(vel,other.vel); // Separate out components -- one in direction of normal PVector un = componentVector(u,n); // Other component u.sub(un); - // These are the new veposities plus the veposity of the object we consider as stastionary + // These are the new velocities plus the velocity of the object we consider as stastionary vel = PVector.add(u,other.vel); other.vel = PVector.add(un,other.vel); } From 115b2ac76657464a3207807df3ad0b38cfff6cc3 Mon Sep 17 00:00:00 2001 From: arastogi1997 Date: Sun, 23 Jul 2017 22:02:53 +0530 Subject: [PATCH 3/3] Changed origination of particles to mouse co-ords, fixing issue#24 --- .../NOC_4_03_ParticleSystemClass.pde | 9 ++++++--- .../NOC_4_03_ParticleSystemClass/Particle.pde | 4 +--- .../NOC_4_03_ParticleSystemClass/ParticleSystem.pde | 10 +++------- 3 files changed, 10 insertions(+), 13 deletions(-) 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