Particle module¶
For the purposes of this simulator, particles are objects which are rendered, and may behave in interesting ways, but do not have mass like ForceObjects and only remain on the screen for a limited duration.
They can be used to draw debug lines, add some kind of effect, or so forth.
They are updated by the PhysicsCanvas, which they add themselves to.
To make a new particle, just extend the Particle.Particle
and overwrite the draw and transform methods.
There is no need to override the update and add_to methods.
To use a particle, initialize it, set its displacement to a vector, then call add_to(physicsCanvas)
-
class
Particle.
Line
(duration, vector, color='#55443C', width=1, arrow='last')[source]¶ Bases:
Particle.Particle
Draws a Line on the canvas from a vector.
Only required params are duration and vector.
- Parameters
duration (number) – How long to stay on screen (seconds)
vector (
Physics.Vector
) – A vector to calculate the line fromcolor (str) – Color of the line, default is gray-purple
width (int) – Width of line, default is 1
-
class
Particle.
Particle
(duration=1)[source]¶ Bases:
object
The base particle class.
By default, for debug purposes, just shows a square at the origin that moves SE
- Parameters
duration (number) – The time to display the particle (s)
-
add_to
(physics_canvas)[source]¶ Adds this Particle to the physics canvas, appending it to the list of particles to be updated and making the internal reference of self.physics_canvas.
Afterwards, calls self.draw
No need to overwrite this in extending classes; overwrite self.draw instead.
- Parameters
physics_canvas –
- Returns
-
canvas_id
¶ Id for moving on canvas
-
displacement
¶ Vector from physicsCanvas origin that particle will be placed
-
draw
()[source]¶ Draws Particle on the physics canvas.
Overwrite this method on inheriting particles.
-
physics_canvas
¶ Particle gets a reference to PhysicsCanvas at the time add_to is called.
-
time_remaining
¶ How much time the particle has left before it’s removed from the rendered/referenced objects
-
class
Particle.
Triangle
(duration, x1, y1, x2, y2, x3, y3, color='blue')[source]¶ Bases:
Particle.Particle
Probably can remove this - didn’t wind up using