# Question about Draw Arrays

**URL:** <https://discourse.processing.org/t/question-about-draw-arrays/5270>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [November 6, 2018, 6:35pm UTC](https://discourse.processing.org/t/question-about-draw-arrays/5270 "2018-11-06T18:35:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [November 6, 2018, 6:59pm UTC](https://discourse.processing.org/t/question-about-draw-arrays/5270/2 "2018-11-06T18:59:35Z")

</div>

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](https://discourse.processing.org/t/guidelines-tips-on-asking-questions/2147)

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

```auto
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
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/question-about-draw-arrays/5270)._
