From last time…
•

Global vs. local variable scope!

•

Making static assets with saveFrame()
Functions I

CAP
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) {}
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
}
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 )
Demo!
square() function
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
Example
Organized into functions

vs. pure chaos
Time Permitting!

Demo!
Make Pong Functions
For next time…
•

Read Shiffman, p. 107–119 (Functions II)!

•

Continue (or start) working on Iteration 1

Quiz 2!
Variables, Conditionals, & Loops

More Related Content

KEY
Thinking Like a Programmer
PPTX
Constructor and destructor in c++
PPTX
Default constructors in C++
KEY
Ruby: Beyond the Basics
PPTX
Set Default Values to Fields in Odoo 15
PPTX
Declarative JavaScript concepts and implemetation
ODP
Getting started with typescript and angular 2
PPTX
operator overloading & type conversion in cpp over view || c++
Thinking Like a Programmer
Constructor and destructor in c++
Default constructors in C++
Ruby: Beyond the Basics
Set Default Values to Fields in Odoo 15
Declarative JavaScript concepts and implemetation
Getting started with typescript and angular 2
operator overloading & type conversion in cpp over view || c++

What's hot (20)

PPS
Underscore
ODP
JavaScript Object Oriented Programming Cheat Sheet
PDF
JavaScript: Patterns, Part 2
PPTX
JS Fest 2018. Douglas Crockford. The Better Parts
PDF
Operator_Overloaing_Type_Conversion_OOPC(C++)
PPTX
Javascript Tip and Triks
PPTX
PDF
C# 4.0 dynamic
PDF
Scala the-good-parts
PDF
Continuations in scala (incomplete version)
PDF
JavaScript: Patterns, Part 3
PDF
Client sidescripting javascript
KEY
Underscore.js
PPTX
Bca 2nd sem u-4 operator overloading
PDF
Objective-C talk
PPTX
Swift vs Objective-C
ODP
Objectivec vs swift
PPTX
Introduction to underscore.js
PPTX
Qtp training session IV
PPTX
Underscore
JavaScript Object Oriented Programming Cheat Sheet
JavaScript: Patterns, Part 2
JS Fest 2018. Douglas Crockford. The Better Parts
Operator_Overloaing_Type_Conversion_OOPC(C++)
Javascript Tip and Triks
C# 4.0 dynamic
Scala the-good-parts
Continuations in scala (incomplete version)
JavaScript: Patterns, Part 3
Client sidescripting javascript
Underscore.js
Bca 2nd sem u-4 operator overloading
Objective-C talk
Swift vs Objective-C
Objectivec vs swift
Introduction to underscore.js
Qtp training session IV
Ad

Viewers also liked (20)

PPTX
Power point de Educación Física (Tennis)
ODP
αναστάσιμα έθιμα ανά την ελλάδα
PPTX
Wc unit 3 work place commuication
PPS
Sochi
PDF
9. Loops II
PDF
A. Design Thinking Lecture
PDF
20. Mathematics I
PPTX
Socialmedia_Mitchell
PDF
2. Processing
PDF
12. Objects I
PDF
3. Final Project - Intro
PDF
MoretonSmith Receivables Management Intro
PDF
6. Conditionals I
PDF
24. Translation & Rotation II
PDF
Finalistas v
ODP
20140220pln final2
PDF
26. Images II
PPT
Evaluation 4
PPTX
Executive Certificate in Public Procurement
PDF
15. Final Project - Iteration 1
Power point de Educación Física (Tennis)
αναστάσιμα έθιμα ανά την ελλάδα
Wc unit 3 work place commuication
Sochi
9. Loops II
A. Design Thinking Lecture
20. Mathematics I
Socialmedia_Mitchell
2. Processing
12. Objects I
3. Final Project - Intro
MoretonSmith Receivables Management Intro
6. Conditionals I
24. Translation & Rotation II
Finalistas v
20140220pln final2
26. Images II
Evaluation 4
Executive Certificate in Public Procurement
15. Final Project - Iteration 1
Ad

Similar to 10. Function I (20)

PDF
4. Interaction
PDF
Functions
PPT
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
PPT
Chapter Introduction to Modular Programming.ppt
PDF
11. Functions II
PPTX
Function in c++
PPTX
Functions
PPTX
FUNCTION CPU
PDF
Functions in C++.pdf
PPTX
Unit 7. Functions
PDF
Functions-Computer programming
PPTX
Functions in programing how functions work
PPT
Chapter 1.ppt
PDF
PSPC-UNIT-4.pdf
PPTX
Function
PPT
Part 3-functions
PPTX
L22- L23-Modular programmingpsucmit.pptx
PPTX
Function
PPTX
CH.4FUNCTIONS IN C (1).pptx
PPT
Lecture 11 - Functions
4. Interaction
Functions
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
Chapter Introduction to Modular Programming.ppt
11. Functions II
Function in c++
Functions
FUNCTION CPU
Functions in C++.pdf
Unit 7. Functions
Functions-Computer programming
Functions in programing how functions work
Chapter 1.ppt
PSPC-UNIT-4.pdf
Function
Part 3-functions
L22- L23-Modular programmingpsucmit.pptx
Function
CH.4FUNCTIONS IN C (1).pptx
Lecture 11 - Functions

More from Joseph Murphy (18)

PDF
33. Input II
PDF
32. Input I
PDF
30. Text II
PDF
29. Text I
PDF
28. Video II
PDF
27. Video I
PDF
25. Images I
PDF
23. Final Project Iteration II
PDF
34. Final Project Iteration 3
PDF
22. Translation & Rotation I
PDF
21. Mathematics II
PDF
19. Algorithms II
PDF
18. Algorithms
PDF
14. Arrays I
PDF
13. Objects II
PDF
8. Loops I
PDF
7. Conditionals II
PDF
5. Variables
33. Input II
32. Input I
30. Text II
29. Text I
28. Video II
27. Video I
25. Images I
23. Final Project Iteration II
34. Final Project Iteration 3
22. Translation & Rotation I
21. Mathematics II
19. Algorithms II
18. Algorithms
14. Arrays I
13. Objects II
8. Loops I
7. Conditionals II
5. Variables

Recently uploaded (20)

PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PPTX
Module on health assessment of CHN. pptx
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PPTX
What’s under the hood: Parsing standardized learning content for AI
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PPTX
Computer Architecture Input Output Memory.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
English Textual Question & Ans (12th Class).pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
PPTX
Education and Perspectives of Education.pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Hazard Identification & Risk Assessment .pdf
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Race Reva University – Shaping Future Leaders in Artificial Intelligence
Cambridge-Practice-Tests-for-IELTS-12.docx
Module on health assessment of CHN. pptx
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Core Concepts of Personalized Learning and Virtual Learning Environments
What’s under the hood: Parsing standardized learning content for AI
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
Computer Architecture Input Output Memory.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
English Textual Question & Ans (12th Class).pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
Education and Perspectives of Education.pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Hazard Identification & Risk Assessment .pdf

10. Function I