GithubHelp home page GithubHelp logo

jerr-it / cellmaker Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 1.0 42 KB

Multi-threaded library for cellular automata

License: MIT License

C 95.54% Makefile 4.46%
c c-language cellular-automata cellular-automaton conways-game-of-life hacktoberfest

cellmaker's Introduction

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

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:

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:

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:;

bool* usedBuffer = currentBuffer(autom);

Free memory:

freeAutomaton(autom);

cellmaker's People

Contributors

jerr-it avatar schaffung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.