04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

110<br />

Figure 4-1. In <strong>Processing</strong>, the x-axis increases from left to right <strong>and</strong><br />

the y-axis increases from top to bottom. The origin is in the top-left<br />

corner, at (0, 0).<br />

If you draw a 40 pixel by 40 pixel rectangle on the monitor at (100, 100), it will be 100 pixels<br />

to the right of the left edge of the monitor <strong>and</strong> 100 pixels down from the top edge of<br />

the monitor. Since you can only plot a point to a specific pixel location on the screen, you<br />

also need to consider which point on the rectangle gets placed at (100, 100). This point is<br />

sometimes referred to as the registration point. In most instances, the registration point is<br />

either the top-left corner of the image or the center of the image. In <strong>Processing</strong>, there is a<br />

function named rectMode() that allows you to specify from what point a rectangle is<br />

drawn by passing different arguments to the function. For example, rectMode(CENTER)<br />

orients the rectangle at its center point, while rectMode(CORNER) uses the rectangle’s topleft<br />

corner; there is also a third argument, rectMode(CORNERS), which draws the rectangle<br />

by specifying two points: the top-left <strong>and</strong> bottom-right corners of the rectangle. In Figure<br />

4-2, the rectangle on the left is drawn from its top-left corner at (100, 100), <strong>and</strong> the one<br />

to the right is drawn from its center point.<br />

Figure 4-2. The square on the left uses its top-left corner for registration, while the one on<br />

the right uses its center point. You can explicitly set the registration point using <strong>Processing</strong>’s<br />

rectMode(MODE) comm<strong>and</strong>.

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

Saved successfully!

Ooh no, something went wrong!