颜色渐变基本算法

// 3颜色等比线性变换  
int startColor = COLORS[colorType][0];  
int endColor = COLORS[colorType][1];  
int delaR = [AColor getRed:endColor] - [AColor getRed:startColor];  
int delaG = [AColor getGreen:endColor] - [AColor getGreen:startColor];  
int delaB = [AColor getBlue:endColor] -  [AColor getBlue:startColor];  
LONG delaTime = SYS_TIME - publicVoiceTimeCount;  
float rate = delaTime * 1.0f / (PublicVoice_TIME); // 0 - 1  
int curColor = [AColor getRGB:[AColor getRed:startColor] + delaR * rate   
                            g:[AColor getGreen:startColor] + delaG * rate    
                            b:[AColor getBlue:startColor] + delaB * rate];  

原来准备用这个做喇叭喊话的,但是由于渐变过度太平滑,效果不好,后来改成6颜色闪烁效果。

[cpp] view plain copy
// 闪烁效果  
int colors[6] = {   
    COLORS[colorType][0],   
    COLORS[colorType][1],  
    COLORS[colorType][2],  
    COLORS[colorType][3],  
    COLORS[colorType][2],  
    COLORS[colorType][1]};  
int _colorCount = (SYS_TIME - publicVoiceTimeCount) / 100; // 1000/100s一变  
if (_colorCount > colorCount) {  
    colorCount = _colorCount;  
    int index = _colorCount % 6;  
    int curColor = colors[index]; } 
原文地址:https://www.cnblogs.com/Free-Thinker/p/5569817.html