midterm project



code for countryside scene

Tree[] trees = new Tree [30] ;
Leaves[] leaves = new Leaves[100];
int z = 450;
int angle;
int turn;
int turn2;
float yb ;
PShape car;
void setup() {

  size(800, 800, P3D);
  background(0);

car = loadShape("carfix.obj");
  for (int i = 0; i < trees.length; i++) {
    trees[i] = new Tree(random(-500,300), random(100,height+250));
  }
 
   for (int l = 0; l < leaves.length; l++) {
    leaves[l] = new Leaves(random(width), random(100,height+250), random(360), random(-2000, 1000));
  }
 


}
void draw(){
 
  background(129,186,255);



println(mouseX);
lights();


//rotateX(radians(770));
//pushMatrix();

 //camera(width/2,yb+(height-10),0,width,height,mouseX,0,1,0);
//popMatrix();

  rotateX(radians(774));
  translate(275, 470);
  scale(0.3);
 
  pushMatrix();
  translate(0,0);
    for (int i = 0; i < trees.length; i++) {
    trees[i].update();
    trees[i].display();
 }
 // }
popMatrix();
  pushMatrix();
  //for(int dis = 150; dis <height; dis +=50){
  translate(1050,0);
    for (int i = 0; i < trees.length; i++) {
    trees[i].update();
    trees[i].display();
 }
 // }
popMatrix();
  
        pushMatrix();
  translate(width/2,height/2+100);
rectMode(CENTER);
fill(94,155,52);
noStroke();
rect(0,0,1500,1000);
  popMatrix();
  
   pushMatrix();
  translate(width/2+10,height/2+100);
rectMode(CENTER);
fill(222);
noStroke();
rect(0,0,230,1000);
  popMatrix();
 
pushMatrix();
  if (keyPressed){
  if(key == 's'){
    yb +=10;
  }
    if(key == 'w'){
    yb += -10;
  }
  }
  translate(width/2, yb+(height+200));
rotateZ(radians(90));
  scale(0.5);

  fill(0);
  shape(car,0,0,180,100);
 //sphere(10);
  popMatrix();
 
  pushMatrix();
 
    for (int l = 0; l <leaves.length; l++) {
    leaves[l].update();
    leaves[l].display();
  }
  popMatrix();
  //saveFrame("output/gol_####.png");

}


///////FallingLeaves Class//////////
class Leaves {
  float angle1;
  float y;
  float x;
  float z;
  Leaves(float tx,float ty, float r, float tz){
    x = tx;
    y=ty;
    angle1 = r;
    z = tz;
  }
 
  void update(){
   
      angle1+= 1;
      z += -5;;
      if(z <= -10){
        z = 500;
      }
  }
  void display(){
  pushMatrix();
   translate(x, y,z);
  rotateX(radians(angle1));
   rotateZ(radians(angle1));
    rotateY(radians(angle1));
  fill(58, 180, 25);
  noStroke();
  arc(0, 0, 10, 20, radians(120), radians(240));
  arc(-5, 0, 10, 20, radians(300), radians(420));
  popMatrix();
}
}

//////////Tree Class///////////////
class Tree {

  float y;
  float x;
PShape tree;

  Tree(float tx,float ty) {
    x = tx;
    y = ty;
    tree = loadShape("treefix.obj");

  }

  void update() {


   
  }

  void display() {
    pushMatrix();
    translate(x, y, 20);
    scale(2);
    shape(tree,0,0,50,50);
    // }
    popMatrix();
  }
}




CODE FOR URBAN SCENE

Light streetlights ;
Building[] building1 = new Building [10] ;
Building2[] building2 = new Building2 [10] ;
Building3[] building3 = new Building3 [10] ;
Snow[] snowball = new Snow[200];
PShape car;
float  angle;
int yb;


void setup() {
  streetlights = new Light(300, (height/2)-200);

  size(800, 800, P3D);
  background(0);
car = loadShape("carfix.obj");
  for (int i = 0; i < building1.length; i++) {
    building1[i] = new Building(random(300), random(-200, height+200));
  }

  for (int i2 = 0; i2 < building2.length; i2++) {
    building2[i2] = new Building2(random(300), random(-200, height+200));
  }

  for (int i3 = 0; i3 < building3.length; i3++) {
    building3[i3] = new Building3(random(300), random(-200, height+200));
  }

  for (int l = 0; l < snowball.length; l++) {
    snowball[l] = new Snow(random(width), random(100, height+200), random(360), random(-2000, 1000), random(1, 3));
  }
}
void draw() {
  lights();
  background(0);
  println(mouseX);

  rotateX(radians(774));
  translate(275, 470);
  scale(0.3);

 
  pushMatrix();
  streetlights.update();
  streetlights.display();
  popMatrix();

  pushMatrix();
  translate(250, 0);
  streetlights.update();
  streetlights.display();
  popMatrix();


  pushMatrix();
  //for(int dis = 150; dis <height; dis +=50){
  translate(-100, 0);
  for (int i = 0; i < building1.length; i++) {
    building1[i].update();
    building1[i].display();
  }
  popMatrix();
  pushMatrix();
  translate(600, 0);
  for (int i = 0; i < building1.length; i++) {
    building1[i].update();
    building1[i].display();
  }
  popMatrix();



  pushMatrix();
  translate(-100, 0);
  for (int i2 = 0; i2 < building2.length; i2++) {
    building2[i2].update();
    building2[i2].display();
  }
  popMatrix();
  pushMatrix();
  translate(600, 0);
  for (int i2 = 0; i2 < building2.length; i2++) {
    building2[i2].update();
    building2[i2].display();
  }
  popMatrix();


  pushMatrix();
  translate(-100, 0);
  for (int i3 = 0; i3 < building3.length; i3++) {
    building3[i3].update();
    building3[i3].display();
  }
  popMatrix();
  pushMatrix();
  translate(600, 0);
  for (int i3 = 0; i3 < building3.length; i3++) {
    building3[i3].update();
    building3[i3].display();
  }
  popMatrix();


  pushMatrix();
  translate(width/2+10, height/2);
  rectMode(CENTER);
  fill(222);
  noStroke();
  rect(0, 0, 230, 2000);
  popMatrix();

pushMatrix();
  if (keyPressed){
  if(key == 's'){
    yb +=10;
  }
    if(key == 'w'){
    yb += -10;
  }
  }
  translate(width/2, yb+(height-10));
rotateZ(radians(90));
  scale(0.5);
  //shape(car,0,0);
  fill(0);
  shape(car,0,0,180,100);
  popMatrix();

  pushMatrix();

  for (int l = 0; l <snowball.length; l++) {
    snowball[l].update();
    snowball[l].display();
  }
  popMatrix();
 //saveFrame("output/gol_####.png");
}


////building1 class ///////

class Building {

  float y;
  float x;
PShape building1;

  Building(float tx,float ty) {
    x = tx;
    y = ty;
    building1 = loadShape("stickbuilding.obj");

building1.disableStyle();

  }

  void update() {


   
  }

  void display() {
    pushMatrix();
    translate(x, y, 0);
    // for(int dis = 0; dis <height; dis += 100){
    //box(50,50,100);
    rotate(radians(90));
   scale(2);
   stroke(random(155),random(155),random(155),50);
   strokeWeight(2);
    fill(36,29,124,150);
    shape(building1,0,0,50,50);
  
    // }
    popMatrix();
  }
}
///////building 2/////


class Building2 {

  float y;
  float x;
PShape  building2;

  Building2(float tx,float ty) {
    x = tx;
    y = ty;

    building2 = loadShape("building.obj");

building2.disableStyle();
  }

  void update() {


   
  }

  void display() {
    pushMatrix();
    translate(x, y, 0);
    // for(int dis = 0; dis <height; dis += 100){
    //box(50,50,100);
    rotate(radians(90));
   scale(2);
   stroke(random(155),random(155),random(155),20);
   strokeWeight(2);
    fill(198,48,111,150);
 
    shape(building2,0,0,50,50);
    // }
    popMatrix();
  }
}



/////building 3.//////

class Building3 {

  float y;
  float x;
PShape  building3;

  Building3(float tx,float ty) {
    x = tx;
    y = ty;

    building3 = loadShape("skyscraper.obj");

building3.disableStyle();
  }

  void update() {
  }

  void display() {
    pushMatrix();
    translate(x, y, 0);
  
    rotate(radians(90));
   scale(1.5);
   stroke(random(155),random(155),random(155),20);
   strokeWeight(2);
    fill(33,100,65,150);
 
    shape(building3,0,0,50,50);
    popMatrix();
  }
}
//////street light////



class Light {

  float y;
  float x;
PShape light;

  Light(float tx,float ty) {
    x = tx;
    y = ty;
    light = loadShape("streetlight.obj");

  }

  void update() {


   
  }

  void display() {
    pushMatrix();
    translate(x, y, 0);
    scale(4);
    for(int dis = -100; dis <height; dis += 50){
    //box(50,50,100);
    shape(light,0,dis,5,5);
     }
    popMatrix();
  }
}



////////snow////

class Snow {
  float angle1;
  float y;
  float x;
  float z;
  float s;
  Snow(float tx,float ty, float r, float tz,float ts){
    x = tx;
    y=ty;
    angle1 = r;
    z = tz;
    s =ts;
  }
 
  void update(){
   
      angle1+= 1;
      z += -5;;
      if(z <= -100){
        z = 1000;
      }
  }
  void display(){
  pushMatrix();
   translate(x, y,z);
  rotateX(radians(angle1));
   rotateZ(radians(angle1));
    rotateY(radians(angle1));
  fill(255);
  noStroke();
 sphere(s);
  popMatrix();
}
}


I try to create two scenes in separate sketch, and put them together into one sketch.
However, when I set a condition to change the scene such as the car move to a point and the countryside scene will change to urban scene, the screen is frozen and it does not work.
Therefore, I just show  two scenes separately.
One more problem is I want to set a camera as the car, but it does not really work.



Comments

Popular posts from this blog

Reverse Eng. Object: HD Render and Exploded View

Procedural Motion