# gsg211/falling-particle architecture

> Architecture diagram of the GitHub repository gsg211/falling-particle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gsg211/falling-particle
- Repository: https://github.com/gsg211/falling-particle

## Overview

1. **Project shape**
This is a single-process Java simulation built on the **Processing** runtime (`lib/core.jar`). It is not split into services or modules; the whole app lives in `src/` and runs as one interactive sketch.

2. **Entry point and runtime**
`src/Main.java` is the application entry point. It likely initializes the Processing window, drives the frame loop, and hands control to the simulation world. The simulation is therefore frame-based and interactive, not batch or server-driven.

3. **Core world model**
`src/Materials/Grid/MaterialGrid.java` is the central subsystem. It represents the 2D cellular world where particles occupy discrete cells and update based on local neighborhood rules. Most simulation flow should be understood as: read current grid state, compute material interactions, then write the next state.

4. **Material abstraction**
`src/Materials/Material.java` is the base type for everything that can exist in the grid. The enums `MaterialStates.java` and `MaterialTypes.java` provide the classification layer used to distinguish behavior categories such as solid, liquid, gas, powder, energy, and empty space.

5. **Behavior families**
The package layout reflects separate movement/interaction rules:
- `Solids/` for mostly fixed materials like `Wood`
- `Liquids/` for flowing materials like `Water`
- `Gasses/` for rising/dispersing materials like `Steam`
- `Powders/` for granular materials like `Sand`, `WetSand`, and `Ash`
- `Energy/` for transient effects like `Fire`
- `Empty.java` for unoccupied cells

6. **Simulation mechanics**
The main mechanic is local particle physics: gravity, settling, flowing, rising, and exchanging positions with neighboring cells. The existence of `WetSand` and `BurningMaterial` suggests materials can change state or behavior when interacting with nearby particles, not just move independently.

7. **Reaction and transformation layer**
The repository’s chemistry-inspired behavior is encoded as material-to-material interactions. Examples implied by the model:
- **Wood** can transition into a burning state via `BurningMaterial`
- **Fire** acts as an energetic, temporary agent
- **Water** can affect solids/powders and may produce **Steam**
- **Sand** can become **WetSand** when exposed to liquids
- **Ash** is a post-combustion residue
This implies the grid update has a reaction phase in addition to movement.

8. **State progression model**
The architecture is likely driven by per-material update logic: each material decides how it behaves when ticked and what it turns into when conditions change. That means the grid is the shared state container, while each material class encapsulates its own rules.

9. **Boundary between engine and content**
The engine boundary is clean: `MaterialGrid` and `Material` define the simulation framework, while concrete subclasses define the content and rules. Adding a new particle type should mostly involve adding a new `Material` subtype rather than changing the whole engine.

10. **Rendering and interaction**
Because the project uses Processing, rendering and user interaction are probably handled in the sketch layer (`Main.java`) alongside simulation stepping. The visual output is likely a direct grid-to-pixel mapping, with each material rendered by color or style.

11. **External dependencies and tooling**
The only visible external runtime dependency is Processing (`core.jar`). There is no sign of database, networking, or build orchestration complexity; this appears to be a local desktop simulation project.

12. **What an architecture diagram should show**
A good diagram would place `Main` at the top, feeding a frame loop into `MaterialGrid`, which contains the 2D cell state. Around the grid, show the material hierarchy and the interaction paths between categories: movement, collision, reaction, and transformation. The main data flow is grid state in → per-cell material rules → updated grid state out, repeated every frame.

Main entry points: [`src/Materials/Material.java`](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Material.java) (Material), [`src/Materials/Solids/Wood.java`](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Solids/Wood.java) (Wood), [`src/Materials/Liquids/Water.java`](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Liquids/Water.java) (Water), [`src/Materials/Grid/MaterialGrid.java`](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Grid/MaterialGrid.java) (Material Grid)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Main<br/>Processing sketch<br/>[Main.java]"]
  node_processing["Processing<br/>runtime<br/>[core.jar]"]
end

subgraph group_core["Core simulation"]
  node_grid[("Material Grid<br/>cellular world<br/>[MaterialGrid.java]")]
  node_material["Material<br/>base particle<br/>[Material.java]"]
  node_states{{"States<br/>enum"}}
  node_types{{"Types<br/>enum<br/>[MaterialTypes.java]"}}
  node_empty(("Empty<br/>vacant cell<br/>[Empty.java]"))
end

subgraph group_materials["Material families"]
  node_solidbase["Solid<br/>abstract family<br/>[Solid.java]"]
  node_liquidbase["Liquid<br/>abstract family<br/>[Liquid.java]"]
  node_gasbase["Gas<br/>abstract family<br/>[Gas.java]"]
  node_powderbase["Powder<br/>abstract family<br/>[Powder.java]"]
  node_wood(("Wood<br/>solid material<br/>[Wood.java]"))
  node_burning(("Burning<br/>transitional solid"))
  node_water(("Water<br/>liquid material<br/>[Water.java]"))
  node_steam(("Steam<br/>gas material<br/>[Steam.java]"))
  node_sand(("Sand<br/>powder material<br/>[Sand.java]"))
  node_wet(("Wet Sand<br/>powder material<br/>[WetSand.java]"))
  node_ash(("Ash<br/>powder residue<br/>[Ash.java]"))
  node_fire(("Fire<br/>energy effect<br/>[Fire.java]"))
end

node_processing -->|"hosts"| node_main
node_main -->|"ticks"| node_grid
node_main -.->|"renders"| node_grid
node_grid -->|"stores"| node_material
node_grid -->|"fills"| node_empty
node_material -->|"classified by"| node_states
node_material -->|"classified by"| node_types
node_solidbase -->|"extends"| node_material
node_liquidbase -->|"extends"| node_material
node_gasbase -->|"extends"| node_material
node_powderbase -->|"extends"| node_material
node_wood -->|"is a"| node_solidbase
node_burning -->|"is a"| node_solidbase
node_water -->|"is a"| node_liquidbase
node_steam -->|"is a"| node_gasbase
node_sand -->|"is a"| node_powderbase
node_wet -->|"is a"| node_powderbase
node_ash -->|"is a"| node_powderbase
node_fire -->|"specializes"| node_material
node_wood -.->|"transforms to"| node_burning
node_water -.->|"transforms to"| node_steam
node_sand -.->|"absorbs"| node_wet
node_wood -.->|"combusts to"| node_ash
node_fire -.->|"ignites"| node_wood
node_fire -.->|"heats"| node_water
node_water -.->|"wets"| node_sand

click node_main "https://github.com/gsg211/falling-particle/blob/main/src/Main.java"
click node_processing "https://github.com/gsg211/falling-particle/blob/main/lib/core.jar"
click node_grid "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Grid/MaterialGrid.java"
click node_material "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Material.java"
click node_states "https://github.com/gsg211/falling-particle/blob/main/src/Materials/MaterialStates.java"
click node_types "https://github.com/gsg211/falling-particle/blob/main/src/Materials/MaterialTypes.java"
click node_solidbase "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Solids/Solid.java"
click node_liquidbase "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Liquids/Liquid.java"
click node_gasbase "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Gasses/Gas.java"
click node_powderbase "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/Powder.java"
click node_wood "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Solids/Wood.java"
click node_burning "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Solids/BurningMaterial.java"
click node_water "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Liquids/Water.java"
click node_steam "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Gasses/Steam.java"
click node_sand "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/Sand.java"
click node_wet "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/WetSand.java"
click node_ash "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/Ash.java"
click node_fire "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Energy/Fire.java"
click node_empty "https://github.com/gsg211/falling-particle/blob/main/src/Materials/Empty.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_processing toneBlue
class node_grid,node_material,node_states,node_types,node_empty toneAmber
class node_solidbase,node_liquidbase,node_gasbase,node_powderbase,node_wood,node_burning,node_water,node_steam,node_sand,node_wet,node_ash,node_fire toneMint
```

## Components

### Runtime

Processing sketch entry and display loop

- [Main](https://github.com/gsg211/falling-particle/blob/main/src/Main.java): Processing sketch · Entry point and frame loop · `src/Main.java`
- [Processing](https://github.com/gsg211/falling-particle/blob/main/lib/core.jar): runtime · External sketch runtime · `lib/core.jar`

### Core simulation

Shared grid state and material abstractions

- [Material Grid](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Grid/MaterialGrid.java): cellular world · 2D grid of cells and per-frame simulation state · `src/Materials/Grid/MaterialGrid.java`
- [Material](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Material.java): base particle · Common behavior and identity for all grid occupants · `src/Materials/Material.java`
- [States](https://github.com/gsg211/falling-particle/blob/main/src/Materials/MaterialStates.java): enum · Material state categories · `src/Materials/MaterialStates.java`
- [Types](https://github.com/gsg211/falling-particle/blob/main/src/Materials/MaterialTypes.java): enum · Material type categories · `src/Materials/MaterialTypes.java`
- [Empty](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Empty.java): vacant cell · Unoccupied grid cell · `src/Materials/Empty.java`

### Material families

Behavior families and concrete particle types

- [Solid](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Solids/Solid.java): abstract family · Base behavior for fixed or mostly fixed materials · `src/Materials/Solids/Solid.java`
- [Liquid](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Liquids/Liquid.java): abstract family · Base behavior for flowing materials · `src/Materials/Liquids/Liquid.java`
- [Gas](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Gasses/Gas.java): abstract family · Base behavior for dispersing materials · `src/Materials/Gasses/Gas.java`
- [Powder](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/Powder.java): abstract family · Base behavior for granular materials · `src/Materials/Powders/Powder.java`
- [Wood](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Solids/Wood.java): solid material · Static solid that can burn · `src/Materials/Solids/Wood.java`
- [Burning](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Solids/BurningMaterial.java): transitional solid · Burning state of a solid material · `src/Materials/Solids/BurningMaterial.java`
- [Water](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Liquids/Water.java): liquid material · Flowing liquid that interacts with powders and solids · `src/Materials/Liquids/Water.java`
- [Steam](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Gasses/Steam.java): gas material · Transient gas produced by heating or evaporation · `src/Materials/Gasses/Steam.java`
- [Sand](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/Sand.java): powder material · Granular falling particle · `src/Materials/Powders/Sand.java`
- [Wet Sand](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/WetSand.java): powder material · Sand altered by liquid contact · `src/Materials/Powders/WetSand.java`
- [Ash](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Powders/Ash.java): powder residue · Combustion residue particle · `src/Materials/Powders/Ash.java`
- [Fire](https://github.com/gsg211/falling-particle/blob/main/src/Materials/Energy/Fire.java): energy effect · Transient energetic agent that propagates reactions · `src/Materials/Energy/Fire.java`

## Connections

- Processing → Main: hosts · Processing runtime executes the sketch
- Main → Material Grid: ticks · Main drives per-frame world updates
- Main → Material Grid: renders · Main likely draws the grid each frame
- Material Grid → Material: stores · Grid cells hold material instances
- Material Grid → Empty: fills · Unoccupied cells are represented explicitly
- Material → States: classified by · Materials are tagged by state category
- Material → Types: classified by · Materials are tagged by type category
- Solid → Material: extends · Solid family inherits shared material behavior
- Liquid → Material: extends · Liquid family inherits shared material behavior
- Gas → Material: extends · Gas family inherits shared material behavior
- Powder → Material: extends · Powder family inherits shared material behavior
- Wood → Solid: is a · Concrete solid material
- Burning → Solid: is a · Derived burning solid state
- Water → Liquid: is a · Concrete liquid material
- Steam → Gas: is a · Concrete gas material
- Sand → Powder: is a · Concrete granular material
- Wet Sand → Powder: is a · Liquid-altered granular material
- Ash → Powder: is a · Combustion residue material
- Fire → Material: specializes · Transient energy-like material behavior
- Wood → Burning: transforms to · Heat or fire can ignite wood
- Water → Steam: transforms to · Heating or evaporation can produce steam
- Sand → Wet Sand: absorbs · Contact with water alters sand behavior
- Wood → Ash: combusts to · Combustion can leave ash residue
- Fire → Wood: ignites · Fire triggers burning reactions in solids
- Fire → Water: heats · Fire can drive evaporation or phase change
- Water → Sand: wets · Water changes powder state and mobility
