gencellular

package
v0.0.0-...-ab92d4e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

README

Simple Cellular Automata in Golang (WIP)

This package currently only implements Conway's Game of Life.

The code was inspired by: github.com/rafael-santiago/googol

Principle

I'll write something here some day when this is done.

IOU

Proper documentation whenever this is finished.

Cells!

alt text

Documentation

Overview

Package gencellular implements cellular automata (for now Conway's Game of Life).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalDefault

func EvalDefault(currState bool, numNeighbors int) bool

EvalDefault is the default evaluation function used to evaluate the state of a cell in the next generation.

func SeedDefault

func SeedDefault(cells [][]bool, w, h int)

SeedDefault is the default init function used to initialize the simulation.

Types

type Animator

type Animator struct {
	*Culture
	// contains filtered or unexported fields
}

Animator is a cell culture that can be animated and exported to a GIF.

func NewAnimator

func NewAnimator(height, width int) *Animator

NewAnimator returns a new cell culture animator with the given height and width.

func NewAnimatorCustom

func NewAnimatorCustom(height, width int, sf SeedFunc, ef EvalFunc) *Animator

NewAnimatorCustom allows for a custom seed init and state eval function.

func (*Animator) ExportGif

func (c *Animator) ExportGif(path string) error

Export all frames to a GIF under the given path.

func (*Animator) Reset

func (c *Animator) Reset()

Reset the simulation and clear all frames.

func (*Animator) Tick

func (c *Animator) Tick()

Tick advances the culture by one tick and stores the current state in the frame.

type Culture

type Culture struct {
	Cells      [2][][]bool // Cell buffers.
	Height     int         // Number of cells over x.
	Width      int         // Number of cells over y.
	Generation int         // Number of ticks.
	Init       SeedFunc    // Function used to initialize the culture.
	Eval       EvalFunc    // Function used to evaluate the state of a cell in the next generation.
}

Culture was a very smart way to call whatever holds the cells.

func New

func New(height, width int) *Culture

New returns a new cell culture with the given height and width.

func NewCustom

func NewCustom(height, width int, sf SeedFunc, ef EvalFunc) *Culture

NewCustom allows for a custom seed init and state eval function.

func (*Culture) Reset

func (c *Culture) Reset()

Reset the simulation.

func (*Culture) Tick

func (c *Culture) Tick()

Tick advances the culture by one tick.

type EvalFunc

type EvalFunc func(currState bool, numNeighbors int) bool

EvalFunc is the type of function used to evaluate the state of a cell in the next generation.

type SeedFunc

type SeedFunc func(cells [][]bool, w, h int)

SeedFunc is the type of function used to initialize the simulation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL