# Trying to achieve Time delay color

hello, i’m totally new to openframeworks. I’ve a good background with processing and i’m very interested in computer vision that why i decided to shift to OF.
anyhow, I’m trying to achieve Time delay color but no luck.
is there any code for this? or any similar effect?
also, can i link it with Realsense camera?

sorry if my questions are pretty dumb but all the books out there is kinda outdated

thanks

You mean, fading from grayscale to color, or from color to color, over time?

I don’t know of a method or extension that does that for you, but you can code it yourself.

I have done it by calculating the change in color values per time or per tick, and then changing the color every frame in the Update function, and redrawing it every frame in the Draw function.

From color to color. Can you tell me where to start? Links perhaps or key words?

Hello Fai,

This is probably one of the least optimal solutions, but it has worked for me most of the time.
Haven’t tested this one yet, so there might be some bugs. But it’s simple enough and the idea is there. I hope it helps.

/////////////////////////////ofApp.h
#include “ofMain.h”

class ofApp : public ofBaseApp
{
public:
void setup();
void update();
void draw();

``````	   float lerpPercent;
float cycleDuration;

ofColor colorFrom;
ofColor colorTo;
``````

};

/////////////////////////////ofApp.cpp
#include “ofApp.h”

void ofApp::setup()
{
colorFrom = ofColor::yellow;
colorTo = ofColor::red;

``````lerpPercent = 0.0f;
cycleDuration = ofGetElapsedTimef();
``````

}

void ofApp::update()
{
lerpPercent = (sin( ofGetElapsedTimef()-cycleDuration ));

``````colorFrom.lerp( colorTo, lerpPercent);

if(lerpPercent >= 0.99f)	//Morphing Complete. Now reset
{
lerpPercent = 0.0f;
cycleDuration   =   ofGetElapsedTimef();
}
``````

}

void ofApp::draw()
{
ofFill();
ofSetColor(colorFrom);
//
//Draw stuff here
//
}

Inceptionizta81 just posted an example of the type of thing I meant.

I’m not sure what aspects might not be clear to you.

OpenFrameworks calls Setup once when your program starts, and then calls Update and the Draw over and over many times (typically 60) per second. So if you want an effect over time, you draw something in the Draw function that uses variables whose values you update each time, generally in Update.

you can try this add-on to create a gradient adding some colors, then you can get the color on a percent of the full gradient:

``````ofxColorGradient<ofColor> gradient;

//first, fill in the gradient with colors, left to right