wm.WILLIAM MARAISLet’s talk ↗
← All projects
SIMULATION / C

Cellular Automata.

A hands-on particle simulation built in C. A grid represents the world, while SDL2 handles the window, rendering and input. The interface lets the user paint and erase materials directly.

STATUSPersonal project
TOOLS & TECHNOLOGIESC / SDL2 / SDL_ttf

An interactive sandbox

The supplied main loop exposes sand, stone, water and glass selection through the number keys. A circular brush paints particles with the left mouse button and removes particles with the right button; the brush size is adjustable.

A compact engine structure

The source separates the main loop, particle handling and rendering into dedicated modules. Screen dimensions determine the particle grid, using a four-pixel scale per cell.

Timing and controls

The event loop accumulates elapsed time and uses a 60 Hz target interval for rendering. The target is a scheduling choice, not a measured performance guarantee. Escape closes the application.

EXPLORE THE SOURCE

Explore the implementation

View repository ↗
git clone https://github.com/SAED2906/CelularAutomata.git

Code example

main.c — brush excerptC
int grid_x = mouse_x / PARTICLE_SCALE;
int grid_y = mouse_y / PARTICLE_SCALE;

for (int i = -brush_size/2; i <= brush_size/2; i++) {
    for (int j = -brush_size/2; j <= brush_size/2; j++) {
        if (i*i + j*j > (brush_size/2)*(brush_size/2)) continue;

        if (remove) {
            remove_particle(grid_x + i, grid_y + j);
        } else if (rand() % 3 != 0) {
            add_particle(grid_x + i, grid_y + j, current_particle_type);
        }
    }
}

NEXT PROJECTC Game Engine ↗