project / learning note

An SDL2 agent-model sketch

A single-file C/SDL2 draft models one hundred moving agents with position, velocity, and simple boundary bounces.

I asked for a small agent model in C using SDL2, and the response drew one hundred moving squares in a black window. There was a useful mismatch between the name and the actual behavior. Each square had a position and velocity, bounced at a screen boundary, and never interacted with another square. That made the draft a good first exercise in event handling and rendering, while leaving the “agent” behavior I might add later untouched.

The source was a single generated file with an initialization step, update loop, and cleanup path. I have no compile or run report for it. The code below is the part I could inspect: how the positions changed each frame and what the boundary test did. It also exposes limits I would have to address before claiming a timed simulation, including frame-based movement and a check that ignores each square’s own width.

Each generated agent carries four numbers:

typedef struct {
    float x, y;
    float vx, vy;
} Agent;

The initialization chooses random positions across the window. Each velocity component is an integer from −2 to 2, stored in a float. That means an agent can move horizontally, vertically, diagonally, or remain still when both components are zero.

The central update supplied in the draft is short enough to show directly:

agents[i].x += agents[i].vx;
agents[i].y += agents[i].vy;

if (agents[i].x < 0 || agents[i].x > WINDOW_WIDTH) {
    agents[i].vx = -agents[i].vx;
}
if (agents[i].y < 0 || agents[i].y > WINDOW_HEIGHT) {
    agents[i].vy = -agents[i].vy;
}

After processing the quit event and updating the agents, the loop clears the renderer, draws each agent as a four-pixel square, presents the frame, and calls SDL_Delay(16). Window and renderer creation have error checks, and the exit path destroys both before quitting SDL.

A few limits are visible directly in this code. Movement is per frame, without an elapsed-time multiplier. The boundary check uses the position against the full window dimension, rather than accounting for the square’s width. The response labels the delay as approximately 60 FPS, but there is no frame-time measurement or guarantee in the draft.

The assistant also supplied this compile command:

gcc agent_model.c -o agent_model -lSDL2

I had a readable SDL loop and a moving-square example to inspect, with clear holes where agent interactions and timed motion should go. No compiler or runtime output in this conversation showed those squares actually moving on my machine.

Related rabbit holes

PublishedOct 3, 2026
note / experiment

A thin-client Linux experiment

A network-boot question became a comparison of separate remote desktops and shared physical desktops, ending with a usable Linux thin-client session and working audio.

Documented activity: September 20, 2026 – September 26, 2026