06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Our fi rst instinct might be <strong>to</strong> add another argument <strong>to</strong> the rect( ) function.<br />

rect(x,y, z ,w,h);<br />

Translation and Rotation (in 3D!) 229<br />

Th e <strong>Processing</strong> reference page for rect( ) , however, does not allow for this possibility. In order <strong>to</strong> specify 3D<br />

coordinates for shapes in the <strong>Processing</strong> world, we must learn <strong>to</strong> use a new function, called translate( ) .<br />

Th e translate( ) function is not exclusive <strong>to</strong> 3D sketches, so let’s return <strong>to</strong> two dimensions <strong>to</strong> see how it<br />

works.<br />

Th e function translate( ) moves the origin point—(0,0)—relative <strong>to</strong> its previous state. We know that when<br />

a sketch fi rst starts, the origin point lives on the <strong>to</strong>p left of the window. If we were <strong>to</strong> call the function<br />

translate( ) with the arguments (50,50), the result would be as shown in Figure 14.3 .<br />

Where is the origin?<br />

(100,100)<br />

fi g. 14.3<br />

Incorrect! We cannot use an (x,y,z) coordinate in <strong>Processing</strong>’s<br />

shape functions such as rect(), ellipse(), line(), and so on.<br />

Other functions in <strong>Processing</strong> can take three arguments for<br />

x,y,z and we will see this later in the chapter.<br />

Th e “ origin ” in a <strong>Processing</strong> sketch is the point (0,0) in two dimensions or (0,0,0) in three<br />

dimensions. It is always at the <strong>to</strong>p left corner of the window unless you move it using translate( ) .<br />

(0,0)<br />

Before<br />

(50,50)<br />

⇒ translate (50,50)⇒<br />

(-50,-50) (0,0)<br />

After<br />

(50,50)<br />

You can think of it as moving a pen around the screen, where the pen indicates the origin point.<br />

In addition, the origin always resets itself back <strong>to</strong> the <strong>to</strong>p left corner at the beginning of draw( ) . Any calls<br />

<strong>to</strong> translate( ) only apply <strong>to</strong> the current cycle through the draw( ) loop. See Example 14-2.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!