Programmed cells follow rules and evolve
The superclass of all elements on screen, named class Element
this.age
is the age of the element, or the number of frames it has been onscreen.this.x
andthis.y
designate the position of an element on screen, where(0,0)
is the top left of the canvas.this.size
is the diameter of the object, in pixels.this.color
is the color value of the object inhex
, stored as aString
.
None
A class containing a single command used by a Cell
instance
this.condition
specifies an array with 3 values, in the formdistanceTo(subject) (comparison) (value)
.this.action
is the action to be taken whenthis.condition
istrue
.
The main element of the simulation; this is what evolves.
class Cell
is a subclass ofElement
, and inherits its attributes.this.args
is a list of theCommand
instances that this cell follows.this.defComm
is the defaultCommand
to follow if none of the conditions inthis.args
are fulfilled.this.fraction
is the percentage of mass baby takes when reproducing.
- Method
move()
calls all the necessary methods each frame. - Methods beginning with
closest
are used to find the subjects for aCommand
instance. - Methods
eatCells()
andeatFood()
are used to consume nearby smaller cells and food - Method
reproduce()
is used when the cell wants to reproduce, creating a new cell with a possibility of mutation in commands. dist()
andcompDist()
are used to find the distance between two cells.compDist
also returns the target position.
Eaten by the cell. This spawns randomly, but is also created around instances of Spawner
and underneath large Cell
objects.
class Food
is a subclass of Element
, and inherits its attributes.
None
Spawners create food around them when a smaller cell is eaten by it.
class Spawner
is a subclass ofElement
, and inherits its attributes.this.id
is the id of the spawner.this.defaultSize
is the initiation size of the spawner.
The only method, this.act()
, does three main things:
- Eat nearby
Cells
that are small - Eat
Food
- Expel
Food
outside ifthis.size
is greater thanthis.defaultSize
Force larger cells to split (reproduce()
) while allowing smaller cells to hide.
class Petri
is a subclass of Element
, and inherits its attributes.
splitCells()
splits larger cells within range.