06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Mathematics 209<br />

How quickly we increment t also aff ects the smoothness of the noise. Try running the code several times,<br />

incrementing t by 0.01, 0.02, 0.05, 0.1, 0.0001, and so on.<br />

By now, you may have noticed that noise( ) always returns a fl oating point value between 0 and 1. Th is<br />

detail cannot be overlooked, as it aff ects how we use Perlin noise in a <strong>Processing</strong> sketch. Example 13-4<br />

assigns the result of the noise( ) function <strong>to</strong> the size of a circle. Th e noise value is scaled by multiplying<br />

by the width of the window. If the width is 200, and the range of noise( ) is between 0.0 and 1.0, the<br />

range of noise( ) multiplied by the width is 0.0 <strong>to</strong> 200.0. Th is is illustrated by the table below and by<br />

Example 13-4 .<br />

Example 13-4: Perlin noise<br />

float time = 0.0;<br />

float increment = 0.01;<br />

void setup() {<br />

size(200,200);<br />

smooth(); {<br />

void draw() {<br />

background(255);<br />

float n = noise(time)*width;<br />

Noise Value Multiplied by Equals<br />

0 200 0<br />

0.12 200 24<br />

0.57 200 114<br />

0.89 200 178<br />

1 200 200<br />

// With each cycle, increment the "time"<br />

time + = increment;<br />

Get a noise value at “time” and scale<br />

it according <strong>to</strong> the window’s width.<br />

// Draw the ellipse with size determined by Perlin noise<br />

fill(0);<br />

ellipse(width/2,height/2,n,n);<br />

}<br />

fi g. 13.4

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

Saved successfully!

Ooh no, something went wrong!