/
main.go
59 lines (48 loc) · 935 Bytes
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"image/color"
"math/rand"
"time"
"tinygo.org/x/drivers/microbitmatrix"
)
var display microbitmatrix.Device
func main() {
display = microbitmatrix.New()
display.Configure(microbitmatrix.Config{})
display.ClearDisplay()
x := int16(1)
y := int16(2)
deltaX := int16(1)
deltaY := int16(1)
then := time.Now()
c := color.RGBA{255, 255, 255, 255}
for {
if time.Since(then).Nanoseconds() > 80000000 {
then = time.Now()
pixel := display.GetPixel(x, y)
if pixel {
display.ClearDisplay()
x = 1 + int16(rand.Int31n(3))
y = 1 + int16(rand.Int31n(3))
deltaX = 1
deltaY = 1
if rand.Int31n(2) == 0 {
deltaX = -1
}
if rand.Int31n(2) == 0 {
deltaY = -1
}
}
display.SetPixel(x, y, c)
x += deltaX
y += deltaY
if x == 0 || x == 4 {
deltaX = -deltaX
}
if y == 0 || y == 4 {
deltaY = -deltaY
}
}
display.Display()
}
}