Here's my situation. I'm using Processing 2.0, and I'm trying to make a grid of squares turned at a 45-degree angle. Each square will be filled with a color chosen randomly from a palette of five. My problem is this; for some reason, when I use COLORS[int(random(COLORS.length))]
to get a color from my palette, I only get black! It's doubly weird because black is not one of the colors in my palette! I have tested my floodFill()
function, and I can confirm that it works, as testing with a single color not pulled from an array works all right. Any tips? My code is as follows:
final int DX = 16, DY = DX;
final color DEFAULT_BG = color(50, 50, 50);
final color[] COLORS = {
color(#ff3333),
color(#4fff55),
color(#585eff),
color(#ebff55),
color(#FF55D5),
};
void setup() {
size(800, 480);
background(DEFAULT_BG);
noSmooth();
for (int x = 0; x < width; x += DX) {
for (int y = 0; y < height; y += DY) {
line(x, y, x + 16, y + 16);
line(x + 16, y, x, y + 16);
}
}
for (int x = 0; x < width; x += 4) {
for (int y = 0; y < height; y += 4) {
if (get(x, y) == DEFAULT_BG) {
color f = COLORS[int(random(COLORS.length))];
floodFill(x, y, DEFAULT_BG, color(f));
}
}
}
}
void floodFill(final int x, final int y, final color from, final color to) {
if (!(x < 0 || y < 0 || x >= width || y >= height || from == to || get(x, y) != from)) {
set(x, y, to);
floodFill(x, y + 1, from, to);
floodFill(x, y - 1, from, to);
floodFill(x + 1, y, from, to);
floodFill(x - 1, y, from, to);
}
}
When I replace the #rrggbb
notation with 0xrrggbb
, I get white instead. When I replace it with 0xrrggbbaa
, I get black and white (not grayscale).
Now using the standard color(r, g, b)
notation works fine. However, I'd still like to know what breaks the hexadecimal versions, so I'll leave this question open.