This repository has been archived by the owner on Aug 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
100 lines (83 loc) · 1.83 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"image/color"
"math"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
)
const (
width = 100
height = 100
scale = 4
glow = width / 5
edge = glow * 3
)
var id = 0
var (
red = color.RGBA{255, 0, 0, 255}
green = color.RGBA{0, 255, 0, 255}
light = color.RGBA{0, 255, 255, 63}
)
type Game struct {
Shapes []*Polygon
}
func (g *Game) Update(screen *ebiten.Image) error {
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
cx, cy := ebiten.CursorPosition()
for x, shape := range g.Shapes {
if shape.Contains(Point{cx, cy}) {
screen.Set(x, 0, green)
}
for i, _ := range shape.In {
d := (glow - math.Sqrt(math.Pow(float64(i[1]-cy), 2)+math.Pow(float64(i[0]-cx), 2))) / glow * 255
if d < 0 {
d = 0
}
ud := uint8(d)
col := color.RGBA{0, ud, ud, 255}
screen.Set(i[0], i[1], col)
}
for e, _ := range shape.Edge {
d := (edge - math.Sqrt(math.Pow(float64(e[1]-cy), 2)+math.Pow(float64(e[0]-cx), 2))) / edge * 255
if d < 0 {
d = 0
}
ud := uint8(d)
col := color.RGBA{0, ud, ud, 255}
screen.Set(e[0], e[1], col)
}
}
screen.Set(cx, cy, red)
ebitenutil.DebugPrint(screen, fmt.Sprintf(
"FPS: %0.2f\n(%d, %d)",
ebiten.CurrentFPS(),
cx, cy,
))
}
func (g *Game) Layout(ow, oh int) (int, int) {
return width, height
}
func main() {
g := &Game{}
g.Shapes = append(g.Shapes,
NewPolygon(red, []Point{
{width / 4, height / 4},
{3 * width / 4, height / 4},
{2 * width / 3, 3 * height / 4},
{width / 3, 3 * height / 4},
}),
NewPolygon(red, []Point{
{2 * width / 5, 2 * height / 5},
{3 * width / 5, 2 * height / 5},
{3 * width / 5, 3 * height / 5},
{2 * width / 5, 3 * height / 5},
}),
)
ebiten.SetWindowSize(width*scale, height*scale)
if err := ebiten.RunGame(g); err != nil {
panic(err)
}
}