Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/8dcc/langtons-ant
- Owner: 8dcc
- License: mit
- Created: 2022-02-24T21:05:49.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-03T22:11:00.000Z (11 months ago)
- Last Synced: 2025-01-01T22:19:57.055Z (9 days ago)
- Topics: c, cellular-automata, langton-ant, langtons-ant, sdl2, simulation
- Language: C
- Homepage:
- Size: 140 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
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 msStep: 536
$ ./langtons-ant 50 20 200
Grid size: 50x20
Cell size: 5 px
Delay: 200 msStep: 231
#+end_srcYou 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]]