Langton’s ant simulation made in C using SDL2.
Simple single-source simulation of langton’s ant, made in under 500 lines of C.
Some of the main features:
- Custom grid size and delay at runtime.
- Very easy to modify color palette with no size limit. Supports 4 possible rotations when stepping on each color. Modified at compile-time.
- Unlimited number of ants at runtime, spawned by clicking on the grid.
- Grid overlay with
g
. - Single stepping with
Left arrow
or automatic stepping withSpace
. - Easily customizable by changing macros inside the source.
Clone the repository and run make
. Make sure you have SDL2 installed.
$ git clone https://github.com/8dcc/langtons-ant
$ cd langtons-ant
$ make
...
You can specify the width, height and delay at runtime.
$ ./langtons-ant
Grid size: 100x100
Cell size: 5 px
Delay: 10 ms
Step: 536
$ ./langtons-ant 50 20 200
Grid size: 50x20
Cell size: 5 px
Delay: 200 ms
Step: 231
You can use the following keys:
Key | Description |
---|---|
q | Quit the program. |
ESC | Same as q . |
g | Toggle grid overlay. |
Left Arrow | Single step. |
Space | Toggle auto-stepping. |
Up Arrow | Increase number of steps per frame when auto-stepping. |
Down Arrow | Decrease number of steps per frame when auto-stepping. |
Left Click | Add ant at the specified position. |
Right Click | Remove ant at the specified position. |
Different ants with default color palette:
Single ant with 9 color palette and custom rotations: