top of page
  • Writer's pictureRikka Ly

Thrive Processing3 Code

Updated: Jul 24, 2023

I encourage you to try this interaction out for yourself :)


PImage bg1, bg2, bigHouse, smallHouse, nest, smallPlants, bigPlants, boat, one, two, three, smog, hand, axe;
PImage bird1, bird2, bird3, person1, person2, person3, wood1, wood2, wood3, vines1, vines2;
PImage bgCol1, bgCol2, bgCol3, cars, paper, cloudsFront, cloudsBack;
static ArrayList<people> people = new ArrayList<people>();
static ArrayList<house> smallHouses = new ArrayList<house>();
static ArrayList<house> bigHouses = new ArrayList<house>();
static ArrayList<bird> birds = new ArrayList<bird>();
static int tintA = 255;
//has the user clicked?
boolean click = false;
//is the click within an object's bounds?
boolean clickCheck = false;
boolean cloudFrontDown = true;
int removalNum = -1;
String removalArray = "";
int oneY = 320;
int twoY = 300;
int threeY = 320;
int vinesY1 = -180;
int vinesY2 = 245;
int oneH = 70;
int twoH = 75;
int threeH = 50;
int timePassed = 0;
float boatX = 625;
float cloudsFrontY = 0;
int stateSpeed = 3;

int smogOpacity = 0;
int carOpacity = 0;
int bg2Opacity = 0;
int bg3Opacity = 0;
int cloudOpacity = 0;

void setup(){
  size(1000, 1000);
  hand = loadImage("assets/cursor1.png");
  axe = loadImage("assets/cursor2.png");
  bg1 = loadImage("assets/Background1.png");
  bg2 = loadImage("assets/Background2.png");
  person1 = loadImage("assets/person1.png");
  person2 = loadImage("assets/person2.png");
  person3 = loadImage("assets/person3.png");
  smallHouse = loadImage("assets/houseSmall.png");
  bigHouse = loadImage("assets/houseBig.png");
  nest = loadImage("assets/nest.png");
  bigPlants = loadImage("assets/bigPlants.png");
  smallPlants = loadImage("assets/smallPlants.png");
  wood1 = loadImage("assets/wood1.png");
  wood2 = loadImage("assets/wood2.png");
  wood3 = loadImage("assets/wood3.png");
  boat = loadImage("assets/boat.png");
  one = loadImage("assets/flyingBirds.png");
  two = loadImage("assets/sun.png");
  three = loadImage("assets/building.png");
  bird1 = loadImage("assets/bird4.png");
  bird2 = loadImage("assets/bird5.png");
  bird3 = loadImage("assets/bird6.png");
  vines1 = loadImage("assets/vines1.png");
  vines2 = loadImage("assets/vines2.png");
  smog = loadImage("assets/smog.png");
  bgCol1 = loadImage("assets/bg1.png");
  bgCol2 = loadImage("assets/bg2.png");
  bgCol3 = loadImage("assets/bg3.png");
  cars = loadImage("assets/cars.png");
  paper = loadImage("assets/paper.jpg");
  cloudsFront = loadImage("assets/cloudsFront.png");
  cloudsBack = loadImage("assets/cloudsBack.png");

  for(int i = 0; i < 0; i++){
    people.add(new people());
  }
  for(int i = 0; i < 5; i++){
    birds.add(new bird());
  }
  for(int i = 0; i < 3; i++){
    smallHouses.add(new house(1));
  }
  smallHouses.get(0).setXY(365, 185);
  smallHouses.get(1).setXY(700, 315);
  smallHouses.get(2).setXY(610, 220);
  
  for(int i = 0; i < 2; i++){
    bigHouses.add(new house(2));
  }
  bigHouses.get(0).setXY(260, 290);
  bigHouses.get(1).setXY(445, 285);
}

void draw(){
  image(bgCol1, 0, 0);
  tint(255, bg2Opacity);
  image(bgCol2, 0, 0);
  tint(255, bg3Opacity);
  image(bgCol3, 0, 0);
  tint(255, 125);
  image(paper, 0, 0);
  
  tint(tintA, tintA, tintA);
  
  image(two, 260, twoY);
  image(one, 300, oneY);
  image(three, 280, threeY);
  //if there are 5 birds, move the first state up and the others down (if they are up)
  if(birds.size() == 5){
    timePassed += 1;
    if(vinesY1 < 90 && timePassed > 100){
      vinesY1 += 2;
    }
    if(vinesY2 < 390 && timePassed > 100){
      vinesY2 += 1;
    }
    if(oneY > oneH){
      oneY -= stateSpeed;
    }
    if(twoY < 300){
      twoY += stateSpeed;
    }
    if(threeY < 320){
      threeY += stateSpeed;
    }
    if(bg2Opacity > 0){
      bg2Opacity -= 1;
    }
    if(bg3Opacity > 0){
      bg3Opacity -= 1;
    }
  //if there are 2-3 people, move the second state up and the others down (if they are up)
  }else if(people.size() == 2 || people.size() == 3){
    timePassed = 0;
    if(cloudOpacity < 200){
      cloudOpacity += 1;
    }
    if(oneY < 320){
      oneY += stateSpeed;
    }
    if(twoY > twoH){
      twoY -= stateSpeed;
    }
    if(threeY < 320){
      threeY += stateSpeed;
    }
    if(bg2Opacity < 255){
      bg2Opacity += 1;
    }
    if(bg3Opacity > 0){
      bg3Opacity -= 1;
    }
    
    if(cloudsFrontY < 25 && cloudFrontDown == true){
        cloudsFrontY += 0.25;
      }else{
        cloudFrontDown = false;
        cloudsFrontY -= 0.25;
        if(cloudsFrontY < 0){
          cloudFrontDown = true;
        }
      }
  //if there are 5 people, move the third state up and the others down (if they are up)
  }else if(people.size() == 5){
    timePassed += 1;
    if(timePassed > 100 && smogOpacity < 200){
      smogOpacity += 1;
    }
    if(carOpacity < 255){
      carOpacity += 2;
    }
    if(oneY < 320){
      oneY += stateSpeed;
    }
    if(twoY < 300){
      twoY += stateSpeed;
    }
    if(threeY > threeH){
      threeY -= stateSpeed;
    }
    if(bg3Opacity < 255){
      bg3Opacity += 1;
    }
    
  }if(birds.size() != 5){
    if(vinesY1 > -180){
      vinesY1 -= 3;
    }
    if(vinesY2 > 245){
      vinesY2 -= 2;
    }
  }
  if(people.size() != 5 && smogOpacity > 0){
    smogOpacity -= 3;
  }
  if(people.size() != 5 && carOpacity > 0){
    carOpacity -= 3;
  }
  if((people.size() == 5 || people.size() == 4 || people.size() == 1 || people.size() == 0) && cloudOpacity > 0){
    cloudOpacity -= 3;
  }
  tint(255, cloudOpacity);
  image(cloudsBack, 0, 0);
  tint(tintA, tintA, tintA);
  image(vines1, 0, vinesY1);
  image(bg2, 0, 0);
  image(vines2, 220, vinesY2);
  image(bg1, 0, 0);
  tint(255, carOpacity);
  image(cars, 0, 0);
  tint(255, cloudOpacity);
  image(cloudsFront, 0, cloudsFrontY);
  noTint();
  
    for(int i = 0; i < smallHouses.size(); i++){
      smallHouses.get(i).display(smallHouse, bigHouse, smallPlants, bigPlants, wood1, wood2, wood3);
      
      //check if a house was clicked, if so, change the display
      if(clickCheck == false){
        clickCheck = smallHouses.get(i).clicked(click);
      }
    }
    
    for(int i = 0; i < bigHouses.size(); i++){
      bigHouses.get(i).display(smallHouse, bigHouse, smallPlants, bigPlants, wood1, wood2, wood3);
      
      //check if a house was clicked, if so, change the display
      if(clickCheck == false){
        clickCheck = bigHouses.get(i).clicked(click);
      }
    }
  
  for(int i = 0; i < birds.size(); i++){
      birds.get(i).display(nest, bird1, bird2, bird3);
  }
  
  for(int i = 0; i < people.size(); i++){
    people.get(i).display(person1, person2, person3);
      
    //check if someone was clicked, if so, remove them
    if(clickCheck == false){
      clickCheck = people.get(i).clicked(click);
    }
  }
  
  if(click == true){
    for(int i = 0; i < birds.size(); i++){
      birds.get(i).setXY();
    }
    for(int i = 0; i < people.size(); i++){
      people.get(i).setXY();
    }
  }
  
  image(boat, boatX, 350);
  
  if(click == true && mouseX > boatX && mouseX < (boatX + 108) && mouseY > 400 && mouseY < (400 + 86) && people.size() != 5){
      //add a person
      people.add(new people());
      //desaturate the background
      tintA -= 5;
      //remove a bird
      birds.remove(0);
      //turn a plant into a house
      //houseCheck is to ensure only one house gets displayed
      boolean houseCheck = false;
      while(houseCheck == false){
        for(int i = 0; i < 3; i++){
          if(smallHouses.get(i).stage == 3 && houseCheck != true){
            smallHouses.get(i).stage = 4;
            houseCheck = true;
          }
          if(i < 2){
            if(bigHouses.get(i).stage == 3 && houseCheck != true){
              bigHouses.get(i).stage = 4;
              houseCheck = true;
            }
          }
        }
      }
  }
  if((mouseX > boatX && mouseX < (boatX + 108) && mouseY > 400 && mouseY < (400 + 86) && people.size() != 5) || clickCheck == true){
    cursor(axe);
  }else{
    cursor(hand);
  }
  tint(255, smogOpacity);
  image(smog, 200, 150);
  noTint();
  //we have finished all click-related operations now
  //the click-related operations rely on this boolean, so reset it
  click = false;
  clickCheck = false;
}

void mouseClicked(){
  click = true;
}

class bird{
  int sizeX = 54;
  int sizeY = 42;
  int stage;
  int timePassed;
  float hatch = random(60, 140);
  float type = random(1, 4);
  float x = random(220, 575-sizeX);
  float y = random(450-sizeY, 500-sizeY);
  
  bird(){
    stage = 2;
  }
  void display(PImage nest, PImage bird1, PImage bird2, PImage bird3){
    if(stage == 1){
      if(type >= 1 && type <= 2){
        image(bird1, x, y);
      }else if(type >= 2 && type <= 3){
        image(bird2, x, y);
      }else if(type >= 3 && type <= 4){
        image(bird3, x, y);
      }
    //stage 2 prints a nest
    //when the time passed is 100 frames change it to stage 1
    }else{
      timePassed += 1;
      image(nest, x, y);
      if(timePassed > hatch){
        timePassed = 0;
        stage = 1;
      }
    }
  }
  void setXY(){
    //x = random(220, 575-sizeX);
    //y = random(450-sizeY, 500-sizeY);
    type = random(1, 4);
  }
}

class house{
  int sizeX;
  int sizeY;
  float x;
  float y;
  int type;
  float woodType = random(1,4);
  int stage = 3;
  int timePassed;
  
  house(int typeNum){
    type = typeNum;
    //if the type is 1, make it a small house
    if(type == 1){
      sizeX = 62;
      sizeY = 65;
    //else, make it a big house
    }else{
      sizeX = 115;
      sizeY = 113;
    }
  }
  void display(PImage smallHouse, PImage bigHouse, PImage smallPlants, PImage bigPlants, PImage wood1, PImage wood2, PImage wood3){
    //stage 1 is for printing the houses
    if(stage == 1){
      if(type == 1){
        image(smallHouse, x, y);
      }else{
        image(bigHouse, x, y);
      }
    //stage 2 prints wood
    //when the time passed is 100 frames change it to stage 3
    }else if(stage == 2){
      timePassed += 1;
      if(woodType >= 1 && woodType <= 2){
        image(wood1, x, y+50);
      }else if(woodType >= 2 && woodType <= 3){
        image(wood2, x, y+50);
      }else if(woodType >= 3 && woodType <= 4){
        image(wood3, x, y+50);
      }
      if(timePassed > 100){
        timePassed = 0;
        stage = 3;
      }
    //stage 3 prints plants
    }else if(stage == 3){
      if(type == 1){
        image(smallPlants, x-40, y);
      }else{
        image(bigPlants, x-30, y);
      }
    //stage 4 prints wood
    //when the time passed is 100 frames change it to stage 1
    }else if(stage == 4){
      timePassed += 1;
      if(woodType >= 1 && woodType <= 2){
        image(wood1, x, y+50);
      }else if(woodType >= 2 && woodType <= 3){
        image(wood2, x, y+50);
      }else if(woodType >= 3 && woodType <= 4){
        image(wood3, x, y+50);
      }
      if(timePassed > 100){
        timePassed = 0;
        stage = 1;
      }
    }
  }
  
  void setXY(int newX, int newY){
    x = newX;
    y = newY;
  }
  
  boolean clicked(boolean clickCheck){
    if(clickCheck == true && mouseX > x && mouseX < (x + sizeX) && mouseY > y && mouseY < (y + sizeY) && stage != 3){
      stage = 2;
      if(people.size() != 0){
        a3.people.remove(0);
      }
      a3.tintA += 5;
      a3.birds.add(new bird());
    }
    if(mouseX > x && mouseX < (x + sizeX) && mouseY > y && mouseY < (y + sizeY) && stage == 1){
      return true;
    }
    return false;
  }
}

class people{
  int sizeX = 29;
  int sizeY = 85;
  float type = random(1, 4);
  float x = random(220, 575-sizeX);
  float y = random(450-sizeY, 500-sizeY);
  
  people(){}
  void display(PImage person1, PImage person2, PImage person3){
    if(type >= 1 && type <= 2){
      image(person1, x, y);
    }else if(type >= 2 && type <= 3){
      image(person2, x, y);
    }else if(type >= 3 && type <= 4){
      image(person3, x, y);
    }
  }
  
  boolean clicked(boolean clickCheck){
    if(clickCheck == true && mouseX > x && mouseX < (x + sizeX) && mouseY > y && mouseY < (y + sizeY)){
      boolean houseCheck = false;
      while(houseCheck == false){
        for(int i = 0; i < 3; i++){
          if(a3.smallHouses.get(i).stage == 1 && houseCheck != true){
            a3.smallHouses.get(i).stage = 2;
            houseCheck = true;
          }
          if(i < 2){
            if(a3.bigHouses.get(i).stage == 1 && houseCheck != true){
              a3.bigHouses.get(i).stage = 2;
              houseCheck = true;
            }
          }
        }
      }
      a3.people.remove(0);
      a3.tintA += 5;
      a3.birds.add(new bird());
    }
    if(mouseX > x && mouseX < (x + sizeX) && mouseY > y && mouseY < (y + sizeY)){
      return true;
    }
    return false;
  }
  
  void setXY(){
    //x = random(220, 575-sizeX);
    //y = random(450-sizeY, 500-sizeY);
    type = random(1, 4);
  }
}

45 views0 comments

Recent Posts

See All
bottom of page