Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
/*
Build your own toy Robot!! 
 
 Programmer: Dominique Watt
 
 At Robot's for Humans .co, we let you create your Robot!
 Click on the different colour buttons to customize your Robo Pal!
 We carry a variety of choices to make you (hopefully) love your Robot!
 **Certain items have different features (hat & bowtie, press a key(colour change fun) look forward to it
 Go on! Create your robo bro!
 
 */

void setup()
{
  size(400, 400);
  println("Left side buttons (Up-Down): 1.Legs 2.Head 3.Pants");
  println("Right side buttons (Up-Down): 1.Eyes 2.Mouth 3.Accessories 4.Shirts");
  println("Have Fun!!");
}

//Here are my universal variables for storing the players button count
float posY=340;
float choiceL=1;
float choiceE=0;
float choiceM=0;  
float choiceA=0;
float choiceA2=0;
float head=1;
float choiceP=0;

//Put together a robot! Much fun!
void draw()
{
  background(70);
  frameRate(60);

  //Background details, pretty unexpected background
  fill(255, 192, 203);
  rect(200, 140, width, height);

  //The gradient 
  fill(255, 192, 203);
  rect (200, 50, width, 40);
  fill(250, 192, 203);
  rect (200, 70, width, 60);
  fill(245, 192, 203);
  rect (200, 90, width, 80);
  fill(240, 192, 203);
  rect (200, 110, width, 100);
  fill(235, 192, 203);
  rect (200, 130, width, 120);
  fill(230, 192, 203);
  rect (200, 150, width, 140);
  fill(225, 192, 203);
  rect (200, 170, width, 160);
  fill(220, 192, 203);
  rect(200, 190, width, 180);
  fill(215, 192, 203);
  rect (200, 210, width, 180);
  fill(210, 192, 203);
  rect(200, 230, width, 180);
  fill(205, 192, 203);
  rect(200, 250, width, 180);

  noStroke();

  //(picture frame) in background
  fill(230);
  rect(200, 110, 200, 100);
  fill(255);
  rect(200, 110, 180, 90);
  fill(245);
  rect(200, 90, 180, 20);
  rect(200, 130, 180, 20);
  fill(235);
  rect(200, 110, 180, 20);

  float a=255;


  //Weird art inside the picture frame, it's objective art...for a robot's new house
  fill(255, 105, 180);
  rect(200, 110, 60, 40);
  fill(255, 105, 180);
  rect(125, 110, 20, 20);
  rect(275, 110, 20, 20);
  fill(230);
  rect(200+(mouseX*0.02), 110, 10, 50);


  //Buttons Section

  //Leg adjusting Button!!
  rect(40, 40, 55, 55);

  //Head Changing BUTTON!!
  rect(40, 130, 55, 55);

  //Pants? yes there's a pants button
  rect(40, 220, 55, 55);

  //Eyes button
  rect(360, 40, 55, 55);

  //Mouth Button
  rect(360, 100, 55, 55);

  //Random Accessories Button
  rect(360, 160, 55, 55);

  //Shirts Button
  rect(360, 220, 55, 55);  

  //Inner buttons (so the actual button part)
  fill(255, 20, 147);
  rect(40, 40, 25, 25);
  fill(240, 128, 128);
  rect(40, 130, 25, 25);
  fill(220, 20, 60);
  rect(40, 220, 25, 25);
  fill(219, 112, 147);
  rect(360, 40, 25, 25);
  fill(139, 0, 0);
  rect(360, 100, 25, 25);
  fill(199, 21, 133);
  rect(360, 160, 25, 25);
  fill(255, 20, 60);
  rect(360, 220, 25, 25);

  //Calling the functions that will create the player's robot
  fill(230);
  robLegs();
  robPants();
  rob();
  robHead();
  robEyes();
  robMouth();
  robShirts();
  robAccessories();

  //Changes coulour of hat & bowtie when pressed, is too much when it effects everything
  if (keyPressed==true)
  {
    colour();
    robAccessories();
  }
}

// Generates random colours when called on 
void colour()
{
  float r=random(0, 255);  
  float g=random(0, 255);
  float b=random(0, 255);
  if (keyPressed==true)
  {
    fill(r, g, b);
  }
}

//Medium Length legs - for that average size robot
void reset()
{
  if (posY>=340)
  {
    posY-=1;
    rect(182, posY-10, 22, 60);
    rect(218, posY-10, 22, 60);
  } else if (posY<=340)
  {
    posY+=1;
    rect(182, posY-10, 22, 60);
    rect(218, posY-10, 22, 60);
  }
}

//Really short legs, when you want a short robot
void flyUpRob()
{
  if (posY>290)
  { 
    posY=posY-1;
    rect(182, posY+2, 22, 70);
    rect(218, posY+2, 22, 70);
  } else 
  {
    rect(182, posY, 22, 70);
    rect(218, posY, 22, 70);
  }
}

//Long Legs - when you want a tall robot
void flyDownRob()
{
  if (posY<=352)
  {
    posY=posY+1;
    rect(182, posY, 22, 80);
    rect(218, posY, 22, 80);
  } else if (posY>=290)
  {
    rect(182, posY-10, 22, 80);
    rect(218, posY-10, 22, 80);
  }
}

//Basic proportions of the starting robot, 
void rob()
{
  fill(230);
  rectMode(CENTER);

  //Arm joints
  rect(158, 246, 15, 15);
  rect(242, 246, 15, 15);

  //Arms
  rect(243, 275, 10, 45);
  rect(157, 275, 10, 45);

  //Neck
  rect(200, 235, 10, 10);

  //Body
  rect(200, 267, 70, 60);
}

//Calls upon my moving leg functions when the button is pressed
void robLegs()
{
  if (choiceL==2)
  {
    flyUpRob();
  } else if (choiceL==3)
  {
    flyDownRob();
  } else if (choiceL==1)
  {
    reset(); 
    rob();
  }
}
//Robot Pants, not that much in demand so not that many options
//Puts pants on the robot when button is pressed
void robPants()
{ 
  if (choiceP==1)
  {
    fill(0);
    rect(182, 322, 22, 60);
    rect(218, 322, 22, 60);
  } else if (choiceP==2)
  {
    fill(0);
    rect(182, 320, 22, 40);
    rect(218, 320, 22, 40);
  }
}
//Gives the robot eyes, changes when button is pressed
void robEyes()
{
  if (choiceE==1)
  {
    fill(0);
    rect(180, 200, 15, 5);
    rect(220, 200, 15, 5);
  } else if (choiceE==2)
  {
    fill(0);
    rect(180, 200, 10, 10);
    rect(220, 200, 10, 10);
    //eyebrows
    rect(180, 185, 15, 5);
    rect(220, 185, 15, 5);
  } else if (choiceE==3)
  {
    fill(0);
    ellipse(180, 200, 10, 10);
    ellipse(220, 200, 10, 10);
  }
}

//Gives the robot a mouth, or not if you don't want it
void robMouth()
{
  if (choiceM==1)
  {
    fill(0);
    rect(200, 220, 20, 5);
  } else if (choiceM==2)
  {
    fill(230, 0, 0);
    rect(200, 220, 25, 25);
  } else if (choiceM==3)
  {
    fill(0);
    ellipse(200, 220, 20, 5);
  }
}

//gives the robot some character, some accessories (hat, weird glasses, and a bowtie!)
void robAccessories()
{
  if (choiceA==1)
  { 
    //HAT CHANGES COLOUR(press that key!!)
    triangle(170, 170, 190, 140, 210, 170);
    ellipse(190, 140, 5, 5);
  } else if (choiceA==2)
  {
    fill(50);
    stroke(50);
    rect(182, 212, 15, 10);
    line(180, 212, 220, 212);
    rect(218, 212, 15, 10);
    line(223, 215, 240, 195);
    line(175, 212, 160, 195);
    noStroke();
  } else if (choiceA==3)
  {
    //bow tie - also changes colour!!
    rect(200, 245, 5, 5);
    rect(208, 242, 10, 15);
    rect(192, 242, 10, 15);
    fill(255, 182, 193);
    ellipse(175, 215, 15, 10);
    ellipse(225, 215, 15, 10);
  }
}

//This changes the Robot's head shape
void robHead()
{
  if (head==1)
  { 
    rect(200, 200, 80, 60);
  } else if (head==2)
  {
    rect(200, 185, 70, 90);
  } else if (head==3)
  {
    rect(200, 200, 120, 60);
  }
}
//Gives the option of having the robot wear a shirt...
void robShirts()
{
  if (choiceA2==1)
  { 
    fill(255);
    rect(200, 272, 57, 57);
    //Symbol?
    fill(150, 0, 0);
    triangle(175, 250, 225, 270, 220, 280);
    //Vest
    fill(0);
    rect(225, 270, 20, 65);
    rect(175, 270, 20, 65);
  } else if (choiceA2==2)
  {
    fill(50);
    rect(200, 270, 64, 64);
    rect(160, 245, 17, 17);
    rect(240, 245, 17, 17);
    fill(255);
    triangle(181, 240, 200.5, 275, 222, 240);
    stroke(0);
    line(200, 240, 200, 300);
    noStroke();
    fill(0);
    ellipse(200.5, 280, 5, 5);
    ellipse(200.5, 290, 5, 5);
  } else if (choiceA2==3)
  {
    stroke(0);
    strokeWeight(3);
    line(185, 265, 215, 265);
    line(185, 275, 215, 275);
    line(185, 285, 215, 285);
    line(200, 264, 200, 287);

    noStroke();
    strokeWeight(1);
  }
}

//Calculates if mouse actually pressed the button, then changes that part of the robot
void mousePressed()
{
  //Leg button pressed checker
  if (mouseX<50&&mouseX>0&&mouseY<60)
  {
    fill(199, 21, 133);
    rect(40, 40, 25, 25);
    choiceL+=1;
    //resets the options again on loop
    if (choiceL>=4)
    {
      choiceL=1;
    }
  }
  //Checks for the head button
  else if (mouseX<52&&mouseX>0&&mouseY<142&&mouseY>115)
  {
    fill(199, 21, 133);
    rect(40, 130, 25, 25);
    head+=1;

    //resets the options again on loop
    if (head>3)
    {
      head=1;
    }
  } 
  //Checks for the eyes button
  else if (mouseX>340&&mouseX<370&&mouseY<50)
  {
    choiceE+=1;
    fill(199, 21, 133);
    rect(360, 40, 25, 25);

    //resets the options again on loop
    if (choiceE>=4)
    {
      choiceE=0;
    }
  }
  //Checks for the mouth button
  else if (mouseX<370&&mouseX>340&&mouseY<120&&mouseY>90)
  {
    choiceM+=1;
    fill(199, 21, 133);
    rect(360, 100, 25, 25);

    //resets the options again on loop
    if (choiceM>=4)
    {
      choiceM=0;
    }
  } 
  //Checks for the accessories button
  else if (mouseX>340&&mouseX<370&&mouseY<170&&mouseY>155)
  {
    choiceA+=1;
    fill(199, 21, 133);
    rect(360, 160, 25, 25);

    //resets the options again on loop
    if (choiceA>=4)
    {
      choiceA=0;
    }
  } 
  //Checks for the Shirt button
  else if (mouseX>340&&mouseX<370&&mouseY<230&&mouseY>200)
  {
    choiceA2+=1;
    fill(199, 21, 133);
    rect(360, 220, 25, 25);

    //resets the options again on loop
    if (choiceA2>=4)
    {
      choiceA2=0;
    }
  }
  //Checks for the pants button
  else if (mouseX>0&&mouseX<50&&mouseY<230&&mouseY>200)
  {
    choiceP+=1;
    fill(199, 21, 133);
    rect(40, 220, 25, 25);
    //resets the options again on loop
    if (choiceP>=3)
    {
      choiceP=0;
    }
  }
}