> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.eq6QUCaLGpr/rev.1149
 * 
 * authors: 
 *   isjtar

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



// nocturnal landscape in czech republic. gradient function by Ira Greenberg  
// by Isjtar (2011)

// constants
//int w = 650;
//int h = 280;
int Y_AXIS = 1;
int X_AXIS = 2;
int[] lines = new int[650];
int[] templines = new int[650];
int pos;
int hi;

void setup(){
  size(650, 280);

  // create some gradients
  // background
    color b2 = color(120, 140, 140);
    color b1 = color(20, 10, 10);
    setGradient(0, 0, width, height, b1, b2, Y_AXIS);
    stroke(20, 30, 30);
    pos = 0;
    hi = height - height / 3 ;
  
    for(int i = 0; i < width; i++){
        lines[i] = hi;
        line(i, lines[i], i, height);
        hi = hi + random(-2, 2);
    }
}


void draw(){
/*     background(255);
    // setGradient(0, 0, width, height, b1, b2, Y_AXIS);
    arrayCopy(lines, 0, templines, 1, width - 1);
    //templines[0] = templines[1] + random(-2, 2); 
   templines[0] = int(random(0,255));
   
   lines = templines;
  //  alert(lines);
  
    for(int i = 0; i < width; i++){
        line(i, lines[i], i, height);
    };
alert(lines);  
*/    
}


void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){
  // calculate differences between color components 
  float deltaR = red(c2)-red(c1);
  float deltaG = green(c2)-green(c1);
  float deltaB = blue(c2)-blue(c1);

  // choose axis
  if(axis == Y_AXIS){
    /*nested for loops set pixels
     in a basic table structure */
    // column
    for (int i=x; i<=(x+w); i++){
      // row
      for (int j = y; j<=(y+h); j++){
        color c = color(
        (red(c1)+(j-y)*(deltaR/h)),
        (green(c1)+(j-y)*(deltaG/h)),
        (blue(c1)+(j-y)*(deltaB/h)) 
          );
        set(i, j, c);
      }
    }  
  }  
  else if(axis == X_AXIS){
    // column 
    for (int i=y; i<=(y+h); i++){
      // row
      for (int j = x; j<=(x+w); j++){
        color c = color(
        (red(c1)+(j-x)*(deltaR/h)),
        (green(c1)+(j-x)*(deltaG/h)),
        (blue(c1)+(j-x)*(deltaB/h)) 
          );
        set(j, i, c);
      }
    }  
  }
}