Now that you've seen how to make interactive worlds, you should realize that we can't always BE SURE a world is set up some specific way. Maybe the eskimoGirl is left of the eskimo -- maybe she's to the right. Previously, we saw that we'd prefer to use turnToFace rather than turn left 0.25 meters or something like that -- so that our program is more flexible -- that is, the eskimoGirl will turn and face the eskimo no matter where in the world he is located. That works fine for turning realistically, but what about doing other things realistically?
In this module, we will learn learn how we can calculate values (distances, heights, etc.) based on sizes and locations of objects to allow us to create programs that react more realistically -- based on the specifics of the objects in the world.
Things you will learn in this module:
Vocabulary for this module:
Abstraction: The process of hiding the complexity or detail of an operation while still presenting its essential characteristics. Putting the many instructions that may carry out a given operation into a method with a name that represents the operation is an example of abstraction. Putting a complex mathematical calculation into a function hides away that complexity and is also an example of abstraction.
Function: A function calculates a value. We can use functions to hide away complex mathematical expressions -- a form of abstraction. When we execute a purple function tile (usually when we execute a method where the function is used as a parameter), we say that we "call the function" (just like calling a method). However, when a function is done executing it has calculated a value -- and the value essentially replaces the function call.
Mathematical Expression: A combination of numbers and mathematical operators that give a numerical result (later we will see it can also produce a logical result). (2 + 5) and (length * width * height) are examples of mathematical expressions.
Return (from a function): When functions are executed they calculate a value which we say is then returned to the place where the function was called. In essence, the value calculated replaces the name of the function call. A return in a piece of code acts like a portkey in the Harry Potter(TM) world. When you reach a place in a code where there is a return it flies back to where the function was called returning the value calculated. If there is any code after the return, it will not be executed (we will see examples of this in later modules).