// Cos Wave int xspacing = 8; // How far apart should each horizontal location be spaced int w; // Width of entire wave float theta = 0.5f; // Start angle at 0.5 float amplitude = 75.0f; // Height of wave float period = 200.0f; // How many pixels before the wave repeats float dx; // Value for incrementing X, to be calculated as a function of period and xspacing float[] yvalues; // Using an array to store height values for the wave (not entirely necessary) void setup() { size(200,200); framerate(30); colorMode(RGB,25,255,55,100); smooth(); w = width; dx = (TWO_PI / period) * xspacing-500; yvalues = new float[w/xspacing]; } void draw() { background(100); calcWave(); renderWave(); } void calcWave() { // Increment theta (try different values for 'angular velocity' here theta += 0.08; // For every x value, calculate a y value with sine function float x = theta; for (int i = 0; i < yvalues.length; i++) { yvalues[i] = cos(x)*amplitude/4; x+=dx; } } void renderWave() { // A simple way to draw the wave with an ellipse at each location for (int x = 0; x < yvalues.length; x++) { noStroke(); fill(225,10,67); ellipseMode(CENTER); ellipse(x*xspacing,width-20+yvalues[x],2,20); fill(225,20,80); ellipseMode(CENTER); ellipse(x*xspacing,width-40+yvalues[x],4,40); fill(255,30,120); ellipseMode(CENTER); ellipse(x*xspacing,width-60+yvalues[x],6,60); fill(255,40,10); ellipseMode(CENTER); ellipse(x*xspacing,width-80+yvalues[x],8,80); fill(255,50); ellipseMode(CENTER); ellipse(x*xspacing,width-100+yvalues[x],10,50); fill(255,60); ellipseMode(CENTER); ellipse(x*xspacing,width-120+yvalues[x],12,112); } }