[SOLVED] Problem setting color

hello,

i am facing a problem i can’t solve.

i am creating a matrix of plain circles which i assign a color.

i defined a method in my Ball class which i use to set a color in ball setup :

ball::setup(float x, float y, float radius, ofColor c);

This method is written like follows :

void ball::setup(float x, float y, float r, ofColor col) {
    pin = ofPoint(x, y);
    position = pin;
    radius = r;
    velocity = ofPoint(0, 0);
    areaRadius = 25;
    dist = ofPoint(0,0);
    color.set(col);
}

i setup every ball like so :

this one works fine

balls.back().setup(x * ballRadius * 2, y * ballRadius * 2, ballRadius, ofColor(ofRandom(16), ofRandom(16), ofRandom(16)));

but now i want to use an image to define each circle color :

in my ofApp::setup()

if(!image.loadImage("test.jpg")) cout << "error loading image" << endl;
image.resize(nbX, nbY);

then i setup each circle color

balls.back().setup(x * ballRadius * 2, y * ballRadius * 2, ballRadius, image.getColor(x, y));

this doesn’t work. I have only white circles.

How come ?

I tried

ofImage img;
img.allocate(nbX, nbY, OF_IMAGE_COLOR);
for (int y = 0; y < nbY; y++) {
    for (int x = 0; x < nbX; x++) {
        img.setColor(x, y, image.getColor(x, y));
    }
}
img.resize(1024, 768);
img.draw(0, 0);

to see if i understand how ofImage works. And that seems ok.
Still have the issue i don’t understand.
Maybe some other part in the code.

here you can see the code

https://github.com/martialgallorini/springBounce/tree/silhouette-install

thanks a lot

I think i have tried everything i was thinking of but with no luck.
Whatever i am testing it runs ok.
When i set the color using

image.getColor(x, y);

every circles are white.

I must be doing something wrong or missing something but i can’t figure out what !

help much appreciated.

thanks a lot.

This is really weird, have you tried simplifying your ball::draw function? You can also cout the image.getColor to see if it’s really white. I’d also try loading the png instead of the jpg image… I’ve had problems with jpgs before… hope it helps

damn it !
as expected, the problem stands between the keyboard and the chair…

what i did :

setupMatrix();

image.loadImage("sign.png");
image.resize(nbX, nbY);

better like this :

image.loadImage("sign.png");
image.resize(nbX, nbY);

setupMatrix();

thanks a lot.

1 Like