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-11. Curves simulating a fountain<br />

Creating curves using trig<br />

Another relatively easy way to generate a curve is to utilize a trig function. Sine <strong>and</strong> cosine<br />

functions both generate a repeating periodic wave. Here’s a simple example (shown in<br />

Figure 7-12):<br />

//trig wave<br />

size(400, 200);<br />

background(0);<br />

stroke(255);<br />

float angle = 0;<br />

float amplitude = 10;<br />

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

float xSpeed = 1;<br />

float frequency = 3.0;<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!