Skip to content

Commit

Permalink
cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisppaul committed May 28, 2020
1 parent 015f1b6 commit edeee85
Show file tree
Hide file tree
Showing 397 changed files with 8,386 additions and 1,973 deletions.
Binary file modified lib/teilchen.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import teilchen.util.*;


/*
* this sketch show how to create a particle system with a single particle in it.
* this sketch demonstrates how to create a particle system with a single particle in it.
*/
Physics mPhysics;
Particle mParticle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import teilchen.util.*;


/*
* this sketch show how to create a particle system with a single particle in it.
* this sketch demonstrates how to create a particle system with a single particle in it and a
* gravity force pulling it downward.
*/
Physics mPhysics;
Particle mParticle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import teilchen.util.*;


/*
* this sketch shows how to create and handle multiple particles and remove
* individual particles.
* this sketch demonstrates how to create and handle multiple particles and remove individual
* particles.
*/
Physics mPhysics;
void settings() {
Expand Down Expand Up @@ -39,7 +39,7 @@ void draw() {
for (int i = 0; i < mPhysics.particles().size(); i++) {
Particle mParticle = mPhysics.particles(i);
if (mParticle.position().y > height * 0.9f) {
mPhysics.particles().remove(i);
mPhysics.particles().remove(i); // @TODO(check if this potentially creates an exception)
}
}
/* draw all the particles in the system */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import teilchen.util.*;


/*
* this sketch shows how to create and use attractors.
* this sketch demonstrates how to create and use an `Attractor` and how to teleport particles.
*/
Physics mPhysics;
Attractor mAttractor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import teilchen.util.*;


/*
* this sketch shows 1 how to create a viscous drag to slow motion eventually
* down. 2 how to create a spring that connects two particles.
* this sketch demonstrates how to create a `Spring` that connects two particles. it also
* demonstrates how to create a `ViscousDrag` to slow down particle motion over time.
*/
Physics mPhysics;
Spring mSpring;
Expand All @@ -24,9 +24,9 @@ void setup() {
mPhysics.add(myDrag);
/* create two particles that we can connect with a spring */
Particle myA = mPhysics.makeParticle();
myA.position().set(width / 2 - 50, height / 2);
myA.position().set(width / 2 - 50, height / 2.0f);
Particle myB = mPhysics.makeParticle();
myB.position().set(width / 2 + 50, height / 2);
myB.position().set(width / 2 + 50, height / 2.0f);
/* create a spring force that connects two particles.
* note that there is more than one way to create a spring.
* in our case the restlength of the spring is defined by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import teilchen.util.*;


/*
* this sketch shows 1 how to create a viscous drag to slow motion eventually
* down. 2 how to create a spring that connects two particles.
* this sketch demonstrates how to connect multiple particles with springs.
*/
Physics mPhysics;
Particle mRoot;
Expand All @@ -20,7 +19,7 @@ void setup() {
/* create a particle system */
mPhysics = new Physics();
/* create a particle to which we will connect springs */
mRoot = mPhysics.makeParticle(width / 2, height / 2, 0.0f);
mRoot = mPhysics.makeParticle(width / 2.0f, height / 2.0f, 0.0f);
/* we give the root particle a higher mass so it doesn t move as easily */
mRoot.mass(30);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch demonstrates how to connect four particles and six springs to form a
* `StableSpringQuad` a construct that allows to emulate something similar to a *body*.
*/
Physics mPhysics;
Particle mRoot;
void settings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch demonstrates how to use a stick to connect two particles. `Stick` is similar to
* `Spring` except that it does not use forces to move particles which results in a more
* *stiff* behavior.
*/
Physics mPhysics;
Particle[] mParticles;
void settings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch demonstrate how to use particles and springs to emulate a piece of cloth.
*/
static final int GRID_WIDTH = 32;
static final int GRID_HEIGHT = 16;
Physics mPhysics;
Particle[][] mParticles;
Attractor mAttractor;
void settings() {
size(640, 480, P3D);
Expand All @@ -27,7 +29,7 @@ void setup() {
mAttractor.strength(-15000);
mAttractor.radius(300);
mPhysics.add(mAttractor);
mParticles = new Particle[GRID_WIDTH][GRID_HEIGHT];
Particle[][] mParticles = new Particle[GRID_WIDTH][GRID_HEIGHT];
/* setup cloth */
float mGridStepX = ((float) width / GRID_WIDTH);
float mGridStepY = (((float) height * 0.5f) / GRID_HEIGHT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import teilchen.util.*;


/*
* this sketch shows 1 how to create and use line deflectors 2 how to use 'ShortLivedParticle'
* this sketch demonstrates how to create and use `LineDeflector2D` and how to use
* `ShortLivedParticle` a particle that only exists for a defined period of time.
*/
Physics mPhysics;
LineDeflector2D mDeflector;
Expand All @@ -19,8 +20,8 @@ void setup() {
/* create a particle system */
mPhysics = new Physics();
mDeflector = new LineDeflector2D();
mDeflector.a().set(50, height / 2);
mDeflector.b().set(width - 50, height / 2 - 100);
mDeflector.a().set(50, height / 2.0f);
mDeflector.b().set(width - 50, height / 2.0f - 100);
mPhysics.add(mDeflector);
/* create gravity */
Gravity myGravity = new Gravity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import teilchen.util.*;


/*
* this sketch shows 1 how to create and use plane deflectors 2 how to use
* 'ShortLivedParticle'
* this sketch demonstrates how to create and use ``PlaneDeflector` and how to use
* `ShortLivedParticle` a particle that only exists for a defined period of time.
*/
Physics mPhysics;
PlaneDeflector mDeflector;
Expand All @@ -28,7 +28,7 @@ void setup() {
*/
mDeflector = new PlaneDeflector();
/* set plane origin into the center of the screen */
mDeflector.plane().origin.set(width / 2, height / 2, 0);
mDeflector.plane().origin.set(width / 2.0f, height / 2.0f, 0);
mDeflector.plane().normal.set(0, -1, 0);
/* the coefficient of restitution defines how hard particles bounce of the deflector */
mDeflector.coefficientofrestitution(0.7f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import teilchen.util.*;


/*
* this sketch shows how to assign an 'wander' behavior to a particle.
* this sketch demonstrates how to use behaviors. it combines `Wander` and `Motor` behaviors
* to turn a `BehaviorParticle` into an autonomously moving *agent*.
*/
Physics mPhysics;
BehaviorParticle mParticle;
Expand All @@ -24,7 +25,7 @@ void setup() {
mPhysics.add(new ViscousDrag());
/* create particles */
mParticle = mPhysics.makeParticle(BehaviorParticle.class);
mParticle.position().set(width / 2, height / 2);
mParticle.position().set(width / 2.0f, height / 2.0f);
mParticle.maximumInnerForce(100);
mParticle.radius(10);
/* create behavior */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import teilchen.util.*;


/*
* this sketch shows how to assign an 'arrival' behavior to a particle.
* this sketch demonstrates how to use behaviors. it appliies the `Arrival` behavior to make a
* `BehaviorParticle` arrive at a certain location.
*/
Physics mPhysics;
BehaviorParticle mParticle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import teilchen.util.*;


/*
* this sketch is exactly like Lesson06_Springs, except that it also shows how
* to resolveOverlap overlaps.
* this sketch is exactly like `Lesson06_Springs` except that it also shows how to resolve
* overlaps of particles by moving particles apart manipulating their position directly.
*/
static final float PARTICLE_RADIUS = 13;
Physics mPhysics;
Expand All @@ -22,7 +22,7 @@ void setup() {
/* create drag */
mPhysics.add(new ViscousDrag());
mPhysics.add(new Gravity(new PVector(0, 100f, 0)));
mRoot = mPhysics.makeParticle(width / 2, height / 2, 0.0f);
mRoot = mPhysics.makeParticle(width / 2.0f, height / 2.0f, 0.0f);
mRoot.mass(30);
mRoot.fixed(true);
mRoot.radius(PARTICLE_RADIUS);
Expand All @@ -39,7 +39,7 @@ void draw() {
}
/* move overlapping particles away from each other */
for (int i = 0; i < 10; i++) {
mRoot.position().set(width / 2, height / 2, 0.0f); // a bit of a 'hack'
mRoot.position().set(width / 2.0f, height / 2.0f, 0.0f); // a bit of a 'hack'
Overlap.resolveOverlap(mPhysics.particles());
}
/* update the particle system */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch demonstrates how to use `CollisionManager` to resolve particle collisions by
* applying temporary springs pushing 2 colliding particles appart.
*/
static final float PARTICLE_SIZE = 12;
CollisionManager mCollision;
Physics mPhysics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch demonstrates how to use `ParticleTrail` to make particles leave a trail.
*/
Physics mPhysics;
ArrayList<ParticleTrail> mTrails;
Attractor mAttractor;
Expand Down Expand Up @@ -44,14 +47,7 @@ void setup() {
myParticleTrail.mass(0.5f);
mTrails.add(myParticleTrail);
}
resetParticles(width / 2, height / 2);
}
void resetParticles(float x, float y) {
for (ParticleTrail myTrails : mTrails) {
myTrails.particle().position().set(x + random(-10, 10), y + random(-10, 10), 0);
myTrails.particle().velocity().set(random(-10, 10), random(-10, 10), random(-10, 10));
myTrails.fragments().clear();
}
resetParticles(width / 2.0f, height / 2.0f);
}
void draw() {
/* set attractor to mouse position */
Expand All @@ -65,6 +61,16 @@ void draw() {
drawTrail(myTrail);
}
}
void mousePressed() {
resetParticles(mouseX, mouseY);
}
void resetParticles(float x, float y) {
for (ParticleTrail myTrails : mTrails) {
myTrails.particle().position().set(x + random(-10, 10), y + random(-10, 10), 0);
myTrails.particle().velocity().set(random(-10, 10), random(-10, 10), random(-10, 10));
myTrails.fragments().clear();
}
}
void drawTrail(ParticleTrail theTrail) {
final ArrayList<Particle> mFragments = theTrail.fragments();
final Particle mParticle = theTrail.particle();
Expand Down Expand Up @@ -102,6 +108,3 @@ void drawTrail(ParticleTrail theTrail) {
mParticle.position().z);
}
}
void mousePressed() {
resetParticles(mouseX, mouseY);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import teilchen.util.*;


/*
* this demo shows some advanced use of particles, springs and attractors to
* create stickmen.
* this sketch demonstratwa some advanced use of particles, springs ( e.g `MuscleSpring` )
* and attractors to create a group of `StickMan`.
*/
Physics mPhysics;
Attractor mAttractor;
Gravity mGravity;
ViscousDrag mViscousDrag;
StickMan[] mMyStickMan;
void settings() {
size(640, 480, P3D);
Expand All @@ -27,13 +26,13 @@ void setup() {
mGravity = new Gravity();
mGravity.force().y = 20;
mPhysics.add(mGravity);
mViscousDrag = new ViscousDrag();
ViscousDrag mViscousDrag = new ViscousDrag();
mViscousDrag.coefficient = 0.85f;
mPhysics.add(mViscousDrag);
mAttractor = new Attractor();
mAttractor.radius(500);
mAttractor.strength(0);
mAttractor.position().set(width / 2, height / 2);
mAttractor.position().set(width / 2.0f, height / 2.0f);
mPhysics.add(mAttractor);
mMyStickMan = new StickMan[20];
for (int i = 0; i < mMyStickMan.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch demonstrates how to contraint the angle between two springs or two sticks.
*/
Physics mPhysics;
Particle mParticleA;
Particle mParticleB;
Expand All @@ -31,10 +34,10 @@ void setup() {
mParticleB = mPhysics.makeParticle();
mParticleC = mPhysics.makeParticle();
mParticleD = mPhysics.makeParticle();
mParticleA.position().set(width / 2 + 50, height / 3);
mParticleB.position().set(width / 2, height - height / 1.75f);
mParticleC.position().set(width / 2, height - height / 4);
mParticleD.position().set(width / 2, height - height / 8);
mParticleA.position().set(width / 2.0f + 50, height / 3.0f);
mParticleB.position().set(width / 2.0f, height - height / 1.75f);
mParticleC.position().set(width / 2.0f, height - height / 4.0f);
mParticleD.position().set(width / 2.0f, height - height / 8.0f);
mParticleA.radius(7);
mParticleB.radius(3);
mParticleC.radius(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import teilchen.util.*;


/*
* this demo shows how to add behaviors to particles. in this example the
* arrival behavior.
* this sketch demonstrates how to use `Arrival` behaviors with particles to create a group of
* ducklings.
*/
Physics mPhysics;
ArrayList<Duckling> mDucklings;
Expand All @@ -18,7 +18,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
frameRate(60);
colorMode(RGB, 1.0f);
/* physics */
mPhysics = new Physics();
Expand Down
Loading

0 comments on commit edeee85

Please sign in to comment.