https://github.com/jerr-it/cellmaker
Multi-threaded library for cellular automata
https://github.com/jerr-it/cellmaker
c c-language cellular-automata cellular-automaton conways-game-of-life hacktoberfest
Last synced: 6 months ago
JSON representation
Multi-threaded library for cellular automata
- Host: GitHub
- URL: https://github.com/jerr-it/cellmaker
- Owner: jerr-it
- License: mit
- Created: 2020-05-25T15:12:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-11T21:06:08.000Z (almost 4 years ago)
- Last Synced: 2025-03-24T03:12:19.153Z (7 months ago)
- Topics: c, c-language, cellular-automata, cellular-automaton, conways-game-of-life, hacktoberfest
- Language: C
- Homepage:
- Size: 41 KB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Cellmaker
Library for simulation of cellular automata, like Conways Game of Life
![]()
![]()
![]()
![]()
How to use
Compile:
```
make
./mainor
gcc -o automaton main.c CellularAutomata/CellularAutomaton.h CellularAutomata/CellularAutomaton.c
./automaton
```Visit main.c for complete file example.
Include:
```c
#include "CellularAutomata/CellularAutomaton.h"
```Define your rules:
```c
//At what neighbor count will a cell survive the current iteration?
unsigned int survive[] = { 2, 3 };
size_t sSize = sizeof(survive) / sizeof(unsigned int);//At what neighbor count will a cell get revived in the current iteration?
unsigned int revive[] = { 3 };
size_t rSize = sizeof(revive) / sizeof(unsigned int);
```Create from array:
```c
bool arr[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
CellularAutomaton autom = newAutomatonFromArray(arr, survive, sSize, revive, rSize, 10, 10);
```Keep in mind that this wraps around the edges, meaning that e.g. cells at the right edge neighbor the cells on the left edge.
Initialize randomly:
```c
srand(time(NULL));
//0.4 means the area will be alive by 40%
CellularAutomaton autom = newAutomaton(survive, sSize, revive, rSize, 0.4, 20, 20);
```Run steps:
```c
for (int i = 0; i < 40; i++)
{
print(autom);
tick(autom);
printf("\n");
}
```Print will print the automaton onto the console. However you can render it however you like by accessing the automatons buffer directly. It's a linear array of bools. Retrieve it by using:;
```c
bool* usedBuffer = currentBuffer(autom);
```Free memory:
```c
freeAutomaton(autom);
```