I should somehow initialize the array list here ??? // kind of lost here
there are different ways :
valid:
before setup() :
color[] grays = new color [5];
in setup() :
grays [0] = #FFFFFF;
grays [1] = #BEBEBE;
grays [2] = #7F7F7F;
grays [3] = #3F3F3F;
grays [4] = #000000;
or like this
color[] grays = {
#FFFFFF,
#BEBEBE,
#7F7F7F,
#3F3F3F,
#000000
};
Full Code
color[] grays = {
#FFFFFF,
#BEBEBE,
#7F7F7F,
#3F3F3F,
#000000
};
float deg = 90; // 90 degrees
float rad = radians(deg); // convert to radians
void setup() {
size(400, 400);
frameRate(1);
}
void draw() {
background (127);
noStroke();
float r = random(1);
// println (r);
translate (200, 200);
if (r < 0.40) {
rotate (rad);
} else if (r > 0.40 && r < 0.50) {
rotate (rad*3);
} else if (r > 0.50 && r < 0.65) {
rotate (rad*2);
} else {
rotate (rad*4);
}
// Would like a random selection from gray array list
int index = int(random(grays.length));
println(index);
fill(grays[index]);
// rect
rectMode (CENTER);
rect (0, 0, 200, 200);
arc (0, -100, 200, 200, 0, PI);
}