Displaying from an array

Oh wow, thank you and here I was just about to hit the bed all defeated…

So, I was just sticking to using arrays cause it’s like this learning thing where I must absolutely work within the constraints given, or it’s just plain stupidity sorry!

Although I’ve got the result, I’ve also managed to confuse myself a bit and I’m not entirely sure if it works exactly in the way I wanted, but along the way, I’ve also learned about intervals.

I’m sure it’d all clear up once I get more experience with all that intervals stuff I guess. Anyway, here’s the abomination I came up with :grin:

var range = [];

function setup() {
  createCanvas(400, 400);
  textAlign(CENTER, CENTER);
  textSize(24);
  populateArray(10);
  sequence();
}

function populateArray(limit) {
  for (i = limit; i > 0; i--) {
    range.push(i);
  }
}

var sequence = function() {
  for (var j = 20; j >= 0; j--) { // j = 20 is arbitrary, just wanted to knw if the loop was running in relation to the array and not something else!
    setTimeout(j => {
      background(204),
        text(range.length--, 200, 200)
    }, 1000 * j);
  }
}
1 Like