This is a model of an ecosystem. The fish move around, eat plankton, reproduce and die. The plankton move around slowly and reproduce.
Explanation of the Code Blocks
![]() |
Start by looking at the Runtime area in the Blocks
window.
The Forever block will create a 'Forever' button in the SpaceLand window, which you can click to make the simulation run. You can see the Procedures (Green blocks) that tell the fish and plankton what to do. Procedures are just blocks of code with a name . So the Fish move left or right, go up and down, reproduce and die The plankton move left or right slowly, go up and down (in the same way as the fish do), and multiply. |
![]() |
Next look at the Setup area of the Blocks window.
The Setup Block creates a button in SpaceLand that will do
whatever is in the blocks it contains. Clear Everyone - removes all objects from SpaceLand Create Fish
Create Plankton
Scatter Everyone spreads fish and plankton all around SpaceLand.
|
Now move to the Fish Area in the Blocks window.
![]() |
is just the name of a 'variable' that holds the value of a fish's energy at any one time. It is an 'agent variable' (blue) meaning that it has a separate value for each different fish. |
![]() |
This is the procedure that tells the fish how to move. They move left a random number of degrees up to 10, then right a random number of degrees up to 10. This has the total effect of turning them in a random direction up to 10 degrees left or right. Then they move forward 1 step. Moving takes energy, so the energy variable is incremented (increased) by -.05 (Increasing it by a negative amount is the same as decreasing it). |
![]() |
This is the procedure that makes the fish move up and down
randomly, but keeps them from going too high (over 30) or below
the ground level.
Random 3 will produce numbers 1, 2 or 3. So random 3 - 2 will produce -1, 0, or 1 for final values. So the fish will randomly move down 1, stay the same, or move up 1. If altitude goes below 1, then it gets set back to be 1 (so the fish can't go below the ground) If altitude goes above 30, it gets set back to 30 (so the fish can't go up out of the water)
|
![]() |
If Fish energy goes below 0, then they die (disappear). |
![]() |
If Fish and Plankton collide, then the Fish eats the plankton. The fish energy goes up .5 and the plankton die (disappear) |
![]() |
If Fish have energy above 5, they will reproduce. When they reproduce, their energy goes down by 2. Hatch produces a baby. The baby is given a random heading (so it will move off in a random direction). It will move forward a random number of steps up to 3, and its energy will start out with a value of 2. |
Next we will look at the procedures for the Plankton.
![]() |
Plankton move in a similar way to the fish, but only go forward .1 of a step each time, so they are moving very slowly. |
![]() |
This is the procedure to make the plankton multiply. Test random 50 = 1, produces a random number between 1 and 50 and tests to see if it equals 1. It will equal one roughly once in 50 times. If the random number was equal to 1, then it tests to see if there are less than 500 plankton left. If so then reproduction will happen. The total result of all this is that about one in 50 of the plankton will reproduce each step of the game, as long as total plankton numbers are below 500. |
Add in Monitoring to Track the Number of Fish and Plankton
![]() |
|














