-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhexagons.go
68 lines (60 loc) · 928 Bytes
/
hexagons.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
package svgr
import (
"fmt"
)
type hexagon [6]*point
func (m *Mosaic) Hexagons() string {
return m.render(func() string {
var hex hexagon
offset := 0
x := m.current.X * shapeSize
y := m.current.Y * shapeSize
if m.current.X%2 == 0 {
offset = 5
} else {
offset = 0
}
hex = hexagon{
&point{
x: x,
y: y + 5 + offset,
},
&point{
x: x + 3,
y: y + 0 + offset,
},
&point{
x: x + 10,
y: y + 0 + offset,
},
&point{
x: x + 13,
y: y + 5 + offset,
},
&point{
x: x + 10,
y: y + 10 + offset,
},
&point{
x: x + 3,
y: y + 10 + offset,
},
}
return fmt.Sprintf(
"<polygon points=\"%d,%d %d,%d %d,%d %d,%d %d,%d %d,%d\" fill=\"%s\"/>",
hex[0].x,
hex[0].y,
hex[1].x,
hex[1].y,
hex[2].x,
hex[2].y,
hex[3].x,
hex[3].y,
hex[4].x,
hex[4].y,
hex[5].x,
hex[5].y,
m.colorAtCurrent(),
)
})
}