Question about Draw Arrays

Hi Blake,

Can you please format your code in our previous post? You can find all the informations on this thread: Guidelines—Tips on Asking Questions

To get back to your question, you can probably adopt a structure like this one:

ArrayList<Image> images; // An array to keep track of the images
boolean lastStateIsMoving; // The last state of your sensor

void setup() {
  size(640, 360);
  
  images = new ArrayList<Image>();
  lastStateIsMoving = false;
}

void draw() {
  background(255);
  
  boolean movements = readSensorValue(); // Check if your sensor read movements
  
  if (movements && !lastStateIsMoving) { // if there is a movement and the previous state of the sensor was no movement
    images.add(new Image(...));
  }
  
  if (!movements && lastStateIsMoving) { // if there is no movement and the previous state of the sensor was movement
    images.get(0).changeState(2);
  }
  
  for (int i = 0; i < images.size(); i++) {
    if (images.get(i).isOutOfScreen()) {
      images.remove(i);
    } else {
      images.get(i).update();
      images.get(i).display();
    }
  }
}


boolean readSensorValue() {
  // TO DO
}


class Image {
  PImage img;
  PVector pos;
  int state;
  
  Image(PImage img) {
    // TO DO
    state = 1;
    pos = new PVector(width/2, random(height));
  }
  
  void update() {
    if (state == 1) { // scaling state
      scaleUp();
    }
    
    if (state == 2) { // moving left
      moveRight();
    }
  }
  
  void changeState(int newState) {
    // TO DO
  }
  
  void scaleUp() {
    // TO DO
  }
  
  void moveRight() {
    // TO DO
  }
  
  boolean isOutOfScreen() {
    // TO DO
  }
  
  void display() {
    // TO DO
  }
}