9 Functions and Periodic Motion

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 size(), print(), and 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. ...

Get Learn Python Visually now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.