Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisppaul committed May 22, 2020
1 parent f15d20b commit ece74fb
Show file tree
Hide file tree
Showing 199 changed files with 843 additions and 562 deletions.
4 changes: 2 additions & 2 deletions 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
2 changes: 1 addition & 1 deletion dist/config.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ IO_EXAMPLE_PATHS=( examples )
PROJECT_PACKAGE=teilchen
SKETCH_IMPORTS=( teilchen.behavior.* teilchen.constraint.* teilchen.cubicle.* teilchen.force.* teilchen.integration.* teilchen.util.* )
BASE_COLOR=23
ADDITIONAL_LIBS=( )
ADDITIONAL_LIBS=( )
2 changes: 2 additions & 0 deletions dist/copy_readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ LIB_NAME=$1
ROOT=$(pwd)

SRC=$ROOT/../README.md
SRC_LICENSE=$ROOT/../LICENSE
DST=$ROOT/../processing-library/$LIB_NAME

cp "$SRC" "$DST"
cp "$SRC_LICENSE" "$DST"
Binary file modified lib/teilchen.jar
Binary file not shown.
159 changes: 159 additions & 0 deletions processing-library/teilchen/LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions processing-library/teilchen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- *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).

## anatomy of a physic-based particle system

### particles
Expand All @@ -28,3 +30,4 @@ constraints act on particle positions outside of a physical simulation. constrai
### integrators

integrators are used to integrate acceleration and velocity to calculate the new position. the most well-known is the *euler* integrator, but there are also optimized versions like *runge-kutta* or *midpoint* or even slightly different concepts like *verlet*.

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 create and use attractors.
*/
Physics mPhysics;
Attractor mAttractor;
void settings() {
Expand All @@ -31,19 +34,12 @@ void setup() {
Particle myParticle = mPhysics.makeParticle();
myParticle.position().set(random(width), random(height));
}
mPhysics.particles().get(0).fixed(true);
/* create an attractor */
mAttractor = new Attractor();
mAttractor.radius(100);
mAttractor.strength(150);
mPhysics.add(mAttractor);
}
void mousePressed() {
/* flip the direction of the attractors strength. */
float myInvertedStrength = -1 * mAttractor.strength();
/* a negative strength turns the attractor into a repulsor */
mAttractor.strength(myInvertedStrength);
}
void draw() {
/* set attractor to mouse position */
mAttractor.position().set(mouseX, mouseY);
Expand All @@ -69,3 +65,9 @@ void draw() {
ellipse(mAttractor.position().x, mAttractor.position().y,
mAttractor.radius(), mAttractor.radius());
}
void mousePressed() {
/* flip the direction of the attractors strength. */
float myInvertedStrength = -1 * mAttractor.strength();
/* a negative strength turns the attractor into a repulsor */
mAttractor.strength(myInvertedStrength);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ void setup() {
/* physics */
mPhysics = new Physics();
Teleporter mTeleporter = new Teleporter();
mTeleporter.min().set(0, 0, height / -2);
mTeleporter.max().set(width, height, height / 2);
mTeleporter.min().set(0, 0, height / -2.0f);
mTeleporter.max().set(width, height, height / 2.0f);
mPhysics.add(mTeleporter);
ViscousDrag myViscousDrag = new ViscousDrag();
mPhysics.add(myViscousDrag);
Expand Down Expand Up @@ -59,15 +59,15 @@ class SwarmEntity extends BehaviorParticle {
SwarmEntity() {
maximumInnerForce(random(100.0f, 1000.0f));
radius(10f);
separation = new Separation<>();
separation = new Separation();
separation.proximity(20);
separation.weight(50.0f);
behaviors().add(separation);
alignment = new Alignment<>();
alignment = new Alignment();
alignment.proximity(30);
alignment.weight(30.0f);
behaviors().add(alignment);
cohesion = new Cohesion<>();
cohesion = new Cohesion();
cohesion.proximity(100);
cohesion.weight(5.0f);
behaviors().add(cohesion);
Expand All @@ -88,7 +88,7 @@ class SwarmEntity extends BehaviorParticle {
translate(position().x, position().y, position().z);
pushMatrix();
PMatrix3D p = new PMatrix3D();
Util.pointAt(p, position(), new PVector(0, 1, 0), PVector.add(position(), velocity()));
teilchen.util.Util.pointAt(p, position(), new PVector(0, 1, 0), PVector.add(position(), velocity()));
applyMatrix(p);
noStroke();
fill(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,33 @@ void setup() {
frameRate(60);
smooth();
mPhysics = new Physics();
mPhysics.constrain_iterations_per_steps = 1;
/* add gravity for extra fun */
mPhysics.add(new Gravity());
/* we chose verlet integration as it integrates much more nicely with sticks ( and constraints in general ) */
Verlet myVerlet = new Verlet();
myVerlet.damping(0.99f);
mPhysics.setIntegratorRef(myVerlet);
Gravity mGravity = new Gravity(0,100,0);
mPhysics.add(mGravity);
/* setup sticks to form mParticle whip */
mParticles = new Particle[16];
float mSegmentLength = 20.0f;
float mSegmentLength = 10.0f;
/* create sticks */
ArrayList<Stick> mSticks = new ArrayList();
final ArrayList<Stick> mSticks = new ArrayList();
for (int i = 0; i < mParticles.length; i++) {
mParticles[i] = mPhysics.makeParticle(i * mSegmentLength, 0, 0, 0.1f);
if (i > 0) {
Stick myStick = new Stick(mParticles[i - 1], mParticles[i], mSegmentLength);
mSticks.add(myStick);
/* damp stick to release tensions from system */
myStick.damping(0.99f);
mPhysics.add(myStick);
if (i == 1) {
/* make head stick shorter */
myStick.restlength(10);
}
final Stick mConnection = new Stick(mParticles[i - 1], mParticles[i], mSegmentLength);
// mConnection.strength(3);
// mConnection.damping(0.99f);
mSticks.add(mConnection);
mPhysics.add(mConnection);
}
}
/* create line intersection mechanism */
for (Particle mParticle : mParticles) {
LineIntersectionConstraint mLineIntersections = new LineIntersectionConstraint(mParticle);
mLineIntersections.intersecting_lines().addAll(mSticks);
mLineIntersections.intersection_padding(1);
mLineIntersections.DEBUG_VIEW = g;
mPhysics.add(mLineIntersections);
mLineIntersections.DEBUG_VIEW = g;
}
/* fix root particle so it can stick to the mouse later */
mParticles[0].fixed(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import teilchen.*;
import teilchen.behavior.*;
import teilchen.constraint.*;
import teilchen.cubicle.*;
import teilchen.force.*;
import teilchen.integration.*;
import teilchen.util.*;


Physics mPhysics;
Particle mPendulumRoot;
Particle mPendulumTip;
Pulse mPulse;
void settings() {
size(640, 480);
}
void setup() {
mPhysics = new Physics();
Gravity mGravity = new Gravity();
mPhysics.add(mGravity);
mPendulumRoot = mPhysics.makeParticle(0, 0, 0, 0.05f);
mPendulumRoot.position().set(width / 2, 100);
mPendulumRoot.fixed(true);
mPendulumTip = mPhysics.makeParticle(0, 0, 0, 0.05f);
float mSegmentLength = height / 2;
Spring mConnection = new Spring(mPendulumRoot, mPendulumTip, mSegmentLength);
mConnection.damping(0.0f);
mConnection.strength(10);
mPhysics.add(mConnection);
mPulse = new Pulse(mPendulumTip);
mPulse.damping(0.99f);
mPhysics.add(mPulse);
}
void draw() {
final int NUM_ITERATIONS = 5;
for (int i = 0; i < NUM_ITERATIONS; i++) {
mPhysics.step(1.0f / (frameRate * NUM_ITERATIONS));
}
background(255);
Particle p1 = mPendulumRoot;
Particle p2 = mPendulumTip;
stroke(0, 192);
noFill();
line(p1.position().x, p1.position().y, p2.position().x, p2.position().y);
stroke(255, 0, 0);
fill(255);
ellipse(p1.position().x, p1.position().y, 10, 10);
ellipse(p2.position().x, p2.position().y, 20, 20);
}
void mousePressed() {
mPulse.force().set(mPendulumTip.velocity().normalize().mult(100));
}
Binary file modified processing-library/teilchen/library/teilchen.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion processing-library/teilchen/src/teilchen/IConnection.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion processing-library/teilchen/src/teilchen/Particle.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
30 changes: 15 additions & 15 deletions processing-library/teilchen/src/teilchen/Physics.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -40,16 +40,14 @@ public class Physics {

public static final float EPSILON = 0.001f;
public static boolean HINT_UPDATE_OLD_POSITION = true;
private final ArrayList<Particle> mParticles;
private final ArrayList<IForce> mForces;
private final ArrayList<IConstraint> mConstraints;
public boolean HINT_OPTIMIZE_STILL = true;

public boolean HINT_REMOVE_DEAD = true;

public boolean HINT_RECOVER_NAN = true;

public boolean HINT_REMOVE_DEAD = true;
public int constrain_iterations_per_steps = 1;
public int integrations_per_steps = 1;
private final ArrayList<Particle> mParticles;
private final ArrayList<IForce> mForces;
private final ArrayList<IConstraint> mConstraints;
private IIntegrator mIntegrator;

public Physics() {
Expand Down Expand Up @@ -85,19 +83,19 @@ public Particle particles(final int theIndex) {
return mParticles.get(theIndex);
}

public BasicParticle makeParticle() {
BasicParticle myParticle = new BasicParticle();
mParticles.add(myParticle);
return myParticle;
}

public BasicParticle makeParticle(final PVector thePosition) {
BasicParticle myParticle = makeParticle();
myParticle.setPositionRef(thePosition);
myParticle.old_position().set(myParticle.position());
return myParticle;
}

public BasicParticle makeParticle() {
BasicParticle myParticle = new BasicParticle();
mParticles.add(myParticle);
return myParticle;
}

public BasicParticle makeParticle(final float x, final float y) {
BasicParticle myParticle = makeParticle();
myParticle.position().set(x, y);
Expand Down Expand Up @@ -277,7 +275,9 @@ public void step(final float theDeltaTime) {
}

protected synchronized void integrate(float theDeltaTime) {
mIntegrator.step(theDeltaTime, this);
for (int j = 0; j < integrations_per_steps; j++) {
mIntegrator.step(theDeltaTime / integrations_per_steps, this);
}
}

protected synchronized void handleForces() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Teilchen
*
* Copyright (C) 2015
* Copyright (C) 2020
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Loading

0 comments on commit ece74fb

Please sign in to comment.