/
pic_test.go
109 lines (101 loc) · 2.42 KB
/
pic_test.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
101
102
103
104
105
106
107
108
109
package hexagon
import (
"fmt"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dimg"
"image"
"image/color"
"image/draw"
"log"
"testing"
)
func TestFirstPIC(t *testing.T) {
log.Println("TESTING")
}
func TestSecondPIC(t *testing.T) {
v := GetVP()
v.SetFlattop(true)
v.SetIso(true)
v.SetIso(false)
v.SetFlattop(false)
v.SetIso(true)
DrawGrid(v, "fliptop.png")
}
func TestThirdPIC(t *testing.T) {
v := GetVP()
v.SetFlattop(true)
v.SetFlattop(false)
v.SetFlattop(true)
v.SetIso(true)
v.SetIso(false)
v.SetIso(true)
DrawGrid(v, "flattop.png")
}
func DrawGrid(v *Viewport, fileName string) {
log.Println("DRAWING GRID FOR", v.ULCorner, v.LRCorner)
draw2d.SetFontFolder("")
dest := image.NewRGBA(image.Rect(0, 0, 400, 400))
white := color.RGBA{0xff, 0xff, 0xff, 255}
draw.Draw(dest, dest.Bounds(), &image.Uniform{white}, image.ZP, draw.Src)
gc := draw2dimg.NewGraphicContext(dest)
gc.SetFontData(draw2d.FontData{Name: "DroidSansMono", Family: draw2d.FontFamilyMono})
gc.SetFillColor(image.Black)
gc.SetFontSize(8)
for x := 0; x < 400; x++ {
for y := 0; y < 400; y++ {
p := Pixel{float64(x), float64(y)}
hex := v.HexContaining(p)
var clr color.RGBA
clN := (hex[0] - hex[1]) % 4
for clN < 0 {
clN += 4
}
switch clN {
case 0: // blue
clr = color.RGBA{0x33, 0x66, 0xcc, 255}
case 1: // green
clr = color.RGBA{0x00, 0xAA, 0x33, 255}
case 2: // red
clr = color.RGBA{0xAA, 0x33, 0x33, 255}
default: // white
clr = white
}
dest.Set(x, y, clr)
/*if (x+60)%60 == 0 && y%15 == 0 {
gc.FillStringAt(fmt.Sprintf("(%d,%d)", hex[0], hex[1]), p[0], p[1])
}*/
}
}
for _, h := range v.VisList() {
corners := v.CornersOf(h)
gc.MoveTo(corners[0][0], corners[0][1])
for i, _ := range corners {
var px, py float64
if i == 5 {
px, py = corners[0][0], corners[0][1]
} else {
px, py = corners[i+1][0], corners[i+1][1]
}
gc.LineTo(px, py)
}
gc.Close()
gc.Stroke()
c := v.CenterOf(h)
gc.FillStringAt(fmt.Sprintf("(%d,%d)", h[0], h[1]), c[0], c[1])
}
gc.SetLineWidth(2)
gc.MoveTo(v.ULCorner[0], v.ULCorner[1])
gc.LineTo(v.LRCorner[0], v.ULCorner[1])
gc.LineTo(v.LRCorner[0], v.LRCorner[1])
gc.LineTo(v.ULCorner[0], v.LRCorner[1])
gc.Close()
gc.Stroke()
//}
draw2dimg.SaveToPngFile(fileName, dest)
}
func GetVP() *Viewport {
v := MakeViewport(30.0, false, false)
v.SetAnchor(5, 5, 200.0, 200.0)
v.SetFrame(110, 110, 290, 290)
return v
}