floor
is a mathematics primitive that reports the closest integer below a given number. In other words, it rounds the number down. For example, floor 5.2
would report 5, and floor -4.8
would report -5.
In the model example below, each turtle has a my-money
variable that increases or decreases a little bit at each tick. We use the floor
primitive to round up a turtle's my-money
variable because we want to present a label under each turtle showing their current money. If we do not round this variable either up or down, their labels would show many floating point numbers such as 1.822882372836
, which would be visually unpleasant. We also use the floor
primitive in setting each turtle's ycor
parameter so that the turtles move only when the rounded-up version of their my-money
variable changes. If they make or lose just a little bit of money, they remain stationary. Lastly, we use the floor
, and its opposite ceiling
, for two of our three monitors in the interface.
xxxxxxxxxx
globals [average-wealth]
turtles-own [ my-money ]
to setup
clear-all
create-turtles 4 [
set shape "businessperson"
set size 2
setxy random-xcor 0
set label 0
]
reset-ticks
end
to go
ask turtles[
set my-money my-money + random-float 1 - random-float 1
set label floor my-money
set ycor floor my-money / 5
]
calculate-average-wealth
tick
end
to wiggle
right random 90
left random 90
end
to calculate-average-wealth
set average-wealth mean [my-money] of turtles
end
Once you mastered the floor
primitive, don't stop there. Check out the resources below to improve your NetLogo skills.
floor
primitive: