Move Draw Loop
There are many ways to do interactive programs. The Move/Draw system shown here is often used in video games.
Two functions are set up, each to do a different part of the game.
The move function controls what is happening. User input is read and any movement of objects occur in this function.
During the draw function everything in the game is at a standstill. The job of the draw function is to put an image of the current state of the game on the screen.
The example below makes an etch-a-sketch. The move function checks the keys 37,38,39,40 (the arrow keys) and changes the variables cx and cy. The draw function just draws a circle at cx,cy. The screen is never cleared so whenever the circle moves it will leave a trail.
The last line of the program is run(move,draw). The run function repeatedly calls move then draw thirty times a second.
You may give run an optional third parameter to adjust the speed run(move,draw,60) will make the move/draw calls 60 times a second.