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.

228 <strong>Learning</strong> <strong>Processing</strong><br />

Is this rectangle fl ying off of the computer screen about <strong>to</strong> bump in<strong>to</strong> your nose? Technically, this is<br />

of course not the case. It is simply a rectangle growing in size. But we have created the illusion of the<br />

rectangle moving <strong>to</strong>ward you.<br />

Fortunately for us, if we choose <strong>to</strong> use 3D coordinates, <strong>Processing</strong> will create the illusion for us. While the<br />

idea of a third dimension on a fl at computer moni<strong>to</strong>r may seem imaginary, it is quite real for <strong>Processing</strong>.<br />

<strong>Processing</strong> knows about perspective, and selects the appropriate two-dimensional pixels in order <strong>to</strong> create<br />

the three-dimensional eff ect. We should recognize, however, that as soon as we enter the world of 3D<br />

pixel coordinates, a certain amount of control must be relinquished <strong>to</strong> the <strong>Processing</strong> renderer. You can no<br />

longer control exact pixel locations as you might with 2D shapes, because XY locations will be adjusted <strong>to</strong><br />

account for 3D perspective.<br />

In order <strong>to</strong> specify points in three dimensions, the coordinates are specifi ed in the order you would expect:<br />

x , y , z . Cartesian 3D systems can be described as “ left-handed ” or “ right-handed. ” If you use your right<br />

hand <strong>to</strong> point your index fi nger in the positive y direction (up) and your thumb in the positive x direction<br />

(<strong>to</strong> the right), the rest of your fi ngers will point <strong>to</strong>ward the positive z direction. It is left-handed if you use<br />

your left hand and do the same. In <strong>Processing</strong>, the system is left-handed, as shown in Figure 14.2 .<br />

+X<br />

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

+Y<br />

fi g. 14.2<br />

Our fi rst goal is <strong>to</strong> rewrite Example 14-1 using the 3D capabilities of <strong>Processing</strong>. Assume the following<br />

variables:<br />

int x = width/2;<br />

int y = height/2;<br />

int z = 0;<br />

int r = 10;<br />

In order <strong>to</strong> specify the location for a rectangle, the rect( ) function takes four arguments: an x location,<br />

a y location, a width, and a height.<br />

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

+Y<br />

–Z<br />

+X

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

Saved successfully!

Ooh no, something went wrong!