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 />

220<br />

I need a fourth vertex() call to generate another line:<br />

size(300, 300);<br />

background(255);<br />

beginShape(LINES);<br />

vertex(20, height/2);<br />

vertex(width-20, height/2);<br />

vertex(width/2, height-20);<br />

vertex(width/2, 20);<br />

endShape();<br />

This mode isn’t much of an improvement over just calling two line() functions. The following<br />

code, for example, gives the exact same output as the last, but in four lines rather<br />

than eight:<br />

size(300, 300);<br />

background(255);<br />

line(20, height/2, width-20, height/2);<br />

line(width/2, height-20, width/2, 20);<br />

Creating line strips<br />

The situation, however, changes once you try to generate a line strip, which uses a noargument<br />

version of beginShape(). By default, beginShape() creates an open <strong>and</strong> filled<br />

path. You need to call noFill() if you want to generate an unfilled line strip. For example,<br />

the next sketch, shown in Figure 6-35, fills the display window with r<strong>and</strong>om vertices all<br />

connected by a continuous path. If you used the line() function, you would need to keep<br />

feeding previous second point positions into the next line call. I implemented this<br />

approach as a comparison, which I think you’ll agree is a much less elegant solution.<br />

// elegant vertex() appraoch<br />

size(300, 300);<br />

background(255);<br />

strokeWeight(3);<br />

noFill();<br />

smooth();<br />

beginShape();<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!