programming for artists and designers: week 3

13
Week 2: Functions

Upload: tinker-london

Post on 14-Jun-2015

380 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Programming for Artists and Designers: Week 3

Week 2: Functions

Page 2: Programming for Artists and Designers: Week 3

Runs once

Runs overand over

Runs each time you click

the mouse

A Brief Detour: Mouse and Key Presses

Page 3: Programming for Artists and Designers: Week 3

Runs once

Runs overand over

A Brief Detour: Mouse and Key Presses

Try replacing mousePressed()with:

keyPressed()mouseReleased()mouseDragged()

How are these different?

Page 4: Programming for Artists and Designers: Week 3

Functions

(you should know what this does)

Page 5: Programming for Artists and Designers: Week 3

Functions

This doesthe same thing…

but with more lines!Why do I care?

Page 6: Programming for Artists and Designers: Week 3

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

Page 7: Programming for Artists and Designers: Week 3

Do the same thingin slightly different ways

Both circles look the same, but behave

differently

Functions:Why do I care?

Page 8: Programming for Artists and Designers: Week 3

If you changethe function code,

you change howthe circles look

without changingtheir behavior

Functions:Why do I care?

make a different shape here

Page 9: Programming for Artists and Designers: Week 3

Sometimes it’sjust 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…

Page 10: Programming for Artists and Designers: Week 3

Anatomy of a Function

what’s this?

parameters(TYPE and NAME)

functioncode

function name

void renderCircle(int _x, int _y){ fill(200); ellipse(_x,_y,100,100);}

Page 11: Programming for Artists and Designers: Week 3

You can use a function to ask a question

and receive an answer

Functions:Why do I care?

Page 12: Programming for Artists and Designers: Week 3

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)

functioncode

function name

Page 13: Programming for Artists and Designers: Week 3

YOU CAN USEOTHER PEOPLE’S

FUNCTIONS

Functions:Why do I care?