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

218<br />

Figure 6-34. Scribble Plotter sketch<br />

There’s nothing new in this sketch. However, there are a few details that might need a little<br />

clarification. The two constant variables SCRIBBLE <strong>and</strong> HATCHING have global scope since I<br />

declared them at the top of the program.<br />

int SCRIBBLE = 0;<br />

int HATCHING = 1;<br />

I passed them in as arguments from the makeRect() function to the scribble() function.<br />

They are capitalized, denoting that they are constants <strong>and</strong> should not be assigned a new<br />

value. If I really wanted to enforce that they shouldn’t be changed, I could have prefaced<br />

the declaration statements with the word final, as in final int HATCHING = 1. final is<br />

technically a Java keyword—it’s not within the <strong>Processing</strong> API—but it can be used within<br />

<strong>Processing</strong>. If you exp<strong>and</strong> upon this sketch (which I hope you do), <strong>and</strong> want to add another<br />

scribble-style algorithm, then create a new constant, pass it as an argument, <strong>and</strong> detect for<br />

it in the scribble() function.<br />

Hopefully you can make some sense of the scribble() function. I’m dividing up the x <strong>and</strong><br />

y distances between the starting <strong>and</strong> ending points (passed into the function), <strong>and</strong> then<br />

plotting lines to those intermediate positions. The r<strong>and</strong>om() function just jitters the placement<br />

of the line vertices. The SCRIBBLE style requires an extra line of code to ensure that<br />

the final line connects back to the original point. Try commenting out the line() function<br />

call within the else block inside the scribble function() conditional block.

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

Saved successfully!

Ooh no, something went wrong!