24.9.13

ICM Week 3




"Hauling Ass" By Claire K-V and Corey B. Here's an interactive sketch that uses loops, objects and CARS!




The Code:
MAIN PROGRAM
float sC2=0;
float y=990;
float y1=0;
//float d=mouseX;

Car c1;
Car c2;
Car c3;
Car c4;
Car c5;

void setup() {
  c1 = new Car(color(244,10,0), width/4+122, 0, .5);
  c2 = new Car(color(0,100,255), width/4+28, 0, .1);
  c3 = new Car(color(200,150,0), width/4+28, 200, .1);
  c4 = new Car(color(0,200,10), width/4+28, -150, .1);
  c5 = new Car(color(100,200,10), width/4+250, 290, .1);
  size (600, 1000);
  smooth();
}

void draw() {
if(mousePressed){
c2 = new Car(color(0,100,255), mouseX-85, mouseY+20, 1.5);
}

  background(0, 250, 150);
  fill(175);
  //background ROAD
  rectMode(CENTER);
  rect(width/2, height/2, 400, height);
  fill(255, 222, 173);
  rectMode(CENTER);
  rect(width/4-50, height/2, 20, height);
  fill(255, 222, 173);
  rectMode(CENTER);
  rect(width/4+350, height/2, 20, height);
  //ROAD lines
  for (y1=height;y1>0;y1-=35) {
  noStroke();
  fill(230, 210, 0);
  rect(width/2, y, 10, 55);
  //rect(width/2, y+170, 10, 55);
  //rect(width/2, y+340, 10, 55);
  //rect(width/2, y+510, 10, 55);
  y=y-2;
  if(y<0){
    y+=height;
  }
  }
  
  c1.display();
  c1.move();
  
  c2.display();
  c2.move();
  
  c3.display();
  c3.move();
  
  c4.display();
  c4.move();
  
  c5.display();
  c5.move();
}
  
  
  
  
NEW TAB
class Car{
  color co;
  float xpos;
  float ypos;
  float yspeed;
  
  Car (color tempCo, float tempXpos, float tempYpos, float tempYspeed){
  co=tempCo;
  xpos=tempXpos;
  ypos=tempYpos;
  yspeed=tempYspeed;
  }
  
  void display(){
    stroke(0);
    //tires
    fill(0);
    rectMode(CENTER);
    rect(xpos+78, ypos-15,8, 22); 
    rect(xpos+121, ypos-15,8, 22);
    rect(xpos+78, ypos+17,8, 22);
    rect(xpos+121, ypos+17,8, 22);
    
    
  //CARBODY
  fill(co);
  rectMode(CENTER);
  rect(xpos+100, ypos, 40, 80);
  ellipseMode(CENTER);
  ellipse(xpos+100, ypos, 27, 41);
  ellipseMode(CENTER);
    ellipse(xpos+78, ypos+10,8, 5);
    ellipse(xpos+121, ypos+10,8, 5);
  //windshieldzzz front
  beginShape();
  fill(0);
  vertex(xpos+88, ypos+10);
  vertex(xpos+87, ypos+25);
  vertex(xpos+113, ypos+25);
  vertex(xpos+112, ypos+10);
  endShape(CLOSE);
  //WS back
  beginShape();
  vertex(xpos+87, ypos-9);
  vertex(xpos+88, ypos-21);
  vertex(xpos+112, ypos-21);
  vertex(xpos+112, ypos-9);
  endShape(CLOSE);
  
  }
  
  void move(){
    ypos=ypos+yspeed;
    if (ypos>height){
      ypos=ypos-height;
    }
  }
}