Modulus
int remainder = 7 % 4;
println( remainder ); // remainder is 3 anyNumber % arrayLength == valid array index Modulus Code Example - Array indexes:
color[] colors;
void setup(){
size( 400, 400);
colorMode(HSB, 360, 100, 100);
colors = new color[3];//initilize: how many elements
colors[0] = color( 100, 100, 100);
colors[1] = color( 200, 100, 100);
colors[2] = color( 300, 100, 100);
}
void draw(){
frameRate(2);
int index = frameCount % 3;
color tempColor = colors[index];
fill(tempColor);
rect( 0,0,width, height);
println(frameCount);
}Last updated