Skip to content

8dcc/langtons-ant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Langton’s ant

Langton’s ant simulation made in C using SDL2.

Description

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 with Space.
  • Easily customizable by changing macros inside the source.

Building

Clone the repository and run make. Make sure you have SDL2 installed.

$ git clone https://github.com/8dcc/langtons-ant
$ cd langtons-ant
$ make
...

Usage

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:

KeyDescription
qQuit the program.
ESCSame as q.
gToggle grid overlay.
Left ArrowSingle step.
SpaceToggle auto-stepping.
Up ArrowIncrease number of steps per frame when auto-stepping.
Down ArrowDecrease number of steps per frame when auto-stepping.
Left ClickAdd ant at the specified position.
Right ClickRemove ant at the specified position.

Screenshots

Different ants with default color palette:

https://i.imgur.com/vZMhVev.png

Single ant with 9 color palette and custom rotations:

https://i.imgur.com/8khDVKx.png