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.

43 lines
1.1 KiB

1 year ago
1 year ago
1 year ago
  1. package effects
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "time"
  6. )
  7. type Solid struct {
  8. States []device.State `json:"states"`
  9. AnimationMS int64 `json:"animationMs"`
  10. Interleave int `json:"interleave"`
  11. }
  12. func (e Solid) State(_, length, round int) device.State {
  13. if len(e.States) == 0 {
  14. return device.State{}
  15. }
  16. if len(e.States) == 1 {
  17. return e.States[0]
  18. }
  19. interleave := e.Interleave + 1
  20. if interleave < 1 {
  21. interleave = 1
  22. }
  23. if interleave > 1 {
  24. calcIndex := round % (len(e.States) * interleave)
  25. return gradientState(append(e.States, e.States[0]), e.Interleave != 0, calcIndex, len(e.States)*interleave+1)
  26. } else {
  27. calcIndex := round % len(e.States)
  28. return gradientState(e.States, e.Interleave != 0, calcIndex, len(e.States)*interleave)
  29. }
  30. }
  31. func (e Solid) Frequency() time.Duration {
  32. return time.Duration(e.AnimationMS) * time.Millisecond
  33. }
  34. func (e Solid) EffectDescription() string {
  35. return fmt.Sprintf("Solid(states:%s, anim:%dms, interleave:%d)", statesDescription(e.States), e.AnimationMS, e.Interleave)
  36. }