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.

30 lines
708 B

1 year ago
2 years ago
2 years ago
  1. package effects
  2. import (
  3. "fmt"
  4. "git.aiterp.net/lucifer3/server/device"
  5. "math/rand"
  6. "time"
  7. )
  8. type Random struct {
  9. States []device.State `json:"states"`
  10. Interpolate bool `json:"interpolate"`
  11. AnimationMS int64 `json:"animationMs"`
  12. }
  13. func (e Random) State(_, _, _ int) device.State {
  14. if len(e.States) == 0 {
  15. return device.State{}
  16. }
  17. return gradientStateFactor(e.States, e.Interpolate, rand.Float64())
  18. }
  19. func (e Random) Frequency() time.Duration {
  20. return time.Duration(e.AnimationMS) * time.Millisecond
  21. }
  22. func (e Random) EffectDescription() string {
  23. return fmt.Sprintf("Random(states:%s, anim:%dms, int:%t)", statesDescription(e.States), e.AnimationMS, e.Interpolate)
  24. }