Randomly select color from a list of preset colors
in
Programming Questions
•
9 months ago
Hey, complete noob here. I'm trying to create a pixel grid that is composed of a set of preselected colors, and that randomly distributes these colors throughout the grid. here is some code that I have already written, hopefully this will help to illustrate what I am trying to do:
float x = 0;
while(x<width) {
float y = 0;
while(y<height) {
if (random(100)> 50) { //50% chance that the square will be grayscale
fill( random(40, 200), random(30, 200), random(200));}
else{
fill(random(50, 250));
}
rect(x, y, 40, 40);
y = y + 40;
}
x = x + 40;
}
Currently, my program selects randomly from a spectrum of colors, and this is not what I want. Any help is greatly appreciated.
1