Learner: What am I doing wrong?
in
Programming Questions
•
1 year ago
The following code is supposed to give me a window of red, green and blue pixels but it just gives a white picture. What am I doing wrong? Changing the size gives all blue, or green and blue but no red. When the 'print' line is enabled it gives a series of random 0's, 1's and 2's so that's working properly.
size(40, 20);
loadPixels();
float rand = random(3);
int j = 0;
for (int i = 0; i < pixels.length; i++) {
rand = random(3);
j = int(rand);
//print (j);
if (j == 0);
{
pixels[i] = color (255, 0, 0);
}
if (j == 1);
{
pixels[i] = color (0, 255, 0);
}
if (j == 2); {
pixels[i] = color (0, 0, 255);
}
}
loadPixels();
float rand = random(3);
int j = 0;
for (int i = 0; i < pixels.length; i++) {
rand = random(3);
j = int(rand);
//print (j);
if (j == 0);
{
pixels[i] = color (255, 0, 0);
}
if (j == 1);
{
pixels[i] = color (0, 255, 0);
}
if (j == 2); {
pixels[i] = color (0, 0, 255);
}
}
updatePixels();
1