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.

Accessing time<br />

Figure 11-4. Collision Detection <strong>and</strong> Timeout sketch<br />

The last sketch combined stuff you’ve looked at before. The collision detection block<br />

worked identically to the previous single-object example, only of course using arrays <strong>and</strong> a<br />

for loop. I did throw in two new function calls: millis() <strong>and</strong> noLoop().<br />

millis() returns the number of milliseconds that have elapsed since the sketch began<br />

running. In addition to returning milliseconds, <strong>Processing</strong> can also communicate with your<br />

computer’s internal clock, accessing the current time with the six functions second(),<br />

minute(), hour(), day(), month(), <strong>and</strong> year().<br />

<strong>Processing</strong>’s noLoop() function immediately stops the draw() structure from looping.<br />

There is also a companion loop() call that begins the draw() loop again. In the example, I<br />

compared the total elapsed milliseconds with a user-defined variable, timeLimit, allowing<br />

the draw() function to eventually stop after a certain amount of time had elapsed.<br />

Adding some simple fading<br />

The final modification I’ll make to the multirectangle sketch is the addition of a fade to the<br />

white background, creating the illusion of some blur trails for the rectangles (shown in<br />

Figure 11-5). The code should remain the same as in the last sketch, with the exception of<br />

the replacement of the first line in the draw() function:<br />

background(255);<br />

MOTION<br />

491<br />

11

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

Saved successfully!

Ooh no, something went wrong!