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.

Figure 7-13. Damping effect on curves<br />

In the last chapter, I demonstrated a scribble function, where endpoints of a line were sent<br />

to a function that r<strong>and</strong>omly jittered points between the terminal points, creating a more<br />

organic-looking line. You can use trig functions in a similar capacity. I thought it might be<br />

interesting to put the particle effect together with the trig function to create particle<br />

waves (see Figure 7-14); it will also be a good review of using custom functions.<br />

This is a fairly complex sketch. Each part of it is encapsulated in a function, <strong>and</strong> there are<br />

no global variables. Thus, the individual functions speak to each other through function<br />

calls. I recommend playing with the sketch for a while before reviewing the code. I completely<br />

parameterized the main particle function, so it’s easy to mess with the variables<br />

in the setup() structure—seeing how the changes affect the output, as illustrated in<br />

Figure 7-15—before diving into the code guts.<br />

/*<br />

Particle Wave<br />

Ira Greenberg, December 5, 2005<br />

revised January 26, 2007<br />

*/<br />

void setup(){<br />

size(800, 400);<br />

background(0);<br />

smooth();<br />

/*lots of stuff to manipulate. I packed<br />

the arguments into arrays just to make the<br />

setParticles function argument/parameter<br />

lists less unwieldy*/<br />

//particle style<br />

/* increase strokeWt if<br />

you don't see any output*/<br />

float strokeWt = 1.5;<br />

float strokeCol= 255;<br />

float[]strokeStyle = { strokeWt, strokeCol };<br />

CURVES<br />

257<br />

7

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

Saved successfully!

Ooh no, something went wrong!