So far our programs were very static. The value of
would be evaluated once, painted on the screen and stay there forever. Now we need to make our program react to the events in outside world. What events? A passage of time
If we want our tree to grow over time, we need to know how much time have passed, so we can update it’s age accordingly.
and passes it to the first (brown) segment. The value of
is our state. In some programs the type of state can be very complex, but in our program it’s simply a
number. It will indicate how much time in milliseconds have passed from the start of the program. Because the time is counted in milliseconds, to get correct results we need to divide it by 5000 (so the tree will grow one generation of segments per five second).
function. It will get two arguments: an incoming message and the current state. Incoming message will always be a duration of time since previous frame, so let’s simply call it
. The state is the current age of the tree, so again we can call it
. In return we must produce a tuple with: