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.

28 lines
636 B

  1. package effects
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "time"
  6. )
  7. type Pattern struct {
  8. States []device.State `json:"states,omitempty"`
  9. AnimationMS int64 `json:"animationMs,omitempty"`
  10. }
  11. func (e Pattern) State(index, _, round, _ int) device.State {
  12. if len(e.States) == 0 {
  13. return device.State{}
  14. }
  15. return e.States[(index+round)%len(e.States)]
  16. }
  17. func (e Pattern) Frequency() time.Duration {
  18. return time.Duration(e.AnimationMS) * time.Millisecond
  19. }
  20. func (e Pattern) EffectDescription() string {
  21. return fmt.Sprintf("Pattern(states:%s, anim:%dms)", statesDescription(e.States), e.AnimationMS)
  22. }