/** In this example we'll create basic perlin noise in 2 dimensions, using the X and Y coordinates of our screen to generate and display the noise */ // How much should we change our noise creation value at each step float noiseDelta = 0.02; // what is the starting point for the noise float noiseStep = 0.0; void setup() { // setup the environment size(200, 200); } void draw() { // clear our background background(0); /* We'll be doing some fairly heavy work with the pixels on the screen, and using the getPixel and setPixel functions adds some overhead to what we're doing. We're sacrificing some of the safety of the get/set methods for speed here. We'll need to use the loadPixels() and updatePixels() methods to tell Processing that we want to work with the actual array of pixels on screen. */ // fill the pixels[] array loadPixels(); // define the value we'll use for the X component of noise float xval = noiseStep; for (int x = 0; x < width; x++) { // increment our x noise value at each step xval += noiseDelta; // define the value we'll use for the Y component of noise float yval = noiseStep; for (int y = 0; y < height; y++) { // increment the y noise value at each step yval += noiseDelta; /* call the 2D noise method with our X and Y noise values. This returns a value between 0.0 and 1.0, which we'll scale by 255 to get a pixel color */ float colorVal = noise(xval, yval) * 255.0; // set the pixel on screen. In the pixel array we access a pixel // at X Y by with the formula (x + y * width) pixels[x + y * width] = color(colorVal, colorVal, colorVal); } } // Try different values here and see what happens. noiseStep += 0.0; // draw the pixels[] array to the screen updatePixels(); }