
class lineDemo extends demoBase {
  PShape boxi;
PShape globe;
float zDimension = 0;
Boolean forward;

ArrayList<Integer> listOfLines;
int colorChange = 0;
int RGBSwitch = 0;
int x = -990;
int y = 0;
int x2 = 990;
int y2 = 0;
int x3 = 150;
int x4 = -150;
  
  float startTime;
  SoundFile sample;
  
  public lineDemo(SoundFile sample) {
    zDimension=1000;
  forward = true;
    startTime = -1;
    this.sample = sample;
  }
  void playDemo() {
    if(startTime == -1) {
      startTime = millis()/1000.0;
      sample.loop();
    }
 background(255);
  noFill();
  
  println(colorChange + " " + forward + " " + RGBSwitch);
  if (colorChange < 255 && forward && RGBSwitch == 0) {
    stroke(min(colorChange,255),0,0);
    colorChange = colorChange + 5;
    if (colorChange == 255 || colorChange == 250)
      RGBSwitch = 1;
  } else if (colorChange <= 255 && forward && RGBSwitch == 1) {
    stroke(0,min(colorChange,255),0);
    colorChange = colorChange - 5;
    if (colorChange == 0)
      RGBSwitch = 2;
  } else if (colorChange < 255 && forward && RGBSwitch == 2) {
    stroke(0,0,min(colorChange,255));
    colorChange = colorChange + 5;
    if (colorChange == 250 || colorChange == 250)
      RGBSwitch = 0;
  } else {
    
  }
  
  translate(width/2, height/2);
  for (int i = 0; i < 35; i++) {  
    fill(i * 150/35);
    line(x+i,y+100*i,x2-i,y2-100*i); 
    line(x+i,y-100*i,x2-i,y2+100*i); 
  }
  
  stroke(255,0,0);
  strokeWeight(5);
  float seconds = millis() / 1000.0 - startTime;

  if(forward){
    x3+= 1 + 5.9*seconds;
    x4-= 1 + 5.9*seconds;

    line(x3,2000,x3,-2000);
    line(x4,2000,x4,-2000);
    
  }
  else{
    x3-= 1 + 5.9*seconds;
    x4+= 1 + 5.9*seconds;
    line(x3,2000,x3,-2000);
    line(x4,2000,x4,-2000);

  }
  
  if (x3 > 800 && forward) {
    forward = false; 
  } 
  else {
    if(x3 < 0 && !forward){
      x3-= 1 + 1.9*seconds;
      x4+= 1 + 1.9*seconds;
      line(x3,2000,x3,-2000);
      line(x4,2000,x4,-2000);
      forward = true;
    }
  }
  }
  
  boolean isOver(){
    boolean result = false;
    if(millis()/1000.0 - startTime > 7) {
      sample.stop();
      result = true;
    }
    return result;
  }
  
}