SlideShare una empresa de Scribd logo
1 de 13
Week 2: Functions
Runs once Runs over and over Runs each  time you click the mouse A Brief Detour: Mouse and Key Presses
Runs once Runs over and over A Brief Detour: Mouse and Key Presses Try replacing  mousePressed () with: keyPressed () mouseReleased () mouseDragged () How are these different?
Functions (you should know what this does)
Functions This does the same thing… but with more lines! Why do I care?
Anatomy of a Function (similar words: method, subroutine) void  renderCircle(){ fill (200); ellipse (x,y,100,100); } what’s this? what’s this? function code function name
Do the same thing in slightly different ways Both circles look the same, but behave differently Functions: Why do I care?
If you change the function code, you change how the circles look without changing their behavior Functions: Why do I care? make a different shape here
Sometimes it’s just neater and easier to read Functions: Why do I care? Blahblahblah make 6 ellipses in three alternating colors and enclose them in a rectangle  that has a randomly changing color and put a line through it all…
Anatomy of a Function what’s this? parameters (TYPE and NAME) function code function name void  renderCircle( int  _x,  int  _y){ fill (200); ellipse (_x,_y,100,100); }
You can use a function to ask a question and receive an answer Functions: Why do I care?
boolean  inCircle( int  _x,  int  _y){ if ( sq (_x-x) +  sq (_y-y) <  sq (50))  return   true ; else   return   false ; } Anatomy of a Function data return type parameters (TYPE and NAME) function code function name
YOU CAN USE OTHER PEOPLE’S FUNCTIONS Functions: Why do I care?

Más contenido relacionado

La actualidad más candente

La actualidad más candente (13)

Python programming lab3 250215
Python programming lab3 250215Python programming lab3 250215
Python programming lab3 250215
 
Sequence Types in Python Programming
Sequence Types in Python ProgrammingSequence Types in Python Programming
Sequence Types in Python Programming
 
Sqlalchemy lightning talk
Sqlalchemy lightning talkSqlalchemy lightning talk
Sqlalchemy lightning talk
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Functional programming with haskell
Functional programming with haskellFunctional programming with haskell
Functional programming with haskell
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
Tutorial matlab
Tutorial matlabTutorial matlab
Tutorial matlab
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and Cats
 
[1062BPY12001] Data analysis with R / week 3
[1062BPY12001] Data analysis with R / week 3[1062BPY12001] Data analysis with R / week 3
[1062BPY12001] Data analysis with R / week 3
 
Sql
SqlSql
Sql
 
The Ring programming language version 1.5.2 book - Part 18 of 181
The Ring programming language version 1.5.2 book - Part 18 of 181The Ring programming language version 1.5.2 book - Part 18 of 181
The Ring programming language version 1.5.2 book - Part 18 of 181
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 

Similar a Programming for Artists and Designers: Week 3

Mdx Basics
Mdx BasicsMdx Basics
Mdx Basics
ALIPPHAR
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
Vivek Singh
 
Notes5
Notes5Notes5
Notes5
hccit
 
Lab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptxLab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptx
meharikiros2
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
Bryan O'Sullivan
 
Notes2
Notes2Notes2
Notes2
hccit
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
Taisuke Oe
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdf
SALES97
 
Excel Useful Tips
Excel Useful TipsExcel Useful Tips
Excel Useful Tips
Parul_100in
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 

Similar a Programming for Artists and Designers: Week 3 (20)

Mdx Basics
Mdx BasicsMdx Basics
Mdx Basics
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
 
Notes5
Notes5Notes5
Notes5
 
Functional programming and Elm
Functional programming and ElmFunctional programming and Elm
Functional programming and Elm
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scala
 
Living in the ES6 Future, Today
Living in the ES6 Future, TodayLiving in the ES6 Future, Today
Living in the ES6 Future, Today
 
Lab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptxLab Session for sql programming language 1.pptx
Lab Session for sql programming language 1.pptx
 
7 Habits For a More Functional Swift
7 Habits For a More Functional Swift7 Habits For a More Functional Swift
7 Habits For a More Functional Swift
 
Ms excel
Ms excelMs excel
Ms excel
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
 
Getting functional with elixir
Getting functional with elixirGetting functional with elixir
Getting functional with elixir
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 
Notes2
Notes2Notes2
Notes2
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdf
 
Excel Useful Tips
Excel Useful TipsExcel Useful Tips
Excel Useful Tips
 
Lecture 02 visualization and programming
Lecture 02   visualization and programmingLecture 02   visualization and programming
Lecture 02 visualization and programming
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 

Más de Tinker London (9)

Homesense @ La Cantine
Homesense @ La CantineHomesense @ La Cantine
Homesense @ La Cantine
 
Arduino Power
Arduino PowerArduino Power
Arduino Power
 
XBee and RFID
XBee and RFIDXBee and RFID
XBee and RFID
 
Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2Programming for Artists and Designers: Week 2
Programming for Artists and Designers: Week 2
 
Programming for Artists and Designers: Week 1
Programming for Artists and Designers: Week 1Programming for Artists and Designers: Week 1
Programming for Artists and Designers: Week 1
 
Playful
PlayfulPlayful
Playful
 
Mobile Games and Hardware Hacking
Mobile Games and Hardware HackingMobile Games and Hardware Hacking
Mobile Games and Hardware Hacking
 
Arduino and Open Hardware
Arduino and Open HardwareArduino and Open Hardware
Arduino and Open Hardware
 
Ethernet Shield
Ethernet ShieldEthernet Shield
Ethernet Shield
 

Programming for Artists and Designers: Week 3

  • 2. Runs once Runs over and over Runs each time you click the mouse A Brief Detour: Mouse and Key Presses
  • 3. Runs once Runs over and over A Brief Detour: Mouse and Key Presses Try replacing mousePressed () with: keyPressed () mouseReleased () mouseDragged () How are these different?
  • 4. Functions (you should know what this does)
  • 5. Functions This does the same thing… but with more lines! Why do I care?
  • 6. Anatomy of a Function (similar words: method, subroutine) void renderCircle(){ fill (200); ellipse (x,y,100,100); } what’s this? what’s this? function code function name
  • 7. Do the same thing in slightly different ways Both circles look the same, but behave differently Functions: Why do I care?
  • 8. If you change the function code, you change how the circles look without changing their behavior Functions: Why do I care? make a different shape here
  • 9. Sometimes it’s just neater and easier to read Functions: Why do I care? Blahblahblah make 6 ellipses in three alternating colors and enclose them in a rectangle that has a randomly changing color and put a line through it all…
  • 10. Anatomy of a Function what’s this? parameters (TYPE and NAME) function code function name void renderCircle( int _x, int _y){ fill (200); ellipse (_x,_y,100,100); }
  • 11. You can use a function to ask a question and receive an answer Functions: Why do I care?
  • 12. boolean inCircle( int _x, int _y){ if ( sq (_x-x) + sq (_y-y) < sq (50)) return true ; else return false ; } Anatomy of a Function data return type parameters (TYPE and NAME) function code function name
  • 13. YOU CAN USE OTHER PEOPLE’S FUNCTIONS Functions: Why do I care?