image

package
v1.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2022 License: MIT Imports: 7 Imported by: 0

README

image

image is an octad image utility that converts board positions into SVG, or Scalable Vector Graphics, images.svgo, the only outside dependency, is used to construct the SVG document.

Usage

SVG

The SVG function is the primary exported function of the package. It writes an SVG document to the io.Writer given.

file, _ := os.Open("output.svg")
defer file.Close()
fenStr := "ppkn/4/2P1/NK1P b NCFncf - 0 1"
pos := &octad.Position{}
pos.UnmarshalText([]byte(fenStr))
image.SVG(file, pos.Board())
Dark / Light Square Customization

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.

white := color.RGBA{255, 255, 255, 1}
gray := color.RGBA{120, 120, 120, 1}
sqrs := image.SquareColors(white, gray)
image.SVG(file, pos.Board(), sqrs)
Marked Squares

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.

blue := color.RGBA{R: 0, G: 64, B: 255, A: 1}
mark := image.MarkSquares(blue, octad.C1, octad.C2)
image.SVG(file, pos.Board(), mark)
Example Program
package main

import (
	"image/color"
	"log"
	"os"

	"github.com/dechristopher/octad"
	"github.com/dechristopher/octad/image"
)

func main() {
    // create file
    f, err := os.Create("example.svg")
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()

    // create board position
    fenStr := "ppkn/4/2P1/NK1P b NCFncf - 0 1"
    pos := &octad.Position{}
    if err := pos.UnmarshalText([]byte(fenStr)); err != nil {
        log.Fatal(err)
    }

    // write board SVG to file
    blue := color.RGBA{R: 0, G: 64, B: 255, A: 1}
    mark := image.MarkSquares(blue, octad.C1, octad.C2)
    if err := image.SVG(f, pos.Board(), mark); err != nil {
        log.Fatal(err)
    }
}
Example Program Result

ppkn/4/2P1/NK1P b NCFncf - 0 1

Documentation

Overview

Package image is a go library that creates images from octad board positions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarkSquares

func MarkSquares(c color.Color, sqs ...octad.Square) func(*encoder)

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.

func SVG

func SVG(w io.Writer, b *octad.Board, opts ...func(*encoder)) error

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 SquareColors

func SquareColors(light, dark color.Color) func(*encoder)

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.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL