Files
Server/effects/gradient.go
2023-10-06 13:15:19 +02:00

36 lines
862 B
Go

package effects
import (
"fmt"
"git.aiterp.net/lucifer3/server/device"
"time"
)
type Gradient struct {
States []device.State `json:"states"`
AnimationMS int64 `json:"animationMs"`
Reverse bool `json:"reverse"`
Interpolate bool `json:"interpolate"`
}
func (e Gradient) State(index, length, round int) device.State {
if len(e.States) == 0 {
return device.State{}
}
if e.Reverse {
round = -round
}
walkedIndex := ((length + index) - (round % length)) % length
return gradientState(e.States, e.Interpolate, walkedIndex, length)
}
func (e Gradient) Frequency() time.Duration {
return time.Duration(e.AnimationMS) * time.Millisecond
}
func (e Gradient) EffectDescription() string {
return fmt.Sprintf("Gradient(states:%s, anim:%dms, int:%t)", statesDescription(e.States), e.AnimationMS, e.Interpolate)
}