5

Enter the Matrix

You’ve created a number of wonderful things from shapes and lines, and even moved shapes around using an if() statement. Now I’ll cover how to combine the concepts you’ve learned to create images and transform all the pieces of your sketch at once, rather than transforming individual shapes.

WHAT IS A MATRIX?

When you create individual shapes with Processing, you’re actually placing them on a matrix. In simple Processing projects, you can think of a matrix as a way to group a lot of shapes and treat them as a single object. It’s a bit like drawing on a piece of paper: if you wanted to move the picture, you could erase it and redraw it—or you could simply move the whole piece of paper.

Without a matrix, you’d have to move every ...

Get The SparkFun Guide to Processing 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.