Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/8dcc/langtons-ant

Langton's ant simulation made in C using SDL2
https://github.com/8dcc/langtons-ant

c cellular-automata langton-ant langtons-ant sdl2 simulation

Last synced: 3 days ago
JSON representation

Langton's ant simulation made in C using SDL2

Awesome Lists containing this project

README

        

#+title: Langton's ant
#+options: toc:nil
#+startup: showeverything
#+author: 8dcc

*Langton's ant simulation made in C using SDL2.*

#+TOC: headlines 2

* Description

Simple single-source simulation of [[https://en.wikipedia.org/wiki/Langton%27s_ant][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 [[https://www.libsdl.org/][SDL2]] installed.

#+begin_src console
$ git clone https://github.com/8dcc/langtons-ant
$ cd langtons-ant
$ make
...
#+end_src

* Usage

You can specify the width, height and delay at runtime.

#+begin_src console
$ ./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
#+end_src

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. |

* 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]]