Programming falling Domino bricks with delay in Processing

Viewed 28

I'm very new to Processing and coding in general and trying to program a row of falling Domino bricks activated by an ellipse. I have programmed a function for the bricks standing upright and one for the fallen bricks, but I can only get the bricks to fall all at the same time. I'm looking for a way to make them fall one after the other. It would be great if someone could help me out.

This is my Code so far - First tab:

Dom[] dominos = new Dom[20];
int m;
float x = 100;

void setup() {
  size (600, 600);
  for (int i=0; i < dominos.length; i++) {
    dominos[i] = new Dom();
  }
}

void draw() {
  background(0);

  if (m<91) {
    m = m + 1;
  }

  fill(0);
  ellipse(m, height/2 + 15, 20, 20);

  fill(255, 80, 0);
  ellipse (m, height/2 + 15, 20, 20);

  for (int i=0; i < dominos.length; i++) {
    if (m < 90)
      dominos[1].show();

    if (m >= 90)
      dominos[i].fall();
  }
}

Second tab:

class Dom {
  float x = 100;
  float y = height/2 - 22.5;

  void fall() {
    push();
    stroke(255);
    strokeWeight(10);
    strokeCap(SQUARE);

    for (int i = 0; i<15; i++) {
      line (x + i*30 + 45, y+40, x + i *30, y+50);
    }
    pop();
  }

  void show() {
    push();
    stroke(255);
    strokeWeight(10);
    strokeCap(SQUARE);

    for (int i = 0; i<15; i++) {
      line (x + i*30, y, x + i *30, y+45);
    }
    pop();
  }
}``
0 Answers
Related