Skip to content

Resolves Issue#24 (Enhancement) #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 1 addition & 3 deletions chp04_systems/NOC_4_03_ParticleSystemClass/Particle.pde
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ class Particle {
return false;
}
}
}


}
10 changes: 3 additions & 7 deletions chp04_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class ParticleSystem {
particles = new ArrayList<Particle>();
}

void addParticle() {
particles.add(new Particle(origin));
void addParticle(PVector position) {
particles.add(new Particle(position.get()));
}

void run() {
Expand All @@ -26,8 +26,4 @@ class ParticleSystem {
}
}
}
}




}
12 changes: 5 additions & 7 deletions chp05_physicslibraries/CollisionsEqualMass/Mover.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -95,6 +95,4 @@ PVector componentVector (PVector vector, PVector directionVector) {
directionVector.normalize();
directionVector.mult(vector.dot(directionVector));
return directionVector;
}


}