O'Reilly logo

Mastering openFrameworks: Creative Coding Demystified by Denis Perevalov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the ofNoise() function

openFrameworks has a built-in implementation of simplex noise, implemented in the ofNoise( t ) function. For example, the following code draws the Perlin noise function, ofNoise( t ), for t ranging from 0 to 10 on the screen:

ofSetColor( 0, 0, 0 );	
for (int x=0; x<1000; x++) {
  float t = x * 0.01;
  float y = ofNoise( t );
  ofLine( x, 300, x, 300 - y * 300 );
}

Note

This is the example 13-PerlinNoise/01-PerlinGraph.

Run the code and you will see the following graph:

Using the ofNoise() function

Now replace the line float y = ofNoise( t ); with the following line:

float y = ofNoise( t + 493.0 );

This code renders the noise function in the range [443, 453]. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required