Initial random selection influences the probability of future choices
in
Programming Questions
•
9 months ago
Hey, so I have three sets of six colors each - a green set, blue set, and a brown set. I want to randomly select from one of these sets, and then randomly select a color from within that set to fill the first square in a grid.
I want the color of the second square in the grid to have a higher probability of coming from the same color set as the previous color did. So if the first color comes from the green set, I want there to be a 60% chance that the next color will also come from the green set, as opposed to 33% if it were random. Here is the code that I have written in an attempt to do this:
void setup() {
size(400, 200);
noStroke();
background(255, 255, 255);
}
color[] greencolorList = {
color(108, 171, 125), color(107, 174, 73), color(79, 184, 87), color(94, 190, 128), color(76, 184, 91),color(53, 170, 89), color(143, 194, 63)};
color[] browncolorList = {
color(72, 92, 42), color(101, 97, 41), color(65, 68, 27), color(170, 134, 86), color(155, 85, 36), color(26, 20, 73), color(145, 70, 33)};
color[] bluecolorList = {
color(111, 152, 207), color(53, 79, 162), color(54, 114, 185), color(79, 114, 144), color(50, 79, 147), color(54, 75, 160), color(54, 93, 170)};
void draw() {
for (int x = 0; x < width; x += 0) {
for (int y = 0; y < height; y += 0) {
int[][] allcolor = {greencolorList, browncolorList, bluecolorList, greencolorList}; //original selection array
int[][] greenarray = {greencolorList, browncolorList, bluecolorList, greencolorList};
int[][] bluearray = {greencolorList, browncolorList, bluecolorList, bluecolorList};
int[][] brownarray = {greencolorList, browncolorList, bluecolorList, browncolorList};
int [][] z = allcolor;
int RandomNum = (int)random(a);
int randomChoice = z[RandomNum][(int) random(7)];
String p = "green";
if (p.equals("green")) {
if (RandomNum == 0) {
z = greenarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "green";}
else {
if (RandomNum == 1) {
z = brownarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "brown";}
else{
if (RandomNum == 2) {
z = bluearray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "blue";}
else{
if (RandomNum == 3) {
z = greenarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "green";;}
}
}
}
}
if (p.equals("blue")) {
if (RandomNum == 0) {
z = greenarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "green";}
else {
if (RandomNum == 1) {
z = brownarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "brown";}
else{
if (RandomNum == 2) {
z = bluearray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "blue";}
else{
if (RandomNum == 3) {
z = bluearray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "blue";}
}
}
}
}
if (p.equals("brown")) {
if (RandomNum == 0) {
z = greenarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "green";}
else {
if (RandomNum == 1) {
z = brownarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "brown";}
else{
if (RandomNum == 2) {
z = bluearray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "blue";}
else{
if (RandomNum == 3) {
z = brownarray;
fill(randomChoice);
rect(x, y, 10, 10);
p = "brown";}
}
}
}
y = y + 10;
}
x = x + 10;
}
}
}
For some reason, this code only fills up part of the window with pixels, and the relationships between the colors is not visually apparent. I hope to generate recognizable relationships between the blues, greens and browns. I also want to fill the entire screen up in a solid grid of pixels instantly. Any thoughts are appreciated, I am new to this.
1