/* While single wave patterns can be interesting, they are also very predictable. One variation is to 'add' waves together to create something more unpredictable. In this example we introduce a class called WaveCollection, and an altered version of our Wave class. To add waves together using our representation of a wave; each wave must have the same settings for spacing and wave width. The WaveCollection takes care of these details for us. To create a wave collection of 1 or more waves (try 3 or 4 waves to see what results), we need a WaveCollection object, and 1 or more waves to add to it. */ // We'll use two waves Wave w1, w2; // Our wave collection WaveCollection waves; void setup() { // setup the environment size(500, 250); colorMode(RGB, 255, 255, 255, 100); // Create two waves. We're using a modified wave class, so we need // three parameters for each wave; the wave type, the amplitude, // and the period of the wave w1 = new Wave(Wave.SIN, 60, 600); w2 = new Wave(Wave.COS, 20, 170); // We initialize our wavecollection with the x-spacing and // wave width we want our waves to share. waves = new WaveCollection(5, 500); // Add both of our waves to the collection waves.add(w1); waves.add(w2); } void draw() { // clear the background background(0); // ask our collection to calculate the movement of all // of the waves. We can do this instead of calling // calcWave on each individual wave waves.calcWaves(); // We can now have the collection figure out the sum // of all of the waves it contains waves.sumWaves(); // We're still adjusting the screen for the positive and // negative values of the waves. Is this better done inside // the waves collection, or the wave class? How would we // do that? translate(0, height / 2); // draw the waves waves.render(); }