add pattern effects.

This commit is contained in:
2022-08-19 00:18:09 +02:00
parent fd898050bf
commit 8c7f1c6ffc
2 changed files with 54 additions and 4 deletions
+24
View File
@@ -0,0 +1,24 @@
package effects
import (
"fmt"
"git.aiterp.net/lucifer3/server/device"
"time"
)
type Pattern struct {
States []device.State `json:"states,omitempty"`
ShiftMS int64 `json:"shiftMs,omitempty"`
}
func (p Pattern) State(index, round, _ int) device.State {
return p.States[(index+round)%len(p.States)]
}
func (p Pattern) Frequency() time.Duration {
return time.Duration(p.ShiftMS) * time.Millisecond
}
func (p Pattern) EffectDescription() string {
return fmt.Sprintf("Pattern(len:%d, animation:%dms)", len(p.States), p.ShiftMS)
}