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
43 lines
1.1 KiB
package effects
|
|
|
|
import (
|
|
"fmt"
|
|
"git.aiterp.net/lucifer3/server/device"
|
|
"time"
|
|
)
|
|
|
|
type Solid struct {
|
|
States []device.State `json:"states"`
|
|
AnimationMS int64 `json:"animationMs"`
|
|
Interleave int `json:"interleave"`
|
|
}
|
|
|
|
func (e Solid) State(_, length, round int) device.State {
|
|
if len(e.States) == 0 {
|
|
return device.State{}
|
|
}
|
|
if len(e.States) == 1 {
|
|
return e.States[0]
|
|
}
|
|
|
|
interleave := e.Interleave + 1
|
|
if interleave < 1 {
|
|
interleave = 1
|
|
}
|
|
|
|
if interleave > 1 {
|
|
calcIndex := round % (len(e.States) * interleave)
|
|
return gradientState(append(e.States, e.States[0]), e.Interleave != 0, calcIndex, len(e.States)*interleave+1)
|
|
} else {
|
|
calcIndex := round % len(e.States)
|
|
return gradientState(e.States, e.Interleave != 0, calcIndex, len(e.States)*interleave)
|
|
}
|
|
}
|
|
|
|
func (e Solid) Frequency() time.Duration {
|
|
return time.Duration(e.AnimationMS) * time.Millisecond
|
|
}
|
|
|
|
func (e Solid) EffectDescription() string {
|
|
return fmt.Sprintf("Solid(states:%s, anim:%dms, interleave:%d)", statesDescription(e.States), e.AnimationMS, e.Interleave)
|
|
}
|