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

256<br />

Figure 7-12. Creating simple curves with trigonometry<br />

The sin() <strong>and</strong> cos() functions are controlled by the incrementation of the angle (frequency)<br />

<strong>and</strong> the value of the amplitude. Try changing these variables to see how the plots<br />

are affected. You can also use a damping variable (which acts like gravity in the particle<br />

example) to decrease the amplitude of the trig functions over time. Here’s an example of<br />

this (see Figure 7-13):<br />

//waves with damping<br />

size(400, 200);<br />

background(0);<br />

stroke(255);<br />

float angle = 0;<br />

float amplitude = 30;<br />

float x = 0, y = 0;<br />

float xSpeed = 1;<br />

float frequency = 6.0;<br />

float damping = .994;<br />

strokeWeight(3);<br />

smooth();<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!