Chapter 6. Translate, Rotate, Scale

An alternative technique for positioning and moving things on screen is to change the screen coordinate system. For example, you can move a shape 50 pixels to the right, or you can move the location of coordinate (0,0) 50 pixels to the right—the visual result on screen is the same.

By modifying the default coordinate system, we can create different transformations including translationrotation, and scaling.

Translate

Working with transformations can be tricky, but the translate() function is the most straightforward, so we’ll start with that. As Figure 6-1 shows, this function can shift the coordinate system left, right, up, and down.

Figure 6-1. Translating the coordinates

Example 6-1: Translating Location ...

Get Make: Getting Started with p5.js now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.