weird behavior analyzing pixels to get color
in
Programming Questions
•
10 months ago
I can't understand why i can't get the right color from the image when look for it within draw;
I expect to have every new ellipse filled with the color of the corresponding pixels in the reference image, as I always used to.
Any advice? Please It's been two days now I'm struggling with this and It's driving me crazy!!!!!
- PImage imgref;
- // int totpix;
- void setup() {
- imgref = loadImage("http://www.outsidernews.net/wp-content/uploads/2012/07/giocatori_carte_cezanne.jpg");
- size(imgref.width, imgref.height);
- background(0);
- //totpix = imgref.width *imgref.height;
- noStroke();
- frameRate(200);
- setImageAsEllipses();
- }
- void draw() {
- for (int i=0; i< 20; i++) {
- float x = random(width);
- float y = random(height);
- if (x>0 && x<width-1 && y>0 && y<height-1) {
- int loc = int((x + y * imgref.width));
- color c = imgref.pixels[loc];
- fill(c);
- ellipse(x, y, 2, 2);
- }
- }
- }
- void setImageAsEllipses() {
- for (int x=0; x<imgref.width; x++) {
- for (int y=0; y<imgref.height; y++) {
- int i= x + y*imgref.width;
- color c = imgref.pixels[i];
- fill(c);
- ellipse(x, y, 1, 1);
- }
- }
- }
1