You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
892 B

2 years ago
2 years ago
2 years ago
2 years ago
  1. package effects
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "time"
  6. )
  7. type Gradient struct {
  8. States []device.State `json:"states,omitempty"`
  9. AnimationMS int64 `json:"AnimationMs,omitempty"`
  10. Reverse bool `json:"backward,omitempty"`
  11. Interpolate bool `json:"interpolate,omitempty"`
  12. }
  13. func (e Gradient) State(index, length, round int) device.State {
  14. if len(e.States) == 0 {
  15. return device.State{}
  16. }
  17. if e.Reverse {
  18. round = -round
  19. }
  20. walkedIndex := ((length + index) - round) % length
  21. return gradientState(e.States, e.Interpolate, walkedIndex, length)
  22. }
  23. func (e Gradient) Frequency() time.Duration {
  24. return time.Duration(e.AnimationMS) * time.Millisecond
  25. }
  26. func (e Gradient) EffectDescription() string {
  27. return fmt.Sprintf("Gradient(states:%s, anim:%dms, int:%t)", statesDescription(e.States), e.AnimationMS, e.Interpolate)
  28. }