# Chapter 8: Particle System

This code provides the struct and methods for creating a particle system. In graphics programming, a particle system is a technique used to simulate certain fuzzy phenomena, which are otherwise very hard to reproduce with conventional rendering techniques. Examples of such phenomena include fire, smoke, sparks, and rain.

We start by defining a `Particle` struct, which represents a single particle in our particle system. Each particle has properties like `x` and `y` for the position, `x_vel` and `y_vel` for velocity, `life` to determine how long it exists, `size`, `color`, and `alpha` (transparency).

We then implement methods `new` for creating a new `Particle` instance, `update` to change the state of the particle every frame (like position, life and alpha), and `render` to draw the particle on the screen. In the update function, there's a condition to respawn particles at the top of the screen if they reach the bottom.

Following this, we have different functions to spawn different types of particles - `spawn_particles_sparks`, `spawn_particles_fires`, and `spawn_particles_rain`. Each function takes in the position, the number of particles to spawn and modifies the particles based on the type.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lados-organization.gitbook.io/goku/chapter-8-particle-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
