Up to this point, we have created programs that deal with the following computer functions:
- Input
- Storage
- Processing (We instructed the computer to make calculations, such as adjusting location and orientation, or count beats per minute for synthetic drum beats.)
- Output (Our focus has been primarily centered on output — observable behaviors generated by the computer such as animation, sound, and text.)
Program State
Arrow Keys to move
Space for regular bomb
Z for nuke
Space for regular bomb
Z for nuke
Programming Variables
Variables in computer programs are similar to both of the types of variables previously discussed — they are both placeholders and changeable quantities. Let's look at examples for each characteristic:
PlaceholderScratch the Cat is minding his business when suddenly a voice from above tells him turn ← [15] degrees! We know from examining his attributes that means subtract 15 degrees from his direction. Or, perhaps the voice tells him move [10] steps. This one is more complicated because it involves modifying both x position and y position and it depends on which direction he is facing. However, to some degree, it doesn't matter, because the variables are an abstraction. Essentially, turn ← [15] degrees means subtract 15 degrees from direction — whatever it is. The variable direction acts as a placeholder.
Variables in computer programs are similar to both of the types of variables previously discussed — they are both placeholders and changeable quantities. Let's look at examples for each characteristic:
PlaceholderScratch the Cat is minding his business when suddenly a voice from above tells him turn ← [15] degrees! We know from examining his attributes that means subtract 15 degrees from his direction. Or, perhaps the voice tells him move [10] steps. This one is more complicated because it involves modifying both x position and y position and it depends on which direction he is facing. However, to some degree, it doesn't matter, because the variables are an abstraction. Essentially, turn ← [15] degrees means subtract 15 degrees from direction — whatever it is. The variable direction acts as a placeholder.
Variables
The mouse will follow your cursor.
Space Bar to drop a banana, that will slow the cat down.
If the mouse and cat touch, the rat will speed up and the cat will slow down.
Space Bar to drop a banana, that will slow the cat down.
If the mouse and cat touch, the rat will speed up and the cat will slow down.