https://github.com/liamg/gca
:microscope::game_die: Go Cellular Automata
https://github.com/liamg/gca
cellular-automata cellular-automaton procedural-generation
Last synced: 10 months ago
JSON representation
:microscope::game_die: Go Cellular Automata
- Host: GitHub
- URL: https://github.com/liamg/gca
- Owner: liamg
- Created: 2019-07-31T18:54:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-31T19:25:03.000Z (over 6 years ago)
- Last Synced: 2025-02-07T12:49:05.996Z (11 months ago)
- Topics: cellular-automata, cellular-automaton, procedural-generation
- Language: Go
- Homepage:
- Size: 86.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go Cellular Automata
[](https://godoc.org/github.com/liamg/gca)
A simple cellular automata package, useful for procedural generation.
Configurable, but has a helpful out of the box config that meets basic needs. Currently uses [Moore neighbourhoods](https://en.wikipedia.org/wiki/Moore_neighborhood).

You can see the code used to generate this gif in [examples/gif/main.go](examples/gif/main.go).
## Installation
GCA supports go modules, but will also work fine without, just use:
```
go get -u github.com/liamg/gca
```
## Usage Example
```go
package main
import (
"fmt"
"github.com/liamg/gca"
)
func main() {
grid := gca.NewGrid(80, 24)
grid.Initialise()
grid.SetMinNeighboursToBirth(5)
grid.SetMinNeighboursToRemain(2)
grid.Run(3)
w, h := grid.Size()
for y := 0; y < h; y++ {
for x := 0; x < w; x++ {
if grid.Read(x, y) {
fmt.Printf(" ")
} else {
fmt.Printf("#")
}
}
fmt.Printf("\n")
}
}
```
...will output something like:
```
# ## #### ###### ####### ### #### ## ####### #
# #### ### ## ## # ###### ##
# #### ## ## ### ## ### ###### ##
# ## ## # ### #### ## ## # ###### ##
# # ### ##### ## ##### ####
## ##### ## ## #
# # ####
### ## #### ## ###
####### ### ### ### #
# ## ## # # #### ### #
## ## ### ### #
# ## ### ### ### #### #
## ## ###### ##### ### ## #
### ## ######## ####### ####### #
## # #### ## ####### ## ### ## ## ######## ##
# # ## ### ## ####### ### ## ### ######## ###
## ### ### ## ####### ## ## ## ## #
### ### # ## ##### ## ## ## ## #
## #### ### #### ### # ### # #
# # ## ## # #### ## # ### #
# ### ### ## #### ### ##
# #### ### ### #### ## ###
# ###### ##### #### ###### ## # ## # #
# ## ######## ############# ####### ### ### ### ### ######
```