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

294<br />

same basic code in two different places in the sketch. When a user clicks, setEllipse()<br />

is called, passing in a bunch of r<strong>and</strong>om values: setEllipse(int(r<strong>and</strong>om(3, 36)),<br />

r<strong>and</strong>om(-200, 300), r<strong>and</strong>om(-200, 300));.<br />

The drawEllipse() function is called each frame from the draw() function. You’ll be using<br />

draw() extensively a little later in the book. draw() is used for animation, <strong>and</strong> by including<br />

it, <strong>Processing</strong> continually redraws the screen (by default) around 60 frames per second.<br />

You can update values within draw(), as I’m doing by repeatedly calling drawEllipse().<br />

Also notice that the first line in the draw() structure is a background(145) call. If I don’t<br />

include this, the screen will not be cleared between draw loops, <strong>and</strong> changes to the curve<br />

plot will build up on the screen. This could be used to very good effect, so you might want<br />

to try commenting out the background(145) call. Then run the sketch <strong>and</strong> click the screen<br />

repeatedly. Figure 7-36 shows a screenshot of my attempt.<br />

Figure 7-36. Bézier Ellipse sketch, example 3

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

Saved successfully!

Ooh no, something went wrong!