> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.DEWUOkcEJyr/rev.361
 * 
 * authors: 
 *   Gisela Martiz

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




var fishimages;
 
//how fish to create
var n = 10;
var  fish;
var backgroundimage;
 
void   setup() {
  size(400, 300);
   // textFont(loadFont("Courier New"), 12);
  
    frameRate(30);
 
   fishimages = [
        "http://i.imgur.com/iSxvC.gif",
        "http://i.imgur.com/mkh0q.gif",
        "http://i.imgur.com/61PDB.gif",
        "http://i.imgur.com/dx0SO.gif",
       "http://i.imgur.com/cng3H.gif",
       
        ];
   
 
    fish = new ArrayList(n);
    
    for(var i=0; i<n; i++) {
        fish[i] = new Fish();
        fish[i].x = random(width);
        fish[i].y = random(height-50);
        fish[i].speed = floor(random(-5,5));
        if (fish[i].speed == 0) fish[i].speed = 1;
        var randomurl = fishimages[floor(random(fishimages.length))];
        fish[i].fishimg = loadImage(randomurl);
    }
    
    
  backgroundimage  = loadImage("http://2.bp.blogspot.com/_XdgS9g4KjmM/SJphOb5ACQI/AAAAAAAAB4s/Qs61CByQ8tI/s400/Under+da+Sea.jpg");
  
  
}
 
 
void   draw() {
   
    image(backgroundimage,  0, 0);
  
    for (var i=0; i<n; i++) {
        fish[i].draw();
        fish[i].move();
    }
    
}
 
 
function Fish(x, y, speed, img) {
    this.x = x;
    this.y = y;
    this.speed = speed;
    this.fishimg = null;
    this.lastime = millis();
 
    this.draw = function() {
        pushStyle();
        //pushMatrix();
        if (this.speed < 0) {
            scale(-1.0,1.0);
            translate(-1 * this.fishimg.width, 0);
            image(this.fishimg, -1*this.x, this.y);
        } else {
           image(this.fishimg, this.x, this.y);
        }
        //popMatrix();
        popStyle();
    }
    
    this.move = function() {
        this.x += this.speed;
        if ((this.x > width+100) || (this.x < -200)) {
          this.speed *= -1;
        }
    }
    
}