10. Function I

166 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
166
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

10. Function I

  1. 1. From last time… • Global vs. local variable scope! • Making static assets with saveFrame()
  2. 2. Functions I CAP
  3. 3. Functions Review void setup() {} void draw() {} • We can do two things with functions:! ! 1. call a function:! ! ! size(500,500); 2. define a function:! ! ! void size(int width, int height) {}
  4. 4. Defining a Function the type of value we expect to be ‘returned’ the arguments we can pass in returnType functionName( argumentList ) { // some code goes here }
  5. 5. the variable type we expect to be ‘returned’ the arguments we will pass in returnType functionName( argumentList ) { // some code goes here } 1. Function Name: a name! 2. Input: the variable types of arguments we will pass in! 3. Output: the variable type that will be returned ( void signifies that we do not expect returned value )
  6. 6. Demo! square() function
  7. 7. Why functions? • Functions organize code in a way that humans can understand! • Modularity: smaller, more readable, more manageable bits of code; it’s debuggable!! • Reusability: you can reuse code within a sketch (two pong paddles) or between sketches
  8. 8. Example Organized into functions vs. pure chaos
  9. 9. Time Permitting! Demo! Make Pong Functions
  10. 10. For next time… • Read Shiffman, p. 107–119 (Functions II)! • Continue (or start) working on Iteration 1 Quiz 2! Variables, Conditionals, & Loops

×