programming for artists and designers: week 3
TRANSCRIPT
Week 2: Functions
Runs once
Runs overand over
Runs each time you click
the mouse
A Brief Detour: Mouse and Key Presses
Runs once
Runs overand 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 doesthe 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 thingin slightly different ways
Both circles look the same, but behave
differently
Functions:Why do I care?
If you changethe function code,
you change howthe circles look
without changingtheir behavior
Functions:Why do I care?
make a different shape here
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…
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);}
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)
functioncode
function name
YOU CAN USEOTHER PEOPLE’S
FUNCTIONS
Functions:Why do I care?