sloppy
December 2, 2021, 9:45am
1
I’ve been trying this for a couple of days and can never seem to get it right with what I imagine would be a simple piece of syntax/code.
Each generated image’s background I want to either be between -1 to 256, and also 3 other specific RGB colors. So far, I’ve just got this:
void setup() {
size(500, 500);
background(random(-1, 256));
}
The above works fine for grayscale & W/B, but what I want to do was something that I imagined would look like this:
background(random(-1, 256)(#DC1A1A)(#1AA9DC)(#1ADC34));
Or maybe as simple as this:
background(random(-1, 256, #DC1A1A, #1AA9DC, #1ADC34));
But of course, neither of those work. I’ve looked through Reference and through topics, but I still can’t find what I imagine to be a simple line of code. Can someone please exactly tell me what it would be?
Note: This isn’t my homework
You could create a color palette array and use random() to pick an index within its length range:
// Discourse.Processing.org/t/how-to-randomly-change-the-background-color-
// between-x-amount-of-static-colors-with-each-output/33880/2
// GoToLoop [2021-Dec-02]
static final color[] PALETTE = {
0, // Black [0]
-1, // White [1]
#DC1A1A, // Vivid Red [2]
#1AA9DC, // Vivid Blue [3]
#1ADC34, // Vivid Lime Green [4]
};
void setup() {
frameRate(1);
fill(0200);
textSize(030);
textAlign(CENTER, CENTER);
println(PALETTE);
}
void draw() {
final int idx = (int) random(PALETTE.length);
final color c = PALETTE[idx];
background(c);
text(idx, width >> 1, height >> 2);
text(hex(c, 6), width >> 1, height >> 1);
}
1 Like
sloppy
December 2, 2021, 4:16pm
3
Thanks, I have seen that page already but I still don’t know how to format that with ‘background(…)’.
The length range I’ve done with -1, 256, but I’m still not getting how I format this for background with 3 other options. Thanks for the response.