Skip to content

Latest commit

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Cellmaker


Library for simulation of cellular automata, like Conways Game of Life

How to use

Compile:

make ./main
or
gcc -o automaton main.c CellularAutomata/CellularAutomaton.h CellularAutomata/CellularAutomaton.c
./automaton

Visit main.c for complete file example.

Include:

#include"CellularAutomata/CellularAutomaton.h"

Define your rules:

//At what neighbor count will a cell survive the current iteration?unsigned intsurvive[] = { 2, 3 };
size_tsSize=sizeof(survive) / sizeof(unsigned int);
//At what neighbor count will a cell get revived in the current iteration?unsigned intrevive[] = { 3 };
size_trSize=sizeof(revive) / sizeof(unsigned int);

Create from array:

boolarr[] =
{
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
};
CellularAutomatonautom=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:

srand(time(NULL));
//0.4 means the area will be alive by 40%CellularAutomatonautom=newAutomaton(survive, sSize, revive, rSize, 0.4, 20, 20);

Run steps:

for (inti=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:;

bool*usedBuffer=currentBuffer(autom);

Free memory:

freeAutomaton(autom);

About

Multi-threaded library for cellular automata

Topics

Resources

Stars

13 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages