///////////////////////////////////////////////////
//the accel by Peter Ng
//arrow left and right to rotate left and right
//clickable headlight roof and rear light

///////////////////////////////////////////////////
int alphaback=1;
float a1=2,a2=1000,a3=2,a4=1000;
float redalpha,yellowalpha;
float x,y,z;
boolean overback = false;
boolean rotateperspectivenormal = false;
boolean rotateperspectiveroof = false;
boolean rotateperspectiverearlights = false;
boolean rotateperspectiveheadlights = false;
boolean overroof = false;
boolean overheadlights = false;
boolean overrearlights = false;
float rsx, rsy, rearlightsx, headlightsx;
boolean locked = false;

void setup(){
  stroke(0,85);
  size(600,300);
  background(255);
  smooth();
  framerate(60);
  noFill();
  ellipseMode(CENTER_DIAMETER);

  rectMode(CENTER_DIAMETER);
  BFont vrinda;
  vrinda = loadFont("vrinda.vlw");
  textFont(vrinda, 40);
}

void loop(){

  background (255);
  if(a1<100000)  {
    a1=1+a1*1.05;
    fill(100,100,100,a1);
    text("roof entrance|laser headlamps|double type rearlamps|300hp",20,150);
  }  else  {
    a2=a2/1.1;
    fill(200,200,200,a2);
    text("roof entrance|laser headlamps|double type rearlamps|300hp",20,150);
  }

  if(a1> 100000 && a2<1 && a3<1000)  {
    a3*=1.05;
    fill(255,0,0,a3);
    text("the accel",width/2-40,height/2);
  }  else  if(a3>1000){
    a4=a4/1.05;
    fill(255,0,0,a4);
    text("the accel",width/2-40,height/2);
  }
  noFill();

  if(a4<1)  {
    a1+=0;
    a2+=0;
    a3+=0;
    a4+=0;

    //BACK FOR WHEN LOCKED
    if (locked == true)  {
      if(alphaback > 200){
        alphaback +=0;
      } else  {
        alphaback *= 2;
      }
      textSize(30);
      fill(255,0,0,alphaback);
      text("back",15,285);
      noFill();
      textSize(40);
    } else if(!locked)  {
      alphaback =1;
    }
    if (mouseX < 100 && mouseY > 275)  {
      overback = true;
    }  else  {
      overback = false;
    }

    fill(50,50,50);
    text(">the accel",10,30);
    noFill();

    translate(300,150,-75);

    //rotation of car
    if (keyPressed && !locked)  {
      if(key == LEFT)  {
        y++;
      }  else  if(key == RIGHT)  {
        y --;
      }  else if(key == UP && x>-90)  {
        x --;
      }  else if (key == DOWN && x<5)  {
        x ++;
      }
    }

    //rotate perspective back to normal

    if(rotateperspectivenormal)  {
      x=x/1.2;
      locked = false;
      rotateperspectiveroof = false;
      rotateperspectiverearlights = false;
      rotateperspectiveheadlights = false;
      overroof = false;
      overheadlights = false;
      overrearlights = false;
      rotateperspectivenormal = false;
      overback = false;

    }  else  {
      x+=0;
    }

    //restructure of y rotate to reset to 1 at 361
    if(y == 361)  {
      y=1;
    }  else  if(y == -361)  {
      y=-1;
    }

    rotateX(radians(x));
    rotateZ(radians(z));
    rotateY(radians(y));
    car();

    ////////////////////////////////////////////////////
    // if clicked on windows
    if(rotateperspectiveroof)  {
      if(abs(y)>= 0)  {
        y= y/2+2;
      }  else  {
        y +=0;
      }

      if(abs(y)<10) {
        x= x/2-15;
      }

      if (x <= -24 && rsx<90)  {
        rsx += 1;
      }  else  {
        rsx += 0;
      }
      if (x>=-25 && rsy>-8)  {
        rsy -= 1;
      }  else  {
        rsy += 0;
      }
      fill(100,100,100);
      text("State of the Art Roof",125,-130);
      text("Sliding Convertible Top",125,-105);
      noFill();
    }  else if(rsx>=0)  {
      rsx --;

    }  else if(rsy<=0)  {
      rsy ++;
    }

    // if clicked on rearlights
    if(rotateperspectiverearlights)  {
      if(abs(y)>= 0)  {
        y= y/2-48;
      }  else  {
        y +=0;
      }
      if(abs(y)>-40 && x<3)  {
        x++;
      }

      if (x >= 2 && redalpha<150 && yellowalpha<150)  {

        redalpha=redalpha*2;
        yellowalpha=yellowalpha*1.2;
        noStroke();
        push();
        translate(205,-9,1);

        rotateY(radians(90));
        fill(255,0,0,200-redalpha);
        rect(0,0,118,8);
        translate(2,8,0);
        fill(255,255,0,200-yellowalpha);
        rect(0,0,72,4);
        stroke(0,85);
        noFill();
        pop();
      }  else  {
        redalpha=1;
        yellowalpha=1;
      }
      push();
      rotateY(radians(90));
      fill(100,100,100);
      text("Yellow LED Brake Light",125,-100);
      text("for Slowing Traffic",170,-75);
      noFill();
      pop();
    }

    // if clicked on headlights
    if(rotateperspectiveheadlights)  {
      if(abs(y)>= 0)  {
        y= y/2+55;
      }  else  {
        y +=0;
      }
      stroke(255,0,0);
      line(-175,15,-74,-320,15,-74);
      line(-175,15,74,-320,15,74);
      stroke(0,85);

      push();

      rotateY(radians(-90));
      translate(0,0,125);
      fill(100,100,100);
      text("Headlamp Built-in Laser",50,-100);
      text("Distance Calculator",85,-75);
      noFill();
      pop();

    }

    push();
    translate(-198.5,-75,89);
    float window1x1 = screenX(257, 18, -30);
    float window1x2 = screenX(109, 65, 0);
    float window1y1 = screenY(257, 18, -30);
    float window1y2 = screenY(109, 65, 0);

    float rearlights1x1 = screenX(380,60,-173);
    float rearlights1x2 = screenX(400,110,-5);
    float rearlights1y1 = screenY(380,60,-173);
    float rearlights1y2 = screenY(400,110,-5);

    float headlights1x1 = screenX(39,77,0);
    float headlights1x2 = screenX(8,96,-35);
    float headlights1y1 = screenY(39,77,0);
    float headlights1y2 = screenY(8,96,-35);

    translate(0,0,-178);
    float window2x1 = screenX(257, 18, 30);
    float window2x2 = screenX(109, 65, 0);
    float window2y1 = screenY(257, 18, 30);
    float window2y2 = screenY(109, 65, 0);

    float headlights2x1 = screenX(39,77,0);
    float headlights2x2 = screenX(8,96,35);
    float headlights2y1 = screenY(39,77,0);
    float headlights2y2 = screenY(8,96,35);
    pop();

    if (locked == false)  {
      //window roof
      if ((mouseX > window1x2 && mouseX < window1x1
      && mouseY > window1y1 && mouseY < window1y2)
      || (mouseX > window1x1 && mouseX < window1x2
      && mouseY > window1y1 && mouseY < window1y2)

      || (mouseX > window2x2 && mouseX < window2x1
      && mouseY > window2y1 && mouseY < window2y2)
      || (mouseX > window2x1 && mouseX < window2x2
      && mouseY > window2y1 && mouseY < window2y2))  {
        if(rsy>-5)  {
          rsy--;
          overroof = true;
        }
        rsy +=0;
      }  else if(rsy<0)  {
        rsy++;
        overroof = false;
      }

      //rear lights
      if ((mouseX > rearlights1x2 && mouseX < rearlights1x1
      && mouseY > rearlights1y1 && mouseY < rearlights1y2 && rearlightsx < 20)
      || (mouseX > rearlights1x1 && mouseX < rearlights1x2
      && mouseY > rearlights1y1 && mouseY < rearlights1y2))  {
        if(rearlightsx<10)  {
          rearlightsx ++;
          overrearlights = true;
        }
        rearlightsx +=0;
      }  else  if(rearlightsx>0)  {
        rearlightsx --;
        overrearlights = false;
      }

      //head lights
      if ((mouseX > headlights1x2 && mouseX < headlights1x1
      && mouseY > headlights1y1 && mouseY < headlights1y2)
      || (mouseX > headlights1x1 && mouseX < headlights1x2
      && mouseY > headlights1y1 && mouseY < headlights1y2)

      || (mouseX > headlights2x2 && mouseX < headlights2x1
      && mouseY > headlights2y1 && mouseY < headlights2y2)
      || (mouseX > headlights2x1 && mouseX < headlights2x2
      && mouseY > headlights2y1 && mouseY < headlights2y2))  {
        if(headlightsx>-10)  {
          headlightsx --;
          overheadlights = true;
        }
        headlightsx +=0;
      }  else  if(headlightsx<0)  {
        headlightsx ++;
        overheadlights = false;
      }
    }

  }
}

void mousePressed() {
  if(overroof == true) {
    locked = true;
    rotateperspectiveroof = true;
  }

  if(overrearlights == true) {
    locked = true;
    rotateperspectiverearlights = true;
  }

  if(overheadlights == true) {
    locked = true;
    rotateperspectiveheadlights = true;
  }

  if(overback)  {
    locked = false;
    rotateperspectivenormal = true;
  }
}

void car()  {
  push();
  push();

  translate(-198.5,-75,89);
  //side
  beginShape(LINE_STRIP);
  curveVertex(37,100);
  curveVertex(37,100);
  curveVertex(68,85.5);
  curveVertex(113.5,74);
  curveVertex(217.5,65);
  curveVertex(217.5,65);
  vertex(254,64);
  vertex(388,57);
  vertex(350,18,-18);
  vertex(262,12,-36);
  endShape();

  beginShape(LINE_STRIP);
  vertex(164,25,-142);
  vertex(164,25,-36);
  curveVertex(164,25,-36);
  curveVertex(164,25,-36);
  curveVertex(98,58,-10);
  curveVertex(98,58,-10);
  vertex(39,77);
  curveVertex(39,77);
  curveVertex(26,82,-1);
  curveVertex(15,86,-2);
  curveVertex(8,96,-6);
  curveVertex(8,96,-6);
  endShape();

  //window stay
  beginShape(LINE_STRIP);
  vertex(257,17.5,-30);
  vertex(251.5,57,-2);
  curveVertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(162,36,-26);
  curveVertex(162,36,-26);
  vertex(170,35,-89);
  endShape();
  beginShape(LINE_STRIP);
  vertex(162,36,-26);
  vertex(164,25,-36);
  endShape();

  //roof slide

  stroke(6,75,239);
  push();
  translate(rsx,rsy,0);
  beginShape(LINE_STRIP);
  vertex(311,13.5,-110.25);
  vertex(311,17.5,-110.25);
  endShape();
  beginShape(LINE_STRIP);
  vertex(311,13.5,-66);
  vertex(311,17.5,-66);
  endShape();
  beginShape(LINE_STRIP);
  vertex(311,13.5,-110.25);
  vertex(311,13.5,-66);
  vertex(257.3,11.5,-66);
  curveVertex(262,12,-36);
  curveVertex(262,12,-36);
  curveVertex(164,25,-36);
  curveVertex(164,25,-36);
  vertex(164,25,-142);
  curveVertex(164,25,-142);
  curveVertex(164,25,-142);
  curveVertex(262,12,-142);
  curveVertex(262,12,-142);
  vertex(257.3,11.5,-112);
  vertex(311,13.5,-110.25);
  endShape();
  push();
  translate(0,4,0);
  beginShape(LINE_STRIP);
  vertex(311,13.5,-110.25);
  vertex(311,13.5,-66);
  vertex(257.3,11.5,-66);
  curveVertex(262,12,-36);
  curveVertex(262,12,-36);
  curveVertex(164,25,-36);
  curveVertex(164,25,-36);
  vertex(164,25,-142);
  curveVertex(164,25,-142);
  curveVertex(164,25,-142);
  curveVertex(262,12,-142);
  curveVertex(262,12,-142);
  vertex(257.3,11.5,-112);
  vertex(311,13.5,-110.25);
  endShape();
  pop();

  //window front slide open
  push();
  beginShape(LINE_STRIP);
  vertex(257,17.5,-40);
  vertex(257,17.5,-30);
  vertex(251.5,57,-2);
  vertex(251.5,57,-12);
  endShape();

  translate(0,0,-2);
  beginShape(LINE_STRIP);
  vertex(257,17.5,-30);
  vertex(251.5,57,-2);
  vertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(162,36,-26);
  curveVertex(196.5,22,-35);
  curveVertex(257,17.5,-30);
  curveVertex(257,17.5,-30);
  endShape();

  translate(0,0,-8);
  beginShape(LINE_STRIP);
  vertex(257,17.5,-30);
  vertex(251.5,57,-2);
  vertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(162,36,-26);
  curveVertex(196.5,22,-35);
  curveVertex(257,17.5,-30);
  curveVertex(257,17.5,-30);
  endShape();
  pop();
  pop();
  stroke(0,85);
  //back side window
  beginShape(LINE_STRIP);
  vertex(251.5,57,-2);
  vertex(365,50,-2);
  vertex(340,23,-15);
  vertex(257,17.5,-30);
  endShape();
  beginShape(LINE_STRIP);
  vertex(265,18,-29);
  vertex(260,57,-1);
  endShape();

  //hatch line
  beginShape(LINE_STRIP);
  curveVertex(370,57);
  curveVertex(370,57);
  curveVertex(390,56,-5);
  curveVertex(397,55,-88);
  curveVertex(390,56,-173);
  curveVertex(370,57,-178);
  curveVertex(370,57,-178);
  endShape();

  //wing
  beginShape(LINE_STRIP);
  vertex(350,18,-18);
  vertex(378,18,-18);
  curveVertex(366,33.4,-12);
  curveVertex(366,33.4,-12);
  curveVertex(366,18,-30);
  curveVertex(366,18,-148);
  curveVertex(366,33.4,-166);
  curveVertex(366,33.4,-166);
  vertex(378,18,-160);
  vertex(350,18,-160);
  endShape();
  beginShape(LINE_STRIP);
  vertex(378,18,-160);
  vertex(378,18,-18);
  vertex(350,18,-18);
  vertex(350,18,-160);
  endShape();

  //window line front
  beginShape(LINE_STRIP);
  vertex(98,58,-10);
  vertex(98,58,-168);
  endShape();

  //headlight
  push();
  translate(0+headlightsx,0,0);
  stroke(248,243,63);
  beginShape(LINE_STRIP);
  curveVertex(8,96,-35);
  curveVertex(8,96,-35);
  curveVertex(8,96,-6);
  curveVertex(21.5,97.7);
  curveVertex(37,80);
  curveVertex(39,77);
  curveVertex(25,80,-18);
  curveVertex(18,90,-35);
  curveVertex(12,95,-38);
  curveVertex(8,96,-35);
  curveVertex(8,96,-35);
  endShape();
  pop();
  stroke(0,85);

  //grill
  //hood
  beginShape(LINE_STRIP);
  curveVertex(22,85,-150);
  curveVertex(22,85,-150);
  curveVertex(18,89,-88);
  curveVertex(22,85,-26);
  curveVertex(22,85,-26);
  endShape();
  //grill bottom
  beginShape(LINE_STRIP);
  curveVertex(22,86,-133);
  curveVertex(22,86,-133);
  curveVertex(10,96.5,-124);
  curveVertex(6,100,-88);
  curveVertex(10,96.5,-54);
  curveVertex(22,86,-45);
  curveVertex(22,95,-88);
  curveVertex(22,86,-133);
  curveVertex(22,86,-133);
  endShape();
  //sideskirts
  line(103,122,302,115);

  //bumper line top
  beginShape(LINE_STRIP);
  curveVertex(37,100);
  curveVertex(37,100);
  curveVertex(10,102,-6);
  curveVertex(4,108,-88);
  curveVertex(10,102,-172);
  curveVertex(37,100,-178);
  curveVertex(37,100,-178);
  endShape();
  //bumper line middle
  beginShape(LINE_STRIP);
  curveVertex(37,115);
  curveVertex(37,115);
  curveVertex(8,122,-6);
  curveVertex(1.8,132,-88);
  curveVertex(8,122,-172);
  curveVertex(37,115,-178);
  curveVertex(37,115,-178);
  endShape();
  //bumper line bottom
  beginShape(LINE_STRIP);
  curveVertex(37,138);
  curveVertex(37,138);
  curveVertex(8,138,-6);
  curveVertex(1.8,138,-88);
  curveVertex(8,138,-172);
  curveVertex(37,138,-178);
  curveVertex(37,138,-178);
  endShape();

  //wheel gap
  beginShape(LINE_STRIP);
  curveVertex(37,138);
  curveVertex(37,138);
  curveVertex(41,103);
  curveVertex(71.5,89);
  curveVertex(97,100);
  curveVertex(105,139);
  curveVertex(105,139);
  vertex(298,136.5);
  curveVertex(298,136.5);
  curveVertex(298,136.5);
  curveVertex(310,96);
  curveVertex(345,88);
  curveVertex(368,102);
  curveVertex(376.5,132);
  curveVertex(376.5,132);
  endShape();

  //wheels
  ellipse(70,120,60,60);
  ellipse(338,121,65,65);
  push();
  translate(0,0,2);
  ellipse(70,120,55,55);
  ellipse(338,121,65,60);
  pop();
  push();
  translate(0,0,-25);
  ellipse(70,120,60,60);
  translate(0,0,-5);
  ellipse(338,121,65,65);
  pop();

  //rear bumper mid
  beginShape(LINE_STRIP);
  curveVertex(370,106);
  curveVertex(370,106);
  curveVertex(400,100,-5);
  curveVertex(406.5,100,-88);
  curveVertex(400,100,-173);
  curveVertex(370,106,-178);
  curveVertex(370,106,-178);
  endShape();
  //rear bumper low
  beginShape(LINE_STRIP);
  curveVertex(376.5,132);
  curveVertex(376.5,132);
  curveVertex(400,122,-5);
  curveVertex(406.5,122,-88);
  curveVertex(400,122,-173);
  curveVertex(376.5,132,-178);
  curveVertex(376.5,132,-178);
  endShape();
  //chasis
  beginShape(LINE_STRIP);
  vertex(376.5,132,-178);
  vertex(376.5,132,-142);
  vertex(298,136.5,-142);
  vertex(298,136.5,-178);
  vertex(105,139,-178);
  vertex(105,139,-148);
  vertex(37,138,-148);
  vertex(37,138,-178);
  endShape();

  //rear lights
  push();
  translate(390.5+rearlightsx,75,-88);
  box(10,23.5,118);

  stroke(255,55,55);

  translate(0,-8,0);
  box(10,8,118);

  stroke(248,169,63);

  translate(0,6,0);
  box(4,4,75);
  translate(0,7,70);
  box(10,35,23);
  translate(0,0,-140);
  box(10,35,23);
  translate(0,15,0);
  box(10,5,23);
  translate(0,0,140);
  box(10,5,23);
  stroke(0,85);
  pop();
  pop();

  //other side

  push();
  translate(-198.5,-75,-89);
  //side
  beginShape(LINE_STRIP);
  curveVertex(37,100);
  curveVertex(37,100);
  curveVertex(68,85.5);
  curveVertex(113.5,74);
  curveVertex(217.5,65);
  curveVertex(217.5,65);
  vertex(254,64);
  vertex(388,57);
  vertex(350,18,18);
  vertex(262,12,36);
  endShape();

  beginShape(LINE_STRIP);
  vertex(164,25,142);
  vertex(164,25,36);
  curveVertex(164,25,36);
  curveVertex(164,25,36);
  curveVertex(98,58,10);
  curveVertex(98,58,10);
  vertex(39,77);
  curveVertex(39,77);
  curveVertex(26,82,1);
  curveVertex(15,86,2);
  curveVertex(8,96,6);
  curveVertex(8,96,6);
  endShape();

  //window stay
  beginShape(LINE_STRIP);
  vertex(257,17.5,30);
  vertex(251.5,57,2);
  curveVertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(162,36,26);
  curveVertex(162,36,26);
  vertex(170,35,89);
  endShape();

  beginShape(LINE_STRIP);
  vertex(162,36,26);
  vertex(164,25,36);
  endShape();

  //headlight
  push();
  stroke(248,243,63);
  translate(0+headlightsx,0,0);
  beginShape(LINE_STRIP);
  curveVertex(8,96,35);
  curveVertex(8,96,35);
  curveVertex(8,96,6);
  curveVertex(21.5,97.7);
  curveVertex(37,80);
  curveVertex(39,77);
  curveVertex(25,80,18);
  curveVertex(18,90,35);
  curveVertex(12,95,38);
  curveVertex(8,96,35);
  curveVertex(8,96,35);
  endShape();
  pop();
  stroke(0,85);
  //wheel gap
  beginShape(LINE_STRIP);
  curveVertex(37,138);
  curveVertex(37,138);
  curveVertex(41,103);
  curveVertex(71.5,89);
  curveVertex(97,100);
  curveVertex(105,139);
  curveVertex(105,139);
  vertex(298,136.5);
  curveVertex(298,136.5);
  curveVertex(298,136.5);
  curveVertex(310,96);
  curveVertex(345,88);
  curveVertex(368,102);
  curveVertex(376.5,132);
  curveVertex(376.5,132);
  endShape();

  //wheels
  ellipse(70,120,60,60);
  ellipse(338,121,65,65);
  push();
  translate(0,0,-2);
  ellipse(70,120,55,55);
  ellipse(338,121,65,60);
  pop();
  push();
  translate(0,0,25);
  ellipse(70,120,60,60);
  translate(0,0,5);
  ellipse(338,121,65,65);
  pop();

  //chasis
  beginShape(LINE_STRIP);
  vertex(376.5,132,178);
  vertex(376.5,132,142);
  vertex(298,136.5,142);
  vertex(298,136.5,178);
  vertex(105,139,178);
  vertex(105,139,148);
  vertex(37,138,148);
  vertex(37,138,178);
  endShape();

  //window front slide open
  stroke(6,75,239);
  push();
  translate(rsx,rsy,0);

  beginShape(LINE_STRIP);
  vertex(257,17.5,40);
  vertex(257,17.5,30);
  vertex(251.5,57,2);
  vertex(251.5,57,12);
  endShape();

  translate(0,0,2);
  beginShape(LINE_STRIP);
  vertex(257,17.5,30);
  vertex(251.5,57,2);
  vertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(162,36,26);
  curveVertex(196.5,22,35);
  curveVertex(257,17.5,30);
  curveVertex(257,17.5,30);
  endShape();
  push();
  translate(0,0,8);
  beginShape(LINE_STRIP);
  vertex(257,17.5,30);
  vertex(251.5,57,2);
  vertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(109,65.3);
  curveVertex(162,36,26);
  curveVertex(196.5,22,35);
  curveVertex(257,17.5,30);
  curveVertex(257,17.5,30);
  endShape();
  pop();

  pop();
  stroke(0,85);
  //back side window
  beginShape(LINE_STRIP);
  vertex(251.5,57,2);
  vertex(365,50,2);
  vertex(340,23,15);
  vertex(257,17.5,30);
  endShape();
  beginShape(LINE_STRIP);
  vertex(265,18,29);
  vertex(260,57,1);
  endShape();

  //sideskirts
  line(103,122,302,115);

  //pop for 2nd side
  pop();

  pop();
}
Project 4: Context
Extend an idea you've explored previously in your life, but adapt it to the context of an interactive system which requires the viewer to engage with the material.