-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.go
72 lines (56 loc) · 1.06 KB
/
scene.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
60
61
62
63
64
65
66
67
68
69
70
71
72
package glitters
import (
"context"
"math"
"github.com/lucasepe/doodlekit"
)
func Scene(total int) doodlekit.Scene {
return &scene{
total: total,
}
}
type scene struct {
w, h int
total int
colors []int
time float64
}
func (s *scene) Init(ctx context.Context) {
gc := doodlekit.Canvas(ctx)
s.w, s.h = gc.Width(), gc.Height()
if s.total < 0 {
s.total = 40
}
if s.total > 2*s.w {
s.total = s.w
}
s.colors = []int{1, 1, 2, 2, 4, 2, 6, 7, 4, 5, 10, 4, 2, 2, 9, 11}
s.time = 0
}
func (s *scene) Update(ctx context.Context, _ float64) {
s.time += 2
}
func (s *scene) Draw(ctx context.Context) {
rng := doodlekit.Rng(ctx)
gc := doodlekit.Canvas(ctx)
for i := 0; i < s.total; i++ {
x, y := rng.RndI(0, s.w), rng.RndI(0, s.h)
c := gc.At(x, y)
if c <= 1 {
c = int(float64(y)/60+math.Abs(math.Mod(float64(x), 32)-16)/60+s.time) % 2
k := 0.2
if c == 0 {
k = 0.8
}
if rng.Rnd(0, 1) < k {
c = 4
} else {
c = 12
}
} else if rng.Rnd(0, 2) < 1 {
c = s.colors[c]
}
gc.Color(c)
gc.Circ(int(x), int(y), 1)
}
}