Documentation ¶
Index ¶
Constants ¶
const ( // CellularAutomataType identifies the cellular automata simulation CellularAutomataType = "cellular_automata" // SlimeMoldType identifies the slime mold simulation SlimeMoldType = "slime_mold" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CellularAutomataConfig ¶
type CellularAutomataConfig struct { // NSpecies is the number of different types of species that exist NSpecies int // PredatorThreshold is the amount of neighboring predators cells it takes // to eat a prey cell PredatorThreshold int // PredatorDirs contains the cardinal directions that predators may attack // prey cells from PredatorDirs []string }
CellularAutomataConfig are options specific to the cellular automata simulation
type Features ¶
type Features struct { // SpeciesID identifies the species type of a cell SpeciesID int // Neighbors stores pointers to an organism's neighbors Neighbors []*Organism // XPos is a float that represents an organisms location within the Grid. // Positions are floats so that organisms can be at locations that are between // Spaces. This allows them to travel in any direction (otherwise they would // be limited to 45˚ increments). Their visible location will still be one // discrete Space (whichever Space they are closest to). XPos float64 // YPos is a float that represents an organisms location within the Grid. // Positions are floats so that organisms can be at locations that are between // Spaces. This allows them to travel in any direction (otherwise they would // be limited to 45˚ increments). Their visible location will still be one // discrete Space (whichever Space they are closest to). YPos float64 // direction represents the angular direction (in degrees) that an organism // is facing. Direction gridphysics.DegreeAngle }
Features are various parameters that define an organism. Not all features are used in every simulation.
type Grid ¶
type Grid struct { // Rows is a 2-dimensional array that contains Spaces in the inner-array. Rows [][]*Space }
Grid represents the simulation area. It contains Spaces that organisms occupy and move through.
func (*Grid) DrawImage ¶
func (g *Grid) DrawImage(s Simulation) (*image.Paletted, error)
DrawImage draws the current state of the grid into a paletted image
func (*Grid) GetNeighbors ¶
GetNeighbors finds and returns all of the spaces that are adjacent to the given coordinates
func (*Grid) GetSpace ¶
GetSpace returns the Space that resides at a given coordinate if the coordinate exists in the grid
type NextFeatures ¶
NextFeatures holds the next state of certain features, so we can calculate every state transition and apply them all at once.
type Organism ¶
type Organism struct { ID int Features *Features NextFeatures *NextFeatures }
Organism represents one creature that can be displayed at one Space
func NewOrganism ¶
NewOrganism instantiates and returns a new Organism
type Simulation ¶
type Simulation interface { OutputName() (string, error) InitializeGrid(g *Grid) error AdvanceFrame(g *Grid) error DrawSpace(sp *Space, img *image.Paletted, x int, y int) error GetPalette() color.Palette }
Simulation is the interface that all simulations must follow
type SimulationConfig ¶
type SimulationConfig struct { CellularAutomata CellularAutomataConfig SlimeMold SlimeMoldConfig }
SimulationConfig holds the configurations for the simulation
type SlimeMoldConfig ¶
type SlimeMoldConfig struct { ScentDecay float64 ScentSpreadFactor float64 SenseReach int SenseDegree int }
SlimeMoldConfig are options specific to the cellular automata simulation
type Space ¶
type Space struct { Organism *Organism Neighbors []*Space Features *SpaceFeatures }
Space represents one discrete location that may be occupied by an organism.
type SpaceFeatures ¶
type SpaceFeatures struct { // Scent represents the strength of a scent that may be left behind by organisms. Scent float64 }
SpaceFeatures contains optional features of a Space that apply to certain simulations.