Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//floats for stuff in the interactive toy
float grass1Y;
float grass1X;
float tree1Y;
float tree1X;
float oildrumX;
float oildrumY;
float pothole1X;
float pothole1Y;
float centermiddleX;
float centermiddleY;

//boolean for light on top of car
boolean light = false;

//window size
void setup() {
  size(400, 400);
  background(0, 230, 0);
  frameRate(60);
  tree1X = 350;
  tree1Y = -50;
  pothole1X = 150;
  pothole1Y = -50;
  oildrumX = 250;
  oildrumY = -50;
  grass1X = 30;
  grass1Y = -50;
  centermiddleX = 1;
  centermiddleY= 1;
}

//drawing the objects

void draw() {
  background(0, 230, 0);
  
  drawmainroad();
  drawsideroad1();
  drawsideroad2();
  drawpothole1();
  drawoildrum();
  drawtree1();
  drawcentermiddle();
  drawgrass1();
  drawCoolcar();
}

//the coolest car ever(body)

void drawCoolcar() {
  noStroke();
  fill(230, 0, 0);
  rectMode(CENTER);
  rect(mouseX, mouseY, 30, 60);

  //Window
  fill(0, 0, 140);
  rectMode(CENTER);
  rect(mouseX, mouseY-20, 20, 10);

  //exhaust pipe
  fill(130);
  rectMode(CENTER);
  rect(mouseX, mouseY + 35, 10, 10);

  //front bumper
  fill(170);
  rectMode(CENTER);
  rect(mouseX, mouseY - 30, 30, 5);

  //roof window
  fill(0, 0, 255);
  rectMode(CENTER);
  rect(mouseX, mouseY + 10, 25, 15);

  //Back bumper
  fill(170);
  rectMode(CENTER);
  rect(mouseX, mouseY + 30, 30, 5);

  //Tires (bottom right)
  fill(150);
  rect(mouseX+20, mouseY +15, 10, 15);
  noStroke();

  //Tires (bottom left)
  fill(150);
  rect(mouseX-20, mouseY +15, 10, 15);
  noStroke();

  //Tires(top right)
  fill(150);
  rect(mouseX+20, mouseY - 10, 10, 15);
  noStroke();

  //Tries(top left)
  fill(150);
  rect(mouseX-20, mouseY - 10, 10, 15);
  noStroke();

  //light on top of car ( random colours) 
  ellipseMode(CENTER);
  ellipse(mouseX, mouseY - 5, 15, 15);

  if (light == true) {
    mousePressed();
  } else {
    light = false;
  }
}
void mousePressed() {
  //light on top of car ( random colours) 
  int red = (int) random (0, 256);
  int green = (int) random (0, 256);
  int blue = (int) random (0, 256);
  light = true;
  fill (red, green, blue);
  ellipseMode(CENTER);
  ellipse(mouseX, mouseY - 5, 15, 15);
}

void mouseReleased() {
  light = false;
}



//Mainroad
void drawmainroad() {
  fill(200);
  rectMode(CENTER);
  rect(200, 200, 225, 400);
  noStroke();
}

//side road one(gray stripe on the left)
void drawsideroad1() {
  fill(120);
  rectMode(CENTER);
  rect(95, 200, 20, 400);
}

//side road two(gray stripe on the right)

void drawsideroad2() {
  fill(120);
  rectMode(CENTER);
  rect(305, 200, 20, 400);
}

//drawing the lines in the middle of the road(and looping them)

void drawcentermiddle() {
  
  for (int i = 1; i < 30; i++) {
    fill(235, 235, 0);
    rectMode(CORNER);
    rect(200, i*30-25, 10, 20);
  
  }
}
//drawing the potholes ( one and two)

void drawpothole1() {
  pothole1Y += 4;
  if ( pothole1Y >= 450) {
    pothole1Y = -50;
  }
  fill(70);
  ellipseMode(CENTER);
  ellipse(pothole1X, pothole1Y, 30, 20);
}

//drawing the oildrum and moving it down the y axis

void drawoildrum() {
  oildrumY += 3.5;
  if (oildrumY >=450) {
    oildrumY = -50;
  }
  fill(119, 78, 8);
  rectMode(CENTER);
  rect(oildrumX, oildrumY, 30, 40);

  fill(130, 85, 20);
  rectMode(CENTER);
  rect(oildrumX, oildrumY, 20, 40);

  fill(150, 95, 32);
  rectMode(CENTER);
  rect(oildrumX, oildrumY, 10, 40);
}

//drawing tree and moving it down moves down the y axis

void drawtree1() {
  tree1Y += 3;
  if (tree1Y > 450) {
    tree1Y = -50;
  }

  fill(175, 114, 7);
  rectMode(CENTER);
  rect(tree1X, tree1Y, 20, 50);

  fill(175, 114, 7);
  rectMode(CENTER);
  rect(tree1X, tree1Y, 40, 10);

  fill(17, 135, 4);
  ellipseMode(CENTER);
  ellipse(tree1X + 20, tree1Y, 20, 20);

  fill(17, 135, 4);
  ellipseMode(CENTER);
  ellipse(tree1X - 20, tree1Y, 20, 20);

  fill(17, 135, 4);
  ellipseMode(CENTER);
  ellipse(tree1X, tree1Y - 30, 40, 40);
}



//drawing the grass loops and making move down the Y axis (also looping)

void drawgrass1() {

    for (int i = 1; i <= 10; i++) {  
    grass1Y += 0.8;
    if (grass1Y >= 450) {
      grass1Y = -50;
    }
    fill(0, 142, 38);
    rectMode(CENTER);
    rect(i*5 + grass1X, grass1Y, 5, 20);
  }
}