Forever and Stop
Happy new year!
Here is a new year's resolution: by July 2015, we will freeze the Pencil Code interface so that we can build curriculum without worrying about removed features. So mail me any ideas of things
Forever and Stop
Happy new year!
Here is a new year's resolution: by July 2015, we will freeze the Pencil Code interface so that we can build curriculum without worrying about removed features. So mail me any ideas of things that need to be changed in Pencil Code before then - email@example.com.
The first change for 2015 is
forever lets you repeat something indefinitely. Put an
-> after it, then indent code that you want to
forever -> fd 2 rt 2
It is useful for making animations. The previous version
of this function was called
tick. The difference is
forever lets you set up more than one loop to
run at once:
forever -> fd 2 rt 2 forever -> pen random color
The two processes run in parallel forever, so the pen continually changes color as the turtle moves.
stop() nothing is forever
stop() will stop the repetitions.
The following program will run the forever loop, watching for
w and down
s keys on the keyboard. One of them will
v and make the turtle move. The other will stop
the forever loop.
v = 0 forever -> fd v if pressed 'w' v = v + 0.1 if pressed's' stop()
forever loops are different from
forever is a function whose loops are stopped by
calling the function
while are loops that are built-in to the language. To
stop those loops, use the built-in command
The speed of
forever function can be set to repeat at any number of
repetitions per second. Just add an optional number before
forever 1, -> dot random color rt 30 fd 25
The number is the number of repetitions per second.