> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://uclaspring12.sketchpad.cc/sp/pad/view/ro.FOrOIwXLoZV/rev.211
 * 
 * authors: 
 *   Valentina
 *   Betty

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



// This sketch builds on a prior work, "Workshop 7 [Template]", created by Casey Reas
// http://uclaspring12.sketchpad.cc/sp/pad/view/ro.6lbkehOSkMa3De/rev.7

/* @pjs preload="/static/uploaded_resources/p.4536/bg.jpg"; */
/* @pjs preload="/static/uploaded_resources/p.4536/pole.png"; */

Robot robo1;
Robot robo2;
Robot robo3;
PImage bg;
PImage pole;

void setup() 
{
  size(640, 480);
  smooth();
  ellipseMode(CENTER);
  robo1 = new Robot(0, 100, .8);
  robo2 = new Robot(0, 200, 1);
  robo3 = new Robot(0, 500, 2);
  
    bg = loadImage("/static/uploaded_resources/p.4536/bg.jpg");
    pole = loadImage("/static/uploaded_resources/p.4536/pole.png");
}

void draw() 
{
  image(bg, 0, 0);
  pushMatrix();
  robo1.dooo();
  robo1.display();
  robo2.dooo();
  robo2.display();
  robo3.dooo();
  robo3.display();
  popMatrix();
  image(pole, 0, 0);
}

class Robot 
{
  //fields
  float x, y;
  float speed = .001;
  float squareBottom;
  float antennaDeltaX;
  float angle = 0;
  float speedangle = 50;
  float r, g, b;
  
  //constructor
  Robot (float tempX, float tempY, float tempS)
  {
    x = tempX;
    y = random (120, 300);
    speed = tempS;
    squareBottom = random (-10, 90);
    r = random (255);
    g = random (255);
    b = random (255);
    //println(antennaDeltaX);
  }

void dooo () 
{
  pushMatrix();
  x += speed;
  float deltaY = abs(30*sin(x/5));
  translate (x, deltaY);
    
  float hfwidth = 100;
  if (x > width+hfwidth)
  {
    x = -hfwidth;
  } 
}

void display()
 { 
    antennaDeltaX = sin(angle)*10;
    angle += speedangle*(squareBottom-y);
    
//body
  noStroke();
  fill(0);
  ellipse(50+x, 60+y+squareBottom, 60, 60);   // bottom circle
  fill(r, g, b);
  rect(20+x, 0+y, 60, 60+squareBottom);         // square
  fill(0);
  triangle(0+x, 0+y, 100+x, 0+y, 50+x, 50+y); // Triangle
 
//eye
  stroke(0);
  strokeWeight(3);
  line(20+x, -30+y, 20+x-antennaDeltaX, -75+y);       // left ant
  line(80+x, -30+y, 80+x+antennaDeltaX, -75+y);     // right ant
  fill(r-40, g+20, b+10);
  ellipse(50+x, -30+y, 60, 60);   // first circle eye
  fill(0);
  ellipse(50+x, -30+y, 30, 30);     // second cirlce
  fill(154, 23, 54);
  ellipse(50+x, -30+y, 20, 20);     // third circle
  
  popMatrix();
 }
}