particlepy.particle

class Particle(shape: particlepy.shape.Shape, position: Tuple[float, float], velocity: Tuple[float, float], delta_radius: float, data: Optional[dict] = None, alive: bool = True)[source]

Bases: object

This is the particle class. It simulates the physics of a particle and can be used in a particle system (ParticleSystem)

Parameters
  • shape (particlepy.shape.Shape) – Visual particle shape

  • position (Tuple[float, float]) – Center position

  • velocity (Tuple[float, float]) – Velocity

  • delta_radius (float) – Radius decrease value

  • data (dict, optional) – A dictionary for extra data, defaults to None

  • alive (bool, optional) – True if particle should be alive, and False if otherwise, defaults to True

Attributes
  • shape (particlepy.shape.Shape) – Visual particle shape

  • position (List[float, float]) – Center position

  • velocity (List[float, float]) – Velocity (can be modified with gravity)

  • delta_radius (float) – Radius decrease value

  • progress (float) – A variable ranging from 0 to 1 to represent the lifespan

  • inverted_progress (float) – A variable ranging from 1 to 0 to represent the lifespan

  • time (float) – A simple timer

  • data (dict) – A dictionary for extra data

  • alive (bool) – True if particle is alive, and False if otherwise

kill()[source]

Sets attribute alive False

render(surface: pygame.Surface)[source]

Renders the particle on given surface

Parameters

surface (pygame.Surface) – The surface on which the particle is being rendered on

revive()[source]

Sets attribute alive True

update(delta_time: float, gravity: Optional[Tuple[float, float]] = None)[source]

Updates position, velocity, progress, etc. of particle and kills it, if radius <= 0

Parameters
  • delta_time (float) – A value to let the particle move according to frame time

  • gravity (Tuple[float, float], optional) – Affects the velocity and ‘pulls’ it in a direction, defaults to None

class ParticleSystem(data: Optional[dict] = None, alive: bool = True)[source]

Bases: object

The particle system class. It is used to manage particles in a group

Parameters
  • data (dict, optional) – A dictionary for extra data, defaults to None

  • alive (bool, optional) – True if particle system should be alive, and False if otherwise, defaults to True

Attributes
  • particles (List[Particle])

  • data (dict) – A dictionary for extra data

  • alive (bool) – True if particle system is alive, and False if otherwise

clear()[source]

Clears the particle list

emit(particle: particlepy.particle.Particle)[source]

Creates a new particle

Parameters

particle (Particle) – Particle which is being created

Raises

Exception – Particle system is not alive, not able to add particles

kill()[source]

Sets alive False

make_shape()[source]

Makes the surface of all particles in system

render(surface: pygame.Surface)[source]

Renders surface of all particles on given surface

Parameters

surface (pygame.Surface) – Surface on which the particles are being rendered

revive()[source]

Sets alive True

update(delta_time: float, gravity: Optional[Tuple[float, float]] = None)[source]

Calls Particle.update() for every particle in system

Parameters
  • delta_time (float) – A value to let the particles move according to frame time

  • gravity (Tuple[float, float], optional) – Affects the velocity and ‘pulls’ particles in a direction, defaults to None