How can I cycle through hex color codes in PHP?

前端 未结 9 2245
野的像风
野的像风 2021-01-06 06:08

I want an array where each field in the array contains a color code

array(0 => \'#4CFF00\', 1 => \'#FFE97F\')

And I want this to go t

9条回答
  •  梦谈多话
    2021-01-06 06:35

    I recommend writing a function to do this. If you need to go between multiple colors, just call it multiple times and concatenate the arrays.

    Psuedocode: `colorRange(arrayReference, startColor, endColor, numSteps)`
    
    Get {R, G, B} startColor and endColor
    Get R_diff, G_diff, and B_diff
    
    for i in 0 to numSteps {
       arrayReference.append(
              i => {min(startR, endR) + (R_diff * (i / numSteps)),
                    min(startG, endG) + (G_diff * (i / numSteps)),
                    min(startB, endB) + (B_diff * (i / numSteps))}
              )
    }
    

提交回复
热议问题