> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.XA$HWicP29t/rev.122
 * 
 * authors: 
 *   Heinze Havinga

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





float trianglesize =10.0;

//start position of triangles
float x;
float y;
//offset to align layer of triangles
float offset=0.0;

//color values
int redV=255;
int greenV=255;
int blueV=255;

float targetX;
float targetY;
float startX=0.0;
float startY=-2.0;

void setup() {
  //noStroke();
  size(550,500);
  noStroke();
 
  //We start with white cubes
  fill(255);
  frameRate(200);
  smooth();
  x = startX;
  y = startY;
  targetX = float(width)/trianglesize;
  targetY = float(height)/trianglesize;

}

void draw() {
  

  if(y%1.5==0){
  fill(redV,greenV,blueV);
  } else if(y%1.0==0){
      if (x%2==0) {
       fill(redV-15,greenV-15,blueV-15);
      } else{
        fill(redV-70,greenV-70,blueV-70);
      }
  }else{
      if (x%2==0) {
       fill(redV-70,greenV-70,blueV-70);
      } else{
        fill(redV-15,greenV-15,blueV-15);
      }
  }
  if (x%2==0) {
    triangle((x+offset)*trianglesize, y*trianglesize, (x+offset)*trianglesize, y*trianglesize+trianglesize, (x+offset)*trianglesize+trianglesize, y*trianglesize+(trianglesize/2));
  }
  else {
    triangle((x+offset)*trianglesize+trianglesize, y*trianglesize, (x+offset)*trianglesize+trianglesize, y*trianglesize+trianglesize, (x+offset)*trianglesize, y*trianglesize+(trianglesize/2));
  }
  x+=1.0;
  if (x>targetX) {
    x=startX;
    y+=0.5;
    if (y%1==0) {
      offset=0;
    }
    else {
      offset=-1.0;
    }

    if (y>targetY) {
    //  println(y +" "+targetY);
      targetX = round(random(2,(width/trianglesize)));
      targetY = round(random(3,(height/trianglesize)));
      
      startX = round(random(0,(targetX)));
      startY = round(random(0,(targetY)));
      
      x=startX;
      y=startY;
      
      if (y%1==0) {
      offset=0;
    }
    else {
      offset=-1.0;
    }
      
     
      //When the whole screen is filled, we fill it up with random other colors! Minimal value is 70 to prevent black sides of squares
      redV=(int)random(75,255);
      greenV=(int)random(75,255);
      blueV=(int)random(75,255);
    }
  }
}