/
gopher.go
53 lines (48 loc) · 988 Bytes
/
gopher.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
package main
import (
gl "github.com/chsc/gogl/gl21"
"github.com/go-gl/glfw"
)
const (
Title = "Rock Paper Scissors"
Width = 150
Height = 150
Scale = 4
)
var matrix *[][]Point
func main() {
RunGame(Title, Width*Scale, Height*Scale, func() {
gl.PointSize(1.0 * Scale)
x := 0
y := 0
dcolor := WHITE
glfw.SetMouseButtonCallback(func(button, state int) {
dcolor += 1
if dcolor > BLUE {
dcolor = WHITE
}
})
glfw.SetMousePosCallback(func(mx, my int) {
mx /= Scale
my /= Scale
if mx >= Width || my >= Height || mx < 0 || my < 0 {
return
}
x = mx
y = my
if matrix != nil && dcolor != WHITE {
(*matrix)[x][y].Color = dcolor
(*matrix)[x][y].Intensity = 10
}
})
glfw.SetKeyCallback(func(key, state int) {
matrix = makeMatrix(Width, Height)
})
matrix = makeMatrix(Width, Height)
}, func() {
matrix = NextMatrix(Width, Height, matrix)
gl.Begin(gl.POINTS)
drawMatrix(matrix, Scale, Scale)
gl.End()
})
}