Smoothing variables and changing objects over time

Hello All,

I have a couple of questions. Probably pretty simple. But I am still not that great at coding, and learning.

First question. I am looking to be able to basically smooth a number. Mostly like a fade value that even if the variable jumps from 0-255, it will take 3 seconds (set via another variable) to fade the number between that.

Second question. Say I had an image, and wanted to move the image from left to right over 3 seconds (set by another variable). How would I do something like that?

Thanks in advance

OF has built in functions for what you’re trying to do: just give a look at ofMap() and ofLerp() in the documentation page.

First answer:

//set your time range in milliseconds  
minTime = 0;  
maxTime = 3000;  
//set you value range  
minValue = 0;  
maxValue = 255;  
//check the current time  
curTime = ofGetElapsedTime()-lastStop;  
smoothVar = ofMap(curTime, minTime, maxTime, minVal, maxVal);  

Second answer: it’s exactly the same :slight_smile:

Awesome! I knew it had to be in there and I just missed it. Thank you very much!!