/
train.go
37 lines (31 loc) · 848 Bytes
/
train.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package effects
import (
"github.com/gca3020/adalight"
"image/color"
)
// Train is a simple effects that lights up every light in sequence a fixed number of times
type Train struct {
color color.Color
repeats int
strip *adalight.Strip
}
// NewTrain builds and returns a new Train Effect
func NewTrain(c color.Color, r int) (f *Train) {
return &Train{color: c, repeats: r}
}
// Init initializes this Effect, passing it the Strip
func (t *Train) Init(s *adalight.Strip, _ int) string {
t.strip = s
return "Train"
}
// Frame populates the pixels in the strip passed during initialization
func (t *Train) Frame(num int) bool {
// Set the strip to black
t.strip.SetAllRGB(color.RGBA{})
// Light up the single pixel
if num < t.repeats*t.strip.Length() {
t.strip.Set(num%t.strip.Length(), t.color)
return false
}
return true
}