module: particle_system

the particle system allows you to easily add different particles to the tree to create epic effects

This is a fairly basic particle system, the behavours of the particles are specified in a subclass, then are added to the simulation

the particle system will then advance each particle, and then draw them to the tree

class: ParticleSystem

The main particle system runner

from particle_system import ParticleSystem
ParticleSystem(tree: Tree)

initiate a particle system for the tree, this should be done once within the run function

from tree import tree ... def run(): ps = ParticleSystem(tree) ...
add_particle(particle: Particle, start: boolean = False)

Add a particle to the simulation, set start to true to insert the particle at the start of the system's particle list

ps.add_particle(snowflake1)
advance()

this will call the advance function on all particles, but does not draw

ps.advance()

There are two methods of drawing, "draw" allows for complete control of rendering of each particle, "fast_draw" goes through each pixel and asks each particle if can color it, which can reduce the amount of draw calls to each particle

draw()

runs the draw function for all particles

ps.draw()
fast_draw()

run fast draw for each pixel for each particle, better for perfomance of lots of overlapping particles, but may lead to unpredicatable overlap coloring

ps.fast_draw()

class: SphereParticle

This is a particle of a sphere, you should sub class this to fill in your own advance function to add behaviour to it

from particle_system import SphereParticle
SphereParticle(x: float, y: float, z: float, radius: float, max_age: int, color: Color)

typically when subclassing you'll use super().__init__(...) syntax

1 2 3 4 5 6 7 8 9 10 11 12 13 14 class SnowFlake(SphereParticle): def __init__(self, x, y): super().__init__(x, y, tree.height + 0.2, 0.2, 100, Color(200, 200, 240)) self.yVel = 0.05 # add custom y velocity variable def advance(self): self.z -= self.yVel # move down by velocity self.yVel += 0.002 # add to velocity like gravity if (self.z < -0.2): # if we're beneath the tree set is_dead to true to kill the particle next advance self.is_dead = True ... new_snowflake = SnowFlake(random.random() -0.5, random.random() -0.5) ps.add_particle(new_snowflake)
Custom Particles

Creating a custom particle is as simple as subclassing the Particle class and implementing a draw or fast_draw method.

the difficult part is coming up with a parametric equasion for the shape you wanna create. for most cases a sphere will do as there is not enough detail in the tree to make out anything inticate

see the implementation of SphereParticle to get an idea of the draw and fast_draw methods, bear in mind you only need one, but be sure to call the corresponding method from the particle system