Particles can do anything that Turtles can do. Here is what has
been added to MultiProcessing to support particle systems:
gravity(Gy);
The gravity function takes a float value indicating how strong gravity
is in the downward Y direction. Calling this function will set gravity
in the X and Z directions to zero (which is normal). It makes sense
to call gravity once in your setup function because you typically
only need to set the global gravity once (in setup(), say) unless
there is a circumstance in your program that makes gravity change.
The default gravity value is 0.03.
gravity(Gx,
Gy, Gz);
This function is just like the one above, but it lets you also specify
the gravity in the X and Z directions in case things in your world
should be falling to the side or forwards or backwards. The default
gravity values are Gx: 0.0, Gy: 0.03, Gz: 0.0.
drag(drag);
The drag function takes a float value indicating how much drag resists
the movement of particles. It is equivalent to air-resistance. Setting
the drag high is like putting it in water. Too little drag will
keep the system from finding equilibrium. The default drag value
is 0.03.
spawnParticle(parent)
This function spawns a new particle of the same type as its parent.
By default, the particle will be created at position (0, 0, 0).
You can use the setPos() function to move it. If you want to assign
it to a new variable of the same type as its parent, you will have
to cast it to the same type, and your line will end up looking something
like this:
ParticleType particleVariable
= (ParticleType)spawn(parent);
spawnParticle(parent,
X, Y, Z);
This function is just like spawnParticle(parent), except that it
positions the new particle at (X, Y, Z) automatically.
particle.setPos(X,
Y, Z);
For a variable of a particle type called "particle" this
will set its position to (X, Y, Z).
particle.fixed
For a variable of a particle type called "particle" this
boolean variable indicates whether this particle is fixed or free
to move by the forces applied to it. To fix a particle, you would
write
particleName.fixed = true;
particle.pos
For a variable of a particle type called "particle" this
variable is an array of three floats that contains the particle's
position in space.
particle.mass
For a variable of a particle type called "particle" this
variable is the mass of the particle. The default mass is 1.0.
particle.enableCollision(collisionRadius);
Enables collision with a radius of collisionRadius for this
particle. Collision will only occur between two particles who both
have collision enabled.
particle.disableCollision();
Disables collision for this particle.
addSpring(particleA,
particleB);
This function adds a new spring to the system between particleA
and particleB. By default the spring has a rest length of 18.0,
a strength of 0.005, and a damping of 0.001. If you want to modify
this spring's properties, you might want to hold the spring in a
variable by writing a line like this:
Spring s = addSpring(particleA,
particleB);
addSpring(particleA,
particleB, strength, damping, length);
This function is just like the above addSpring(), but you can manually
specify the strength, damping, and length. If you make a spring
too strong or give it too little or negative damping, you will witness
a very interesting numerical explosion. It's worth trying to see
it happen.
drawSprings();
This function is a utility function that you can use in your main
loop to automatically use the current stroke to draw lines representing
each existing spring. You will find that you must match the coordinate
system of the particles they connect (including initial translation
and arcball) or else the springs will be drawn in the wrong place.
spring.restLength
For a Spring variable "spring" this variable is the rest
length of the spring.
spring.damping
For a Spring variable "spring" this variable is the damping
of the spring.
spring.strength
For a Spring variable "spring" this variable is the strength
of the spring.
defaultSpringStrength(defaultStrength);
This function sets the default spring strength for new springs that
are created after the function is called to this value. This way
you can create many springs with the same strength.
defaultSpringDamping(defaultDamping);
This function sets the default spring damping for new springs that
are created after the function is called to this value. This way
you can create many springs with the same damping.
defaultSpringRestLength(defaultRestLength);
This function sets the default spring rest length for new springs
that are created after the function is called to this value. This
way you can create many springs with the same rest length.
addMagnet(particleA);
This function adds a new magnet to the system whose location is
attached to particleA. By default the magnet has a strength of 1.0.
If you want to modify this magnet's properties, you might want to
hold the magnet in a variable by writing a line like this:
Magnet m = addMagnet(particleA);
addMagnet(particleA,
strength);
This function is just like the above addMagnet(), but you can manually
specify the strength.
magnet.strength
For a Magnet variable "magnet" this variable is the strength
of the magnet. |