我需要逐步插入或更改一系列颜色,因此它从 colorA 到 colorB 再到 colorC 再到 colorD 并返回到 colorA,这需要基于以毫秒为单位的时间,任何帮助将不胜感激(算法,伪代码会很棒)。
请注意,我正在使用 RGB,它可能是 0-255 或 0.0-1.0 范围。
这就是我到目前为止所拥有的,我需要在每个“timePeriod”上更改颜色,我计算经过的时间百分比并更改颜色,这段代码的问题是当它从 A 到B 到 B 到 C 等等
int millisNow = ofGetElapsedTimeMillis();
int millisSinceLastCheck = millisNow - lastTimeCheck;
if ( millisSinceLastCheck > timePeriod ) {
lastTimeCheck = millisNow;
millisSinceLastCheck = 0;
colorsIndex++;
if ( colorsIndex == colors.size()-1 ) colorsIndex = 0;
cout << "color indes: " << colorsIndex << endl;
cout << "color indes: " << colorsIndex + 1 << endl;
}
timeFraction = (float)(millisSinceLastCheck) / (float)(timePeriod);
float p = timeFraction;
colorT.r = colors[colorsIndex].r * p + ( colors[colorsIndex+1].r * ( 1.0 - p ) );
colorT.g = colors[colorsIndex].g * p + ( colors[colorsIndex+1].g * ( 1.0 - p ) );
colorT.b = colors[colorsIndex].b * p + ( colors[colorsIndex+1].b * ( 1.0 - p ) );
colorT.normalize();
提前致谢