r/Simulated • • 5h ago

Interactive Real-time 3D starling murmuration, simulated and rendered inside a terminal (C99, no dependencies)

Enable HLS to view with audio, or disable this notification

I'm the creator of Cbirds, a bird flock simulator that runs in the terminal, written in C99 with no dependencies and inspired by Craig Reynolds' Boids algorithm. This is its 3D mode, running in Ghostty on macOS.

How the 3D flock works: each bird only listens to its nearest neighbours, seven by default as real starlings do, instead of everyone within a radius. On top of Reynolds' three rules (alignment, cohesion, separation) there is a pull toward a roost that keeps the flock in view, and a slow drift in the air over the roost. The bands, the splits and the folds in the video all come out of those rules. The camera goes once round the flock every two minutes, and nearer birds are drawn bigger and brighter.

Everything is simulated and drawn on the CPU and sent to the terminal as images through the Kitty graphics protocol. The panel in the corner shows what a frame costs: in this clip about 15 ms to simulate, draw and send, about 54 KB to the terminal, at 59 fps. The sliders tune the simulation while it runs.

I started the 2D version in September 2025, mostly out of curiosity, after seeing antirez's C64 terminal emulator (https://github.com/antirez/c64-kitty) and a lecture by Pier Luca Lanzi on multi agent systems at Politecnico di Milano. I did get quite a bit of help from coding agents along the way. One useful thing I ended up building was a custom GIF encoder, so the agents could visually inspect the simulation and check whether their changes worked.

It also has hawks that chase the flock, multiple flocks that merge or avoid each other, text piped in that takes flight (`cat file.txt | cbirds`), Braille rendering for any terminal, and birds that fly between terminal windows.

Source: https://github.com/clainstone/cbirds
Command: `cbirds --render kitty --3d --color prism`
Install: `brew install clainstone/tap/cbirds` (also MacPorts, apt and Nix)

20 Upvotes

4 comments sorted by

3

u/c0ltZ 5h ago

For some reason, the formations and actions of the birds looks very similar to some big schools of fish avoiding a predator or something.

2

u/clainstone 4h ago

True! Setting --hawks 1 you can add a predator btw

1

u/chronicallylaconic 2h ago

This is really impressive! Thanks so much for sharing it with us!

1

u/clainstone 2h ago

Thank you!