Members
antState :boolean
A global boolean storing the current ant state.
Type:
- boolean
antx :number
A global variable storing the ant's x position.
Type:
- number
anty :number
A global variable storing the ant's y position.
Type:
- number
bearing :number
A global variable storing the direction that the ant is facing.
Can take the value of up, right, down or
left.
Type:
- number
(constant) down :number
A global constant that denotes one of the four possible ant directions in
this case it is the downwards direction.
Have a look at bearing
Type:
- number
grid :Array.<Array.<boolean>>
The grid variable stores the state of the world that the turmite is moving
through in the global namespace.
Type:
- Array.<Array.<boolean>>
(constant) left :number
A global constant that denotes one of the four possible ant directions in
this case it is the left direction.
Have a look at bearing
Type:
- number
(constant) right :number
A global constant that denotes one of the four possible ant directions in
this case it is the right direction.
Have a look at bearing
Type:
- number
scale :number
Scale is a global variable that determines how many pixels will take up one
grid square.
Type:
- number
(constant) up :number
A global constant that denotes one of the four possible ant directions in
this case it is the upwards direction.
Have a look at bearing
Type:
- number
Methods
draw()
p5.js draw function.
Draws the ant and calculates it's next movement.
moveForward()
Change the ants position depending on which direction it is facing.
setup()
p5.js setup function.
Creates a html canvas and adds a white background.
Set all values in the grid to 1.
Initialise the antx, anty and bearing variables.
Set the antState to false.
turnLeft()
Turn left changing the ants bearing.
turnRight()
Turn right changing the ants bearing.