gameoflife

package module
v0.0.0-...-68739dd Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

gameoflife

John Conway's Game of Life

example

package main

import(
	gl "github.com/nichtsen/gameoflife" 
)

func main() {
	//board length, width,
	//and block length by pixels
	width, len, unit := 5, 5, 100
	//1 for alive 0 for dead
	b, err := gl.NewBlock(
		width,
		len,
		[]byte{
		0,1,0,0,1,
		0,1,1,1,0,
		0,1,1,0,0,
		0,1,0,0,0,
		1,0,0,1,0},
	)
	if err != nil {
		panic(err)
	}
	br := gl.NewBoard(&b, unit)
	// transition for 10 times
	br.Transition(10)
}

generation0 generation1 generation2 generation3 generation4 generation5 generation6 generation7 generation8 generation9

Documentation

Index

Constants

View Source
const (
	Framename      = "generation"
	Ext            = ".jpg"
	MaxTransitions = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	// contains filtered or unexported fields
}

Block is a matrix of x * y size

func NewBlock

func NewBlock(width, height int, s []byte) (Block, error)

NewBlock return a Block, width on the horizontal line(x axis), height on vertical line(y axis) TODO 4 bit a byte

func (*Block) Next

func (b *Block) Next()

Next moves to next status of matrix

func (*Block) String

func (b *Block) String() string

func (*Block) Update

func (b *Block) Update(x, y int)

Update status of a pixel in matrix

type Board

type Board struct {
	image.RGBA
	// contains filtered or unexported fields
}

Board can visualize its underlying Block

func NewBoard

func NewBoard(b *Block, unit int) *Board

NewBoard return a new Board for visualizing its underlying Block

func (*Board) Transition

func (b *Board) Transition(n int)

Transition for n times

func (*Board) Update

func (b *Board) Update()

Update the Board to next frame

func (*Board) WriteImg

func (b *Board) WriteImg(name string)

WriteImg writes the Board to a image file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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