Members
glider :Array.<Array.<number>>
Variable to hold the shape of a glider, an oscilating pattern which
translates across the page.
Type:
- Array.<Array.<number>>
gliderGun :Array.<Array.<number>>
Variable to hold the shape of a Gosper Glider Gun. This is interesting as
it proves that a finite number of cells can replicate indefinietly.
Type:
- Array.<Array.<number>>
grid1 :Array.<Array.<number>>
Used to hold the state of all cell sites in the simulation.
Type:
- Array.<Array.<number>>
grid2 :Array.<Array.<number>>
Used to hold the state of all cell sites in the simulation.
Type:
- Array.<Array.<number>>
gridX :number
Stores the width of the simulation grid
Type:
- number
gridY :number
Stores the height of the simulation grid
Type:
- number
lightSpaceShip :Array.<Array.<number>>
Variable to hold the shape of a light weight space ship, an oscilating
pattern which translates across the page.
Type:
- Array.<Array.<number>>
paused :boolean
Flag to see if the simulation has been paused.
Type:
- boolean
selectedInsertion :string
What type of object will be inserted when the mouse is clicked.
Type:
- string
size :number
Stores the size of one grid cell
Type:
- number
updateRate :number
The interval number of frames between simulation updates.
Type:
- number
usingGrid1 :boolean
Stores which grid is currently being displayed. This allows for the rules
to be applied on the sites of the alternate grid without changing the sites
that are being read.
Type:
- boolean
Methods
clearGrid()
Removes all live cells from the grid.
draw()
p5.js draw function, draws cells on the canvas and updates the simulation
based on updateRate.
drawMenu()
Draws the menu with the keyboard operations on the side of the canvas.
keyPressed()
Handles key presses. Will either switch the global selectedInsertion
variable, pause the simulation of clear the screen.
mousePressed()
Will insert the selected object at the mouse location. Will wrap cells
that go over the edge to the other side of the screen.
neighbours(grid, x, y) → {number}
Function to get the number of live neighbours around a certain cell. If
the cell is at the edge this function will automatically wrap around to
the other side of the grid.
Parameters:
Name | Type | Description |
---|---|---|
grid |
Array.<Array.<number>> | The array on which the neighbours shall be counted. |
x |
number | The coloumn for the cell that will be checked |
y |
number | The row for the cell that will be checked |
Returns:
- How many cells are alive around the given cell.
- Type
- number
randomiseGrid()
Randomly kills or inserts cells at every point on the grid. There is a 50
percent chance of either occurence.
setup()
p5.js setup function, creates canvas and randomises grid1 and grid2.