CMPT 166 Lecture Notes - Lecture 16: Global Variable, Local Variable, Ellipse
Document Summary
In these notes you will learn: the terminology for describing and using functions in processing, how to write a variety of simple functions in processing, what a void function is, the difference between local and global variables. You are no doubt familiar with functions from mathematics. Functions in processing are, essentially, a more general-purpose version of mathematical functions. They have many similarities, but also some important differences. In mathematics, a function is a rule that pairs an input value with an output value. For example, in math we can define a function ff like this: f(x)=x2f(x)=x2. This function is named f, and it takes a single number as input called xx. For example, f(5)=5 5=25f(5)=5 5=25, and we would say that f(5)f(5) evaluates to 25. We can also use it within expressions, such as 2+3f(2)2+3f(2), which evaluates to 14. Now lets write the equivalent of ff in processing: float f(float x) return x * x;