As your programs grow more complex, your line counts will increase, and you’ll begin repeating the same or similar code. By using functions, you can divide your programs into named blocks of reusable code. This makes your code more modular, allowing you to reuse lines without needing to rewrite them.
You’ve already used many Processing functions, like
rect(), and in this chapter, you’ll learn how to define your own functions. As an example, Processing has no function for drawing diamonds, but you can create one. You decide what to name this function and what arguments it will accept. ...