Blend object colors

Hello,

I want to blend colors but i don’t know how !

Basically i have a circle with a color. I want to change its color by blending another color to it.

How would i achieve that ?

Well i was able to blend colors but by drawing the circle twice ! There must be a cleaner and more optimized solution i guess…

void ball::draw() {
    ofPushMatrix();
    ofSetColor(ballColor);
    ofCircle(position, radius);
    ofEnableBlendMode(OF_BLENDMODE_SCREEN);
    ofSetColor(ofMap(dist.x + dist.y, -10, 10, 40, 200, true));
    ofCircle(position, radius);
    ofDisableBlendMode();
    ofPopMatrix();
}

Try calling lerp on the color.

ofColor tcolor( 255, 0, 0 );
ofColor bcolor( 255, 0, 255 );
tcolor.lerp( bcolor, sin( ofGetElapsedTimef() ) * 0.5 + 0.5 );
ofSetColor( tcolor );

hello @NickHardeman

yes this is working thanks

but i was looking for something more like regular blending modes like Add, Multiply or Screen…
Strange that there is no easy blending method like

ofColor a(r, g, b);
ofColor b(r1, g1, b1);
ofColor c = a.blend(b, blend_mode);

The only solution i found is to encode the blend formula i needed

void ball::draw() {
    ofColor color = ofColor(ofRandom(16), ofRandom(16), ofRandom(16));
    ofColor c = ofColor(ofMap(dist.x + dist.y, -10, 10, 40, 200, true));
    // formula for color SCREEN blend mode
    ofSetColor(ofColor(255) - (((ofColor(255) - c)*(ofColor(255) - color))/ofColor(255)));
    ofCircle(position, radius);
}

If anyone has another solution…

thanks