/
visualize.go
60 lines (49 loc) · 1.28 KB
/
visualize.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
package sudoku
import (
"image"
"image/color"
"math"
"github.com/llgcode/draw2d/draw2dimg"
)
func drawLines(src image.Image, lines []polarLine) image.Image {
dst := image.NewRGBA(src.Bounds())
gc := draw2dimg.NewGraphicContext(dst)
gc.SetFillColor(color.RGBA{0x0, 0x0, 0x0, 0xff})
gc.SetStrokeColor(color.RGBA{0x0, 0xff, 0x0, 0xff})
gc.SetLineWidth(2)
gc.Clear()
gc.DrawImage(src)
for _, line := range lines {
a := math.Cos(line.Theta)
b := math.Sin(line.Theta)
x0 := a * float64(line.Distance)
y0 := b * float64(line.Distance)
x1 := (x0 + 10000*(-b))
y1 := (y0 + 10000*(a))
x2 := (x0 - 10000*(-b))
y2 := (y0 - 10000*(a))
gc.MoveTo(x1, y1)
gc.LineTo(x2, y2)
gc.Close()
}
gc.FillStroke()
return dst
}
func drawLineFragments(src image.Image, fragments []lineFragment) image.Image {
dst := image.NewRGBA(src.Bounds())
gc := draw2dimg.NewGraphicContext(dst)
gc.SetFillColor(color.RGBA{0x0, 0x0, 0x0, 0xff})
gc.SetStrokeColor(color.RGBA{0x0, 0xff, 0x0, 0xff})
gc.SetLineWidth(2)
gc.Clear()
gc.DrawImage(src)
for _, fragment := range fragments {
x1, y1 := float64(fragment.Start.X), float64(fragment.Start.Y)
x2, y2 := float64(fragment.End.X), float64(fragment.End.Y)
gc.MoveTo(x1, y1)
gc.LineTo(x2, y2)
gc.Close()
}
gc.FillStroke()
return dst
}