Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
Guy[] guyArmy;
int guyArmySize = 19;

Dots[] dotLine;
int dotLineSize = 400;

void setup() {
  size(400, 400);
  dotLine = new Dots[dotLineSize];
  for (int j=0; j<dotLine.length; j++) {
    dotLine[j] = new Dots(random(0, 400), color(random(255), random(255), random(255)));
  }
  guyArmy = new Guy[guyArmySize];
  for (int i=0; i<guyArmy.length; i++) {
    guyArmy[i] = new Guy(random(10, 390), color(random(255), random(255), random(255)), random(random(-3, 3)));
  }
}

void draw() {

  //UPDATE
  for (int j=0; j<dotLine.length; j++) {
    dotLine[j].update();
  }
  for (int i=0; i<guyArmy.length; i++) {
    guyArmy[i].update();
  }

  //DISPLAY
  background(15);
  for (int j=0; j<dotLine.length; j++) {
    dotLine[j].display();
  }
  for (int i=0; i<guyArmy.length; i++) {
    guyArmy[i].display();
  }
}
class Dots {
  PVector position;
  color skin;

  Dots (float tempX, color tempSkin) {
    skin = tempSkin;
    position = new PVector(tempX, 215);
  }
  
  void update(){
   if (mousePressed){
     position.y = position.y + 1;
   }
   else {
     position.y = position.y - 1;
   }
   if (position.y<216){
    position.y=215; 
   }
  }

  void display() {
    fill(skin);
    rect(position.x, position.y, 10, 10, 2);
  }
}
class Guy {

  PVector position;
  PVector velocity;

  float guyWidth;
  float guyHeight;
  color skin;

  Guy (float tempPositionX, color tempSkin, float tempVelocityX) {

    guyWidth = 20;
    guyHeight = 20;
    skin = tempSkin;

    position = new PVector(tempPositionX, 200);
    velocity = new PVector(tempVelocityX, 1);
  }


  void update() {
    position.add(velocity);
    if (mousePressed) {
      guyHeight = guyHeight+1;
      guyWidth = guyWidth+1;
    } else {
      guyHeight = guyHeight-1;
      guyWidth = guyWidth-1;
      if (guyHeight<21) {
        guyHeight = 20;
        guyWidth = 20;
      }
    }
  }

  void display() {
    noStroke();
    fill(skin);
    ellipse(position.x, 200, guyWidth+sin(millis()/100)*2, guyHeight-sin(millis()/100)*2);

    //EYES
    //white
    fill(255);
    ellipse(position.x+guyWidth/4, 200-guyHeight/4, guyWidth/2, guyHeight/2-sin(millis()/100)*2);
    ellipse(position.x-guyWidth/4, 200-guyHeight/4, guyWidth/2, guyHeight/2-sin(millis()/100)*2);
    //black
    fill(0);
    ellipse(position.x+guyWidth/4, 200-guyHeight/4, guyWidth/4, guyHeight/4);
    ellipse(position.x-guyWidth/4, 200-guyHeight/4, guyWidth/4, guyHeight/4);

    //MOUTH
    ellipse(position.x, 200+guyHeight/4.5, guyWidth/2, guyHeight/4-sin(millis()/100)*4);

    //LOOP INSIDE THE BOX
    if (position.x+guyWidth>410 || position.x-guyWidth<-10) {
      velocity.x = velocity.x*-1;
    }
  }
}