> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.QlJ056WQBQ8/rev.914
 * 
 * authors: 
 *   Philip
 *   Carson
 *   
 *   
 *   
 *   Philip

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



int xspacing = 18;   // How far apart should each dot be spaced
int w;              // Width of entire wave

float theta = 0.4;  // Start angle at 0
float amplitude = 150.0;  // Height of wave
float period = 500.0;  // How many pixels before the wave repeats
float dx;  // Value for incrementing X, a function of period and xspacing
float[] yvalues;  // Using an array to store height values for the wave

int red_value = 0;
int blue_value = 0;

void setup() {
  size(800, 500);
  background(0); //erase the canvas by setting it to black

  w = width+16; //the width of the canvas (640) + some padding
  dx = (TWO_PI / period) * xspacing;
  yvalues = new float[w/xspacing]; // x/xpacing == number of dots
}

void draw() {
  //background(0); //erase the canvas by setting it to black
  calcWave(); //calculate updated positions
  renderWave(); //draw it
}

void calcWave() {
  // Increment theta (try different values for 'angular velocity' here
  theta += 0.2;

  // For every x value, calculate a y value with sine function
  float x = theta;
  for (int i = 0; i < yvalues.length; i++) {
    yvalues[i] = tan(5*x)*amplitude;
    x+=dx;
  }
}

boolean red_going_up = true;
boolean blue_going_up = true;

void renderWave() {
  noStroke(); //don't draw outlines aronud the ellipses

    if (red_going_up && red_value>=255)
        red_going_up = false;
    if (!red_going_up && red_value<=0)
        red_going_up = true;
        
    if  (red_going_up)
        red_value += 3;
    else
        red_value -= 3;
        
    if (blue_going_up && blue_value>=255)
        blue_going_up = false
    if (!blue_going_up && blue_value<=0)
        blue_going_up = true
        
    if (blue_going_up)
        blue_value += 2
    else
        blue_value -=2;

  fill(color(0, red_value, blue_value)); //set the fill color to white
  // A simple way to draw the wave with an ellipse at each location
  for (int x = 0; x < yvalues.length; x++) {
    rect(x*xspacing, height/2+yvalues[x], 16, 16);
  }
}