16 lines
736 B
Go
16 lines
736 B
Go
|
package patterns
|
||
|
|
||
|
// gradient returns from fromX to toX fading from (fromR,fromG,fromB) to (toR,toG,toB)
|
||
|
// at least that's the idea.
|
||
|
func Gradient(fromR byte, fromG byte, fromB byte, toR byte, toG byte, toB byte, fromX int, toX int) []byte {
|
||
|
ret := make([]byte, toX*3)
|
||
|
var stepR float32 = (float32(toR) - float32(fromR)) / (float32(toX) - float32(fromX))
|
||
|
var stepG float32 = (float32(toG) - float32(fromG)) / (float32(toX) - float32(fromX))
|
||
|
var stepB float32 = (float32(toB) - float32(fromB)) / (float32(toX) - float32(fromX))
|
||
|
for i := fromX; i < toX*3; i += 3 {
|
||
|
ret[i] = fromR + byte(float32(i/3)*stepR)
|
||
|
ret[i+1] = fromG + byte(float32(i/3)*stepG)
|
||
|
ret[i+2] = fromB + byte(float32(i/3)*stepB)
|
||
|
}
|
||
|
return ret
|
||
|
}
|