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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6 <strong>Learning</strong> <strong>Processing</strong><br />

Once we arrive at drawing a rectangle, things become a bit more complicated. In <strong>Processing</strong> , a rectangle is<br />

specifi ed by the coordinate for the <strong>to</strong>p left corner of the rectangle, as well as its width and height<br />

(see Figure 1.7 ).<br />

Top left<br />

x-axis<br />

0 1 2 3 4 5 6 7 8 9<br />

0<br />

1<br />

2<br />

3<br />

width height<br />

y-axis<br />

4<br />

5<br />

height<br />

rect (2,3,5,4);<br />

6<br />

7<br />

8<br />

9<br />

<strong>to</strong>p left<br />

x<br />

<strong>to</strong>p left<br />

y<br />

fi g. 1.7<br />

0<br />

1<br />

2<br />

3<br />

4<br />

y-axis<br />

5<br />

6<br />

7<br />

8<br />

9<br />

fi g. 1.8<br />

width<br />

However, a second way <strong>to</strong> draw a rectangle involves specifying the centerpoint, along with width<br />

and height as shown in Figure 1.8 . If we prefer this method, we fi rst indicate that we want <strong>to</strong> use the<br />

“ CENTER ” mode before the instruction for the rectangle itself. Note that <strong>Processing</strong> is case-sensitive.<br />

Incidentally, the default mode is “ CORNER, ” which is how we began as illustrated in Figure 1.7 .<br />

0 1 2 3 4<br />

x-axis<br />

5 6 7 8 9<br />

center<br />

(3,3)<br />

rectMode (CENTER);<br />

rect (3,3,5,5);<br />

height<br />

width<br />

Finally, we can also draw a rectangle with two points (the <strong>to</strong>p left corner and the bot<strong>to</strong>m right corner).<br />

Th e mode here is “ CORNERS ” (see Figure 1.9) .<br />

center<br />

x<br />

center<br />

y

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

Saved successfully!

Ooh no, something went wrong!