Weirdness with Color variable
in
Programming Questions
•
2 months ago
Ok here's one that for the life of me I can't figure out. Take the following code:
BUT - if I comment out the fill on 24 and uncomment the fill on 23, the ellipses drawn become invisible. I confirmed that they were actually drawing by putting the stroke(255) into setup(). Obviously clr has valid color data because the r,g,b variables are correctly populated with the appropriate values.
So what am I missing? Why does fill(clr) result in the creation of invisible ellipses?
Best Regards, Jim
- String inputFile="someImageBiggerThanTheScreen.jpg";
- PImage img;
- int x, y;
- color clr;
- float r,g,b;
- void setup() {
- img = loadImage(inputFile);
- size(1200,800);
- stroke(255); // just to prove that an ellipse is actually being drawn
- }
- void draw() {
- if(frameCount==1) {
- image(img, 0, 0,width,height); // puts the image on screen - works
- loadPixels(); // loads the pixel array - appears to work
- }
- x = int(random(width-1)); // grab a random x
- y = int(random(height-1)); // grab a random y
- int i = int(x + (y*width)); // get the pixel array location
- clr = pixels[i]; // pixel is supposed to have a color datatype so put it in the color variable clr
- r=red(clr); g=green(clr); b=blue(clr); // just for grins, grab the r,g,b components
- //println(x+","+y+" --> "+r +","+g+","+b);
- //fill(clr);
- fill(r,g,b);
- ellipse(x,y,70,70);
- }
BUT - if I comment out the fill on 24 and uncomment the fill on 23, the ellipses drawn become invisible. I confirmed that they were actually drawing by putting the stroke(255) into setup(). Obviously clr has valid color data because the r,g,b variables are correctly populated with the appropriate values.
So what am I missing? Why does fill(clr) result in the creation of invisible ellipses?
Best Regards, Jim
1