Skip to content

Commit

Permalink
cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisppaul committed May 22, 2020
1 parent ece74fb commit e17849b
Show file tree
Hide file tree
Showing 50 changed files with 133 additions and 182 deletions.
4 changes: 2 additions & 2 deletions processing-library/teilchen/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# teilchen

![LessonX04_StickMan](https://raw.githubusercontent.com/d3p/teilchen/master/img/LessonX04_StickMan.png)
![LessonX04_StickMan](https://raw.githubusercontent.com/dennisppaul/teilchen/master/img/LessonX04_StickMan.png)

- *teilchen* is a simple physics library based on particles, forces, constraints and behaviors.
- *teilchen* is also a collection of a variety of concepts useful for modeling with virtual physics and behaviors. nothing new nothing fancy, except maybe for the combination of forces ( *external forces* ) and behavior ( *internal forces* ).
- *teilchen* is also a [processing.org](http://processing.org "Processing.org")-style library.
- *teilchen* is a german word and a synonym for *Partikel* which translates to the english *particle*.

the library is hosted on github [teilchen](https://github.com/d3p/teilchen).
the library is hosted on github [teilchen](https://github.com/dennisppaul/teilchen).

## anatomy of a physic-based particle system

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch show how to create a particle system with a single particle in it.
*/
Physics mPhysics;
Particle mParticle;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
/* create a particle system. */
mPhysics = new Physics();
/* create a particle. note that the particle is automatically added to particle system */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch show how to create a particle system with a single particle in it.
*/
Physics mPhysics;
Particle mParticle;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
/* create a particle system */
mPhysics = new Physics();
/* create a gravitational force */
Gravity mGravity = new Gravity();
/* the direction of the gravity is defined by the 'force' vector */
mGravity.force().set(0, 30, 0);
/* forces, like gravity or any other force, can be added to the system. they will be automatically applied to all particles */
/* forces, like gravity or any other force, can be added to the system. they will be automatically applied to
all particles */
mPhysics.add(mGravity);
/* create a particle and add it to the system */
mParticle = mPhysics.makeParticle();
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 shows how to create and handle multiple particles and remove
* individual particles.
*/
Physics mPhysics;
void settings() {
size(640, 480, P3D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
/* create a particle system */
mPhysics = new Physics();
/* create a viscous force that slows down all motion */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch shows 1 how to create and use line deflectors 2 how to use 'ShortLivedParticle'
*/
Physics mPhysics;
LineDeflector2D mDeflector;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
/* create a particle system */
mPhysics = new Physics();
mDeflector = new LineDeflector2D();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch shows 1 how to create and use plane deflectors 2 how to use
* 'ShortLivedParticle'
*/
Physics mPhysics;
PlaneDeflector mDeflector;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
/* create a particle system */
mPhysics = new Physics();
/* create a deflector and add it to the particle system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import teilchen.integration.*;
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.
*/
Physics mPhysics;
Spring mSpring;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
/* create a particle system */
mPhysics = new Physics();
/* create a viscous force that slows down all motion; 0 means no slowing down. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import teilchen.integration.*;
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.
*/
Physics mPhysics;
Particle mRoot;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
/* create a particle system */
mPhysics = new Physics();
/* create a particle to which we will connect springs */
Expand All @@ -27,7 +29,8 @@ void draw() {
if (mousePressed) {
Particle mParticle = mPhysics.makeParticle(mouseX, mouseY, 0);
Spring mSpring = mPhysics.makeSpring(mRoot, mParticle);
/* restlength defines the desired length of the spring. in this case it is the distance between the two particles. */
/* restlength defines the desired length of the spring. in this case it is the distance between the two
particles. */
float mRestlength = mSpring.restlength();
/* we modify the restlength to add a bit of energy into the system */
mSpring.restlength(mRestlength * 1.5f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(60);
mPhysics = new Physics();
/* we use 'runge kutta' as it is more stable for this application */
Expand All @@ -35,7 +34,7 @@ void setup() {
Particle d = mPhysics.makeParticle(0, 100);
new StableSpringQuad(mPhysics, d, c, mPhysics.makeParticle(100, 200), mPhysics.makeParticle(0, 200));
/* create stable quad from springs */
/* first the edge-springs ... */
/* first the edge-springs ... */
final float mySpringConstant = 100;
final float mySpringDamping = 5;
mPhysics.makeSpring(a, b, mySpringConstant, mySpringDamping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ void settings() {
}
void setup() {
frameRate(60);
smooth();
mPhysics = new Physics();
/* increase the number of iterations for contraints in each step. this can greatly relaxes tensions in the system. */
/* increase the number of iterations for contraints in each step. this can greatly relaxes tensions in the
system. */
mPhysics.constrain_iterations_per_steps = 5;
/* add gravity for extra fun */
mPhysics.add(new Gravity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import teilchen.integration.*;
import teilchen.util.*;


static final int GRID_WIDTH = 32;
static final int GRID_HEIGHT = 16;
Physics mPhysics;
Particle[][] mParticles;
final int GRID_WIDTH = 32;
final int GRID_HEIGHT = 16;
Attractor mAttractor;
void settings() {
size(640, 480, P3D);
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 shows how to assign an 'wander' behavior to a particle.
*/
Physics mPhysics;
BehaviorParticle mParticle;
Wander mWander;
Expand All @@ -15,7 +18,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(120);
/* physics */
mPhysics = new Physics();
Expand All @@ -28,7 +30,8 @@ void setup() {
/* create behavior */
mWander = new Wander();
mParticle.behaviors().add(mWander);
/* a motor is required to push the particle forward - wander manipulates the direction the particle is pushed in */
/* a motor is required to push the particle forward - wander manipulates the direction the particle is pushed
in */
mMotor = new Motor();
mMotor.auto_update_direction(true);
/* the direction the motor pushes into is each step automatically set to the velocity */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch shows how to assign an 'arrival' behavior to a particle.
*/
Physics mPhysics;
BehaviorParticle mParticle;
Arrival mArrival;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(120);
colorMode(RGB, 1.0f);
noFill();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import teilchen.integration.*;
import teilchen.util.*;


/*
* this sketch is exactly like Lesson06_Springs, except that it also shows how
* to resolveOverlap overlaps.
*/
static final float PARTICLE_RADIUS = 13;
Physics mPhysics;
Particle mRoot;
void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
mPhysics = new Physics();
/* create drag */
mPhysics.add(new ViscousDrag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(30);
noFill();
ellipseMode(CENTER);
mCollision = new CollisionManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(60);
/* create a particle system */
mPhysics = new Physics();
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 demo shows some advanced use of particles, springs and attractors to
* create stickmen.
*/
Physics mPhysics;
Attractor mAttractor;
Gravity mGravity;
Expand All @@ -16,7 +20,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
smooth();
frameRate(60);
noFill();
mPhysics = new Physics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
frameRate(30);
smooth();
mPhysics = new Physics();
mPhysics.setIntegratorRef(new RungeKutta());
ViscousDrag myViscousDrag = new ViscousDrag();
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 demo shows how to add behaviors to particles. in this example the
* arrival behavior.
*/
Physics mPhysics;
ArrayList<Duckling> mDucklings;
CollisionManager mCollision;
Expand All @@ -15,7 +19,6 @@ void settings() {
}
void setup() {
frameRate(60);
smooth();
colorMode(RGB, 1.0f);
/* physics */
mPhysics = new Physics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
frameRate(60);
smooth();
rectMode(CENTER);
hint(DISABLE_DEPTH_TEST);
/* physics */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
frameRate(60);
smooth();
rectMode(CENTER);
hint(DISABLE_DEPTH_TEST);
/* physics */
mPhysics = new Physics();
Gravity myGravity = new Gravity(0, 0, -30);
mPhysics.add(myGravity);
/* triangle deflectors */
/* triangle deflectors */
final PVector[] mVertices = new PVector[]{new PVector(0, 0, 0),
new PVector(width, height, 0),
new PVector(0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void settings() {
size(640, 480, P3D);
}
void setup() {
frameRate(60);
/* physics */
mPhysics = new Physics();
Gravity myGravity = new Gravity(0, 20, 0);
Expand All @@ -34,7 +33,7 @@ void draw() {
for (int i = 0; i < mPhysics.particles().size(); i++) {
Particle mParticle = mPhysics.particles(i);
if (mParticle.position().y > height || mParticle.still()) {
mPhysics.particles().remove(i);
mPhysics.particles().remove(i); //@TODO(this might cause an exception. should be replaced by iterator)
}
}
/* draw particles */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import teilchen.integration.*;
import teilchen.util.*;


// @TODO(not fully functional yet)
Physics mPhysics;
Particle[] mParticles;
void settings() {
Expand All @@ -20,7 +21,7 @@ void setup() {
Verlet myVerlet = new Verlet();
myVerlet.damping(0.99f);
mPhysics.setIntegratorRef(myVerlet);
Gravity mGravity = new Gravity(0,100,0);
Gravity mGravity = new Gravity(0, 100, 0);
mPhysics.add(mGravity);
/* setup sticks to form mParticle whip */
mParticles = new Particle[16];
Expand Down
Binary file modified processing-library/teilchen/library/teilchen.jar
Binary file not shown.
Loading

0 comments on commit e17849b

Please sign in to comment.