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.

void setup(){<br />

size(400, 400);<br />

background(255);<br />

strokeWeight(10);<br />

fill(127);<br />

rect(100, 50, 200, 300);<br />

}<br />

Figure 9-1. <strong>Processing</strong>’s rect() function<br />

The shape functions in <strong>Processing</strong> rely on a drawing mode variable for defining their<br />

origin—the point from which the shapes are drawn. The default origin point for a rectangle<br />

is the top-left corner, while for an ellipse it’s the center. However, you can easily<br />

change these by calling rectMode() or ellipseMode() before calling the rect() or<br />

ellipse() function, respectively. This next example (shown in Figure 9-2) draws three rectangles<br />

utilizing three different drawing modes: rectMode(CORNER), rectMode(CENTER),<br />

<strong>and</strong> rectMode(CORNERS).<br />

void setup(){<br />

size(400, 400);<br />

background(255);<br />

strokeWeight(10);<br />

fill(127);<br />

rect(103, 120, 130, 100);<br />

rectMode(CENTER);<br />

rect(103, 120, 130, 100);<br />

rectMode(CORNERS);<br />

rect(233, 220, 363, 320);<br />

}<br />

SHAPES<br />

341<br />

9

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

Saved successfully!

Ooh no, something went wrong!