-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.go
58 lines (46 loc) · 995 Bytes
/
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
package tunnel
import (
"context"
"math"
"github.com/lucasepe/doodlekit"
)
func Scene() doodlekit.Scene {
return &scene{}
}
type scene struct {
t float64
w, h int
speed float64
colors []int
}
func (s *scene) Init(ctx context.Context) {
gc := doodlekit.Canvas(ctx)
s.speed = 2
s.colors = []int{4, 5, 2}
s.w = gc.Width()
s.h = gc.Height()
}
func (s *scene) Update(ctx context.Context, _ float64) {
s.t += s.speed
}
func (s *scene) Draw(ctx context.Context) {
halfW, halfH := s.w/2, s.h/2
gc := doodlekit.Canvas(ctx)
gc.Translate(float64(halfW), float64(halfH))
for y := -halfH; y <= halfH; y++ {
for x := -halfW; x <= halfW; x++ {
a := float64(s.t)/16 + (math.Atan2(float64(y), float64(x))+math.Pi)*2.546
d := 222 / math.Sqrt(float64(x*x+y*y))
q := s.colors[int(a*12/16)%len(s.colors)]
var c int
if d > 1.3*float64(s.h) {
c = 1
} else {
c = q ^ int((d+float64(s.t)/4))%3
}
gc.Color(c)
gc.Pix(x, y)
}
}
gc.Identity()
}