Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : how do you put a counter on any array?

$
0
0
I don't use that library, but it looks like what you are looking for is modulo: http://processing.org/reference/modulo.html

Use it like this:
  1. int index = 0;

  2. // A sample list in alphabetic order to show modulo working below
  3. String[] example = {
  4.   "Apple", "Banana", "Cranberry", "Durian", "Entawak"
  5. };

  6. void setup() {
  7.   size(100, 100);
  8. }

  9. void draw() {
  10.   int loopedIndex = (index % example.length);
  11.   println(index+", "+example[loopedIndex]);
  12.   index++;
  13. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles