From c26788ff399f827e402724a3b812ce5a9015f302 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Mon, 25 Nov 2024 12:33:18 -0500 Subject: [PATCH] export encoder (#139) --- image/image.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/image/image.go b/image/image.go index 9599390..a42a7e3 100755 --- a/image/image.go +++ b/image/image.go @@ -15,7 +15,7 @@ import ( // SVG writes the board SVG representation into the writer. // An error is returned if there is there is an error writing data. // SVG also takes options which can customize the image output. -func SVG(w io.Writer, b *chess.Board, opts ...func(*encoder)) error { +func SVG(w io.Writer, b *chess.Board, opts ...func(*Encoder)) error { e := new(w, opts) return e.EncodeSVG(b) } @@ -23,8 +23,8 @@ func SVG(w io.Writer, b *chess.Board, opts ...func(*encoder)) error { // SquareColors is designed to be used as an optional argument // to the SVG function. It changes the default light and // dark square colors to the colors given. -func SquareColors(light, dark color.Color) func(*encoder) { - return func(e *encoder) { +func SquareColors(light, dark color.Color) func(*Encoder) { + return func(e *Encoder) { e.light = light e.dark = dark } @@ -34,8 +34,8 @@ func SquareColors(light, dark color.Color) func(*encoder) { // to the SVG function. It marks the given squares with the // color. A possible usage includes marking squares of the // previous move. -func MarkSquares(c color.Color, sqs ...chess.Square) func(*encoder) { - return func(e *encoder) { +func MarkSquares(c color.Color, sqs ...chess.Square) func(*Encoder) { + return func(e *Encoder) { for _, sq := range sqs { e.marks[sq] = c } @@ -45,14 +45,14 @@ func MarkSquares(c color.Color, sqs ...chess.Square) func(*encoder) { // Perspective is designed to be used as an optional argument // to the SVG function. It draws the board from the perspective // of the given color. White is the default. -func Perspective(c chess.Color) func(*encoder) { - return func(e *encoder) { +func Perspective(c chess.Color) func(*Encoder) { + return func(e *Encoder) { e.perspective = c } } // A Encoder encodes chess boards into images. -type encoder struct { +type Encoder struct { w io.Writer light color.Color dark color.Color @@ -63,8 +63,8 @@ type encoder struct { // New returns an encoder that writes to the given writer. // New also takes options which can customize the image // output. -func new(w io.Writer, options []func(*encoder)) *encoder { - e := &encoder{ +func new(w io.Writer, options []func(*Encoder)) *Encoder { + e := &Encoder{ w: w, light: color.RGBA{235, 209, 166, 1}, dark: color.RGBA{165, 117, 81, 1}, @@ -94,7 +94,7 @@ var ( // EncodeSVG writes the board SVG representation into // the Encoder's writer. An error is returned if there // is there is an error writing data. -func (e *encoder) EncodeSVG(b *chess.Board) error { +func (e *Encoder) EncodeSVG(b *chess.Board) error { boardMap := b.SquareMap() canvas := svg.New(e.w) canvas.Start(boardWidth, boardHeight) @@ -142,7 +142,7 @@ func (e *encoder) EncodeSVG(b *chess.Board) error { return nil } -func (e *encoder) colorForSquare(sq chess.Square) color.Color { +func (e *Encoder) colorForSquare(sq chess.Square) color.Color { sqSum := int(sq.File()) + int(sq.Rank()) if sqSum%2 == 0 { return e.dark @@ -150,7 +150,7 @@ func (e *encoder) colorForSquare(sq chess.Square) color.Color { return e.light } -func (e *encoder) colorForText(sq chess.Square) color.Color { +func (e *Encoder) colorForText(sq chess.Square) color.Color { sqSum := int(sq.File()) + int(sq.Rank()) if sqSum%2 == 0 { return e.light