/* The PerlinWave is modelled on our previous Wave class. It makes use of amplitude, period, spacing and width like the previous wave class. */ class PerlinWave { // The horizontal spacing and size of our wave int xspacing; int waveWidth; // Variables for calculating the shape of our wave float yoff; float amplitude; float period; float dx; // storage for our wave samples float[] yvalues; // Constructor for a new wave, using Amplitude, spacing, width and period PerlinWave(float amp_, int xspace, int width_, float period_) { // store our properties and calculate any values we may need amplitude = amp_; xspacing = xspace; waveWidth = width_; period = period_; dx = (1.0f / period) * xspacing; yvalues = new float[waveWidth / xspacing]; } void calcWave() { // shift the starting point of our noise yoff += 0.01; // recalculate the shape of the noise wave at each sample point float x = yoff; for (int i = 0; i < yvalues.length; i++) { // get a value bewtween -1 and 1 from our noise function float n = 2 * noise(x) - 1.0f; // apply the amplitude and store the vaule yvalues[i] = n * amplitude; x += dx; } } // draw our sample points from the wave void render() { smooth(); for (int x = 0; x < yvalues.length; x++) { noStroke(); fill(32, 64, 128, 50); ellipseMode(CENTER); ellipse(x * xspacing, yvalues[x], 16, 16); } } float[] getValues() { return yvalues; } }