FunctionsFunctions are portions of code within a program that does something specific. We've used some functions that are a part of the Processing language already. Functions have a name followed by parameters in parentesis. Like rect(100,100,50,50). The functions we've used so far work the same every time we use them, with the exception of how the parameters change them. In this unit we will be using functions that are specific to Processing, but you will program the behavior of.Watch the video below and read Pages 51-52 in Getting Started with Processing.
What should you know?
Mouse InputIn this unit we will add our first unser input. What I mean by this is you do stuff while the program is running and it responds to you! We're continuing through chapter 5 of Getting Started with Processing. The video below walks you through examples 5-4 thru 5-6. Watch the video, read 53-55, and play with the program examples. Changing things up a bit and see what happens.
Example 5-7 introduces the dist() function. Basically dist() simply finds the distance between any two points. Try the program below to see how it works.
Try out Example 5-7. Play with it and see if you can make it cooler.
Another very useful function is map(). Map is used to rescale variables. You can think of it as dimensional analysis without all the mind-numbingness. The video below describes how map works.
Map has 5 parameters:
Reproduce my code for an "eye" and tweak it a bit to make it work better. You can even map things backwards if you want. Swap the positions of the new smallest and new biggest and see what happens. Also work through examples 5-10 and 5-11 from the book. Mouse ClickNew Code
Mouse FunctionsSetup and Draw are not the only Functions built into Processing. The mouse variables can also be executed as functions. These functions will be run once when the event happens. This will interrupt whatever else is happening in the sketch. So, Draw loops over and over again, but if the mouse is clicked the code in void mousePressed() will execute immediately and then then the program will pick up exactly where it left off. Try the code below: Mouse Functions Available:
|
Intro to Processing >