diff --git a/image/README.md b/image/README.md index da5bee8..5fb2d4e 100644 --- a/image/README.md +++ b/image/README.md @@ -24,8 +24,8 @@ image.SVG(file, pos.Board()) The default colors, shown in the example SVG below, are (235, 209, 166) for light squares and (165, 117, 81) for dark squares. The light and dark squares can be customized using the SquareColors() option. ```go -white := color.RGBA{255, 255, 255, 1} -gray := color.RGBA{120, 120, 120, 1} +white := color.RGBA{255, 255, 255, 255} +gray := color.RGBA{120, 120, 120, 255} sqrs := image.SquareColors(white, gray) image.SVG(file, pos.Board(), sqrs) ``` @@ -35,7 +35,7 @@ image.SVG(file, pos.Board(), sqrs) MarkSquares is designed to be used as an optional argument to the SVG function. It marks the given squares with the color. A possible usage includes marking squares of the previous move. ```go -yellow := color.RGBA{255, 255, 0, 1} +yellow := color.RGBA{255, 255, 0, 51} mark := image.MarkSquares(yellow, chess.D2, chess.D4) image.SVG(file, pos.Board(), mark) ``` @@ -82,7 +82,7 @@ func main() { } // write board SVG to file - yellow := color.RGBA{255, 255, 0, 1} + yellow := color.RGBA{255, 255, 0, 51} mark := image.MarkSquares(yellow, chess.D2, chess.D4) arrows := image.MarkArrows(image.Arrow(chess.D2, chess.D4)) if err := image.SVG(f, pos.Board(), mark, arrows); err != nil { diff --git a/image/image.go b/image/image.go index 4a4035a..5da1c89 100755 --- a/image/image.go +++ b/image/image.go @@ -152,7 +152,9 @@ func (e *Encoder) EncodeSVG(b *chess.Board) error { canvas.Rect(x, y, sqWidth, sqHeight, "fill: "+colorToHex(c)) markColor, ok := e.marks[sq] if ok { - canvas.Rect(x, y, sqWidth, sqHeight, "fill-opacity:0.2;fill: "+colorToHex(markColor)) + _, _, _, a := markColor.RGBA() + opacity := float64(a) / 0xffff + canvas.Rect(x, y, sqWidth, sqHeight, fmt.Sprintf("fill-opacity:%f;fill: %s", opacity, colorToHex(markColor))) } // draw piece p := boardMap[sq] diff --git a/image/image_test.go b/image/image_test.go index 0b84ab3..c90f8bf 100755 --- a/image/image_test.go +++ b/image/image_test.go @@ -12,8 +12,8 @@ import ( "github.com/notnil/chess/image" ) -const expectedMD5 = "a2ee66ca19e4c347aec41371c1ca07f8" -const expectedMD5Black = "ce4d4e033a50678898c62928b8e0a15c" +const expectedMD5 = "625c63ef80796a3485004952a18c9b25" +const expectedMD5Black = "1988104209a5401be2f645967fadec78" const expectedMD5KnightsAndDiagonalArrows = "9c95aa56cec67be2ceee141f259753f7" func TestSVG(t *testing.T) { @@ -24,7 +24,7 @@ func TestSVG(t *testing.T) { if err := pos.UnmarshalText([]byte(fenStr)); err != nil { t.Error(err) } - mark := image.MarkSquares(color.RGBA{255, 255, 0, 1}, chess.D2, chess.D4) + mark := image.MarkSquares(color.RGBA{255, 255, 0, 100}, chess.D2, chess.D4) arrows := image.MarkArrows(image.Arrow(chess.D2, chess.D4)) if err := image.SVG(buf, pos.Board(), mark, arrows); err != nil { t.Error(err) @@ -46,7 +46,7 @@ func TestSVGFromBlack(t *testing.T) { if err := pos.UnmarshalText([]byte(fenStr)); err != nil { t.Error(err) } - mark := image.MarkSquares(color.RGBA{255, 255, 0, 1}, chess.D2, chess.D4) + mark := image.MarkSquares(color.RGBA{255, 255, 0, 51}, chess.D2, chess.D4) arrows := image.MarkArrows(image.Arrow(chess.D2, chess.D4).WithColor(color.Black)) per := image.Perspective(chess.Black) if err := image.SVG(buf, pos.Board(), mark, arrows, per); err != nil {