gfx: github.com/peterhellberg/gfx Index | Examples | Files

package gfx

import "github.com/peterhellberg/gfx"

Package gfx is a convenience package for dealing with graphics in my pixel drawing experiments.

My experiments are often published under https://gist.github.com/peterhellberg

Usage examples and images can be found in the package README https://github.com/peterhellberg/gfx

Index

Examples

Package Files

animation.go base64.go batch.go block.go blocks.go box.go bresenham.go cie_lab.go circle.go cmplx.go colors.go degrees.go doc.go draw.go draw_target.go drawer.go errors.go file.go geo.go hsl.go hsv.go http.go hunter_lab.go image.go imdraw.go int.go interfaces.go layer.go linear_scaler.go log.go math.go matrix.go palette.go paletted_image.go palettes.go playground.go polygon.go polyline.go rand.go rect.go resize.go signed_distance.go simplex.go sort.go tiles.go triangle.go triangles_data.go vec2.go vec3.go vertex.go xyz.go

Variables

var (
    ColorTransparent = ColorNRGBA(0, 0, 0, 0)
    ColorOpaque      = ColorNRGBA(0xFF, 0xFF, 0xFF, 0xFF)
    ColorBlack       = Palette1Bit.Color(0)
    ColorWhite       = Palette1Bit.Color(1)
    ColorRed         = Palette3Bit.Color(1)
    ColorGreen       = Palette3Bit.Color(2)
    ColorBlue        = Palette3Bit.Color(3)
    ColorCyan        = Palette3Bit.Color(4)
    ColorMagenta     = Palette3Bit.Color(5)
    ColorYellow      = Palette3Bit.Color(6)

    // ColorByName is a map of all the default colors by name.
    ColorByName = map[string]color.NRGBA{
        "Transparent": ColorTransparent,
        "Opaque":      ColorOpaque,
        "Black":       ColorBlack,
        "White":       ColorWhite,
        "Red":         ColorRed,
        "Green":       ColorGreen,
        "Blue":        ColorBlue,
        "Cyan":        ColorCyan,
        "Magenta":     ColorMagenta,
        "Yellow":      ColorYellow,
    }
)

Standard colors transparent, opaque, black, white, red, green, blue, cyan, magenta, and yellow.

var (
    // Default block colors based on PaletteTango.
    BlockColorYellow = BlockColor{Light: PaletteTango[0], Medium: PaletteTango[1], Dark: PaletteTango[2]}
    BlockColorOrange = BlockColor{Light: PaletteTango[3], Medium: PaletteTango[4], Dark: PaletteTango[5]}
    BlockColorBrown  = BlockColor{Light: PaletteTango[6], Medium: PaletteTango[7], Dark: PaletteTango[8]}
    BlockColorGreen  = BlockColor{Light: PaletteTango[9], Medium: PaletteTango[10], Dark: PaletteTango[11]}
    BlockColorBlue   = BlockColor{Light: PaletteTango[12], Medium: PaletteTango[13], Dark: PaletteTango[14]}
    BlockColorPurple = BlockColor{Light: PaletteTango[15], Medium: PaletteTango[16], Dark: PaletteTango[17]}
    BlockColorRed    = BlockColor{Light: PaletteTango[18], Medium: PaletteTango[19], Dark: PaletteTango[20]}
    BlockColorWhite  = BlockColor{Light: PaletteTango[21], Medium: PaletteTango[22], Dark: PaletteTango[23]}
    BlockColorBlack  = BlockColor{Light: PaletteTango[24], Medium: PaletteTango[25], Dark: PaletteTango[26]}

    // BlockColors is a slice of the default block colors.
    BlockColors = []BlockColor{
        BlockColorYellow,
        BlockColorOrange,
        BlockColorBrown,
        BlockColorGreen,
        BlockColorBlue,
        BlockColorPurple,
        BlockColorRed,
        BlockColorWhite,
        BlockColorBlack,
    }

    // Block colors based on the Go color palette.
    BlockColorGoGopherBlue = BlockColor{Dark: PaletteGo[0], Medium: PaletteGo[2], Light: PaletteGo[4]}
    BlockColorGoLightBlue  = BlockColor{Dark: PaletteGo[9], Medium: PaletteGo[11], Light: PaletteGo[13]}
    BlockColorGoAqua       = BlockColor{Dark: PaletteGo[18], Medium: PaletteGo[20], Light: PaletteGo[22]}
    BlockColorGoFuchsia    = BlockColor{Dark: PaletteGo[27], Medium: PaletteGo[29], Light: PaletteGo[31]}
    BlockColorGoBlack      = BlockColor{Dark: PaletteGo[36], Medium: PaletteGo[38], Light: PaletteGo[40]}
    BlockColorGoYellow     = BlockColor{Dark: PaletteGo[45], Medium: PaletteGo[47], Light: PaletteGo[49]}

    // BlockColorsGo is a slice of block colors based on the Go color palette.
    BlockColorsGo = []BlockColor{
        BlockColorGoGopherBlue,
        BlockColorGoLightBlue,
        BlockColorGoAqua,
        BlockColorGoFuchsia,
        BlockColorGoBlack,
        BlockColorGoYellow,
    }

    // BlockColorByName is a map of block colors by name.
    BlockColorByName = map[string]BlockColor{

        "Yellow": BlockColorYellow,
        "Orange": BlockColorOrange,
        "Brown":  BlockColorBrown,
        "Green":  BlockColorGreen,
        "Blue":   BlockColorBlue,
        "Purple": BlockColorPurple,
        "Red":    BlockColorRed,
        "White":  BlockColorWhite,
        "Black":  BlockColorBlack,

        "GoGopherBlue": BlockColorGoGopherBlue,
        "GoLightBlue":  BlockColorGoLightBlue,
        "GoAqua":       BlockColorGoAqua,
        "GoFuchsia":    BlockColorGoFuchsia,
        "GoBlack":      BlockColorGoBlack,
        "GoYellow":     BlockColorGoYellow,
    }
)

Block colors, each containing a Light, Medium and Dark color.

var (
    // XYZReference2 for CIE 1931 2° Standard Observer
    XYZReference2 = XYZReference{
        A:   XYZ{109.850, 100.000, 35.585},
        B:   XYZ{99.0927, 100.000, 85.313},
        C:   XYZ{98.074, 100.000, 118.232},
        D50: XYZ{96.422, 100.000, 82.521},
        D55: XYZ{95.682, 100.000, 92.149},
        D65: XYZ{95.047, 100.000, 108.883},
        D75: XYZ{94.972, 100.000, 122.638},
        E:   XYZ{100.000, 100.000, 100.000},
        F1:  XYZ{92.834, 100.000, 103.665},
        F2:  XYZ{99.187, 100.000, 67.395},
        F3:  XYZ{103.754, 100.000, 49.861},
        F4:  XYZ{109.147, 100.000, 38.813},
        F5:  XYZ{90.872, 100.000, 98.723},
        F6:  XYZ{97.309, 100.000, 60.191},
        F7:  XYZ{95.044, 100.000, 108.755},
        F8:  XYZ{96.413, 100.000, 82.333},
        F9:  XYZ{100.365, 100.000, 67.868},
        F10: XYZ{96.174, 100.000, 81.712},
        F11: XYZ{100.966, 100.000, 64.370},
        F12: XYZ{108.046, 100.000, 39.228},
    }

    // XYZReference10 for CIE 1964 10° Standard Observer
    XYZReference10 = XYZReference{
        A:   XYZ{111.144, 100.000, 35.200},
        B:   XYZ{99.178, 100.000, 84.3493},
        C:   XYZ{97.285, 100.000, 116.145},
        D50: XYZ{96.720, 100.000, 81.427},
        D55: XYZ{95.799, 100.000, 90.926},
        D65: XYZ{94.811, 100.000, 107.304},
        D75: XYZ{94.416, 100.000, 120.641},
        E:   XYZ{100.000, 100.000, 100.000},
        F1:  XYZ{94.791, 100.000, 103.191},
        F2:  XYZ{103.280, 100.000, 69.026},
        F3:  XYZ{108.968, 100.000, 51.965},
        F4:  XYZ{114.961, 100.000, 40.963},
        F5:  XYZ{93.369, 100.000, 98.636},
        F6:  XYZ{102.148, 100.000, 62.074},
        F7:  XYZ{95.792, 100.000, 107.687},
        F8:  XYZ{97.115, 100.000, 81.135},
        F9:  XYZ{102.116, 100.000, 67.826},
        F10: XYZ{99.001, 100.000, 83.134},
        F11: XYZ{103.866, 100.000, 65.627},
        F12: XYZ{111.428, 100.000, 40.353},
    }
)
var DefaultAnimationDelay = 50

DefaultAnimationDelay is the default animation delay, in 100ths of a second.

var ErrDone = Error("done")

ErrDone can for example be returned when you are done rendering.

var HTTPClient = HTTP{
    Client: &http.Client{
        Timeout: 30 * time.Second,
    },
    UserAgent: "gfx.HTTPClient",
}

HTTPClient is the default client used by Get/GetPNG/GetTileset, etc.

var IM = Matrix{1, 0, 0, 1, 0, 0}

IM stands for identity matrix. Does nothing, no transformation.

var Palette15PDX = Palette{
    {0x6E, 0x32, 0x32, 0xFF},
    {0xBB, 0x57, 0x35, 0xFF},
    {0xDF, 0x92, 0x45, 0xFF},
    {0xEC, 0xD2, 0x74, 0xFF},
    {0x83, 0xA8, 0x16, 0xFF},
    {0x27, 0x72, 0x24, 0xFF},
    {0x17, 0x3B, 0x47, 0xFF},
    {0x04, 0x68, 0x94, 0xFF},
    {0x17, 0xA1, 0xA9, 0xFF},
    {0x81, 0xDB, 0xCD, 0xFF},
    {0xFD, 0xF9, 0xF1, 0xFF},
    {0xC7, 0xB2, 0x95, 0xFF},
    {0x87, 0x71, 0x5B, 0xFF},
    {0x46, 0x3F, 0x3C, 0xFF},
    {0x20, 0x17, 0x08, 0xFF},
}

Palette15PDX is the 15P DX palette.

Palette created by GrafxKid.

https://lospec.com/palette-list/15p-dx

var Palette1Bit = Palette{
    {0x00, 0x00, 0x00, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
}

Palette1Bit is a basic 1-bit (black and white) palette.

var Palette20PDX = Palette{
    {0x17, 0x0D, 0x20, 0xFF},
    {0x47, 0x47, 0x57, 0xFF},
    {0x78, 0x78, 0x76, 0xFF},
    {0xB1, 0xB9, 0xA6, 0xFF},
    {0xEB, 0xFF, 0xDA, 0xFF},
    {0x68, 0x29, 0x3E, 0xFF},
    {0xA9, 0x44, 0x00, 0xFF},
    {0xD9, 0x7E, 0x00, 0xFF},
    {0xEB, 0xD0, 0x00, 0xFF},
    {0x52, 0x3C, 0x14, 0xFF},
    {0x81, 0x60, 0x31, 0xFF},
    {0xBC, 0x8B, 0x57, 0xFF},
    {0xEB, 0xCD, 0x93, 0xFF},
    {0x0E, 0x4C, 0x58, 0xFF},
    {0x04, 0x6E, 0x92, 0xFF},
    {0x01, 0xA3, 0xC3, 0xFF},
    {0x55, 0xDE, 0xB7, 0xFF},
    {0x17, 0x79, 0x47, 0xFF},
    {0x5A, 0xB2, 0x17, 0xFF},
    {0xB1, 0xE3, 0x29, 0xFF},
}

Palette20PDX is the 20P DX palette.

Palette created by GrafxKid.

https://lospec.com/palette-list/20p-dx

var Palette2BitGrayScale = Palette{
    {0x00, 0x00, 0x00, 0xFF},
    {0x67, 0x67, 0x67, 0xFF},
    {0xB6, 0xB6, 0xB6, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
}

Palette2BitGrayScale is a grayscale palette calculated using 2-bits per color.

It was used by the original gameboy and a few other computer systems.

https://lospec.com/palette-list/2-bit-grayscale

var Palette3Bit = Palette{
    {0x00, 0x00, 0x00, 0xFF},
    {0xFF, 0x00, 0x00, 0xFF},
    {0x00, 0xFF, 0x00, 0xFF},
    {0x00, 0x00, 0xFF, 0xFF},
    {0x00, 0xFF, 0xFF, 0xFF},
    {0xFF, 0x00, 0xFF, 0xFF},
    {0xFF, 0xFF, 0x00, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
}

Palette3Bit is the 3-Bit palette.

A calculated palette using 1 bit for each RGB value. It was used by a number of early computers.

var PaletteAAP16 = Palette{
    {0x07, 0x07, 0x08, 0xFF},
    {0x33, 0x22, 0x22, 0xFF},
    {0x77, 0x44, 0x33, 0xFF},
    {0xCC, 0x88, 0x55, 0xFF},
    {0x99, 0x33, 0x11, 0xFF},
    {0xDD, 0x77, 0x11, 0xFF},
    {0xFF, 0xDD, 0x55, 0xFF},
    {0xFF, 0xFF, 0x33, 0xFF},
    {0x55, 0xAA, 0x44, 0xFF},
    {0x11, 0x55, 0x22, 0xFF},
    {0x44, 0xEE, 0xBB, 0xFF},
    {0x33, 0x88, 0xDD, 0xFF},
    {0x55, 0x44, 0xAA, 0xFF},
    {0x55, 0x55, 0x77, 0xFF},
    {0xAA, 0xBB, 0xBB, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
}

PaletteAAP16 is the AAP-16 palette.

Created by Adigun Polack, meant for beginners.

https://lospec.com/palette-list/aap-16

var PaletteAAP64 = Palette{
    {0x06, 0x06, 0x08, 0xFF},
    {0x14, 0x10, 0x13, 0xFF},
    {0x3B, 0x17, 0x25, 0xFF},
    {0x73, 0x17, 0x2D, 0xFF},
    {0xB4, 0x20, 0x2A, 0xFF},
    {0xDF, 0x3E, 0x23, 0xFF},
    {0xFA, 0x6A, 0x0A, 0xFF},
    {0xF9, 0xA3, 0x1B, 0xFF},
    {0xFF, 0xD5, 0x41, 0xFF},
    {0xFF, 0xFC, 0x40, 0xFF},
    {0xD6, 0xF2, 0x64, 0xFF},
    {0x9C, 0xDB, 0x43, 0xFF},
    {0x59, 0xC1, 0x35, 0xFF},
    {0x14, 0xA0, 0x2E, 0xFF},
    {0x1A, 0x7A, 0x3E, 0xFF},
    {0x24, 0x52, 0x3B, 0xFF},
    {0x12, 0x20, 0x20, 0xFF},
    {0x14, 0x34, 0x64, 0xFF},
    {0x28, 0x5C, 0xC4, 0xFF},
    {0x24, 0x9F, 0xDE, 0xFF},
    {0x20, 0xD6, 0xC7, 0xFF},
    {0xA6, 0xFC, 0xDB, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
    {0xFE, 0xF3, 0xC0, 0xFF},
    {0xFA, 0xD6, 0xB8, 0xFF},
    {0xF5, 0xA0, 0x97, 0xFF},
    {0xE8, 0x6A, 0x73, 0xFF},
    {0xBC, 0x4A, 0x9B, 0xFF},
    {0x79, 0x3A, 0x80, 0xFF},
    {0x40, 0x33, 0x53, 0xFF},
    {0x24, 0x22, 0x34, 0xFF},
    {0x22, 0x1C, 0x1A, 0xFF},
    {0x32, 0x2B, 0x28, 0xFF},
    {0x71, 0x41, 0x3B, 0xFF},
    {0xBB, 0x75, 0x47, 0xFF},
    {0xDB, 0xA4, 0x63, 0xFF},
    {0xF4, 0xD2, 0x9C, 0xFF},
    {0xDA, 0xE0, 0xEA, 0xFF},
    {0xB3, 0xB9, 0xD1, 0xFF},
    {0x8B, 0x93, 0xAF, 0xFF},
    {0x6D, 0x75, 0x8D, 0xFF},
    {0x4A, 0x54, 0x62, 0xFF},
    {0x33, 0x39, 0x41, 0xFF},
    {0x42, 0x24, 0x33, 0xFF},
    {0x5B, 0x31, 0x38, 0xFF},
    {0x8E, 0x52, 0x52, 0xFF},
    {0xBA, 0x75, 0x6A, 0xFF},
    {0xE9, 0xB5, 0xA3, 0xFF},
    {0xE3, 0xE6, 0xFF, 0xFF},
    {0xB9, 0xBF, 0xFB, 0xFF},
    {0x84, 0x9B, 0xE4, 0xFF},
    {0x58, 0x8D, 0xBE, 0xFF},
    {0x47, 0x7D, 0x85, 0xFF},
    {0x23, 0x67, 0x4E, 0xFF},
    {0x32, 0x84, 0x64, 0xFF},
    {0x5D, 0xAF, 0x8D, 0xFF},
    {0x92, 0xDC, 0xBA, 0xFF},
    {0xCD, 0xF7, 0xE2, 0xFF},
    {0xE4, 0xD2, 0xAA, 0xFF},
    {0xC7, 0xB0, 0x8B, 0xFF},
    {0xA0, 0x86, 0x62, 0xFF},
    {0x79, 0x67, 0x55, 0xFF},
    {0x5A, 0x4E, 0x44, 0xFF},
    {0x42, 0x39, 0x34, 0xFF},
}

PaletteAAP64 is the AAP-64 palette.

Created by Adigun Polack.

https://lospec.com/palette-list/aap-16

var PaletteARQ4 = Palette{
    {0xFF, 0xFF, 0xFF, 0xFF},
    {0x67, 0x72, 0xA9, 0xFF},
    {0x3A, 0x32, 0x77, 0xFF},
    {0x00, 0x00, 0x00, 0xFF},
}

PaletteARQ4 is the ARQ4 palette.

Created by Endesga. #ARQ4

https://lospec.com/palette-list/arq4

var PaletteAmmo8 = Palette{
    {0x04, 0x0C, 0x06, 0xFF},
    {0x11, 0x23, 0x18, 0xFF},
    {0x1E, 0x3A, 0x29, 0xFF},
    {0x30, 0x5D, 0x42, 0xFF},
    {0x4D, 0x80, 0x61, 0xFF},
    {0x89, 0xA2, 0x57, 0xFF},
    {0xBE, 0xDC, 0x7F, 0xFF},
    {0xEE, 0xFF, 0xCC, 0xFF},
}

PaletteAmmo8 is the Ammo-8 palette.

Created by rsvp asap.

https://lospec.com/palette-list/ammo-8

var PaletteArne16 = Palette{
    {0x00, 0x00, 0x00, 0xFF},
    {0x49, 0x3C, 0x2B, 0xFF},
    {0xBE, 0x26, 0x33, 0xFF},
    {0xE0, 0x6F, 0x8B, 0xFF},
    {0x9D, 0x9D, 0x9D, 0xFF},
    {0xA4, 0x64, 0x22, 0xFF},
    {0xEB, 0x89, 0x31, 0xFF},
    {0xF7, 0xE2, 0x6B, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
    {0x1B, 0x26, 0x32, 0xFF},
    {0x2F, 0x48, 0x4E, 0xFF},
    {0x44, 0x89, 0x1A, 0xFF},
    {0xA3, 0xCE, 0x27, 0xFF},
    {0x00, 0x57, 0x84, 0xFF},
    {0x31, 0xA2, 0xF2, 0xFF},
    {0xB2, 0xDC, 0xEF, 0xFF},
}

PaletteArne16 is the Arne 16 palette.

Created by Arne.

https://lospec.com/palette-list/arne-16

var PaletteByName = PaletteLookup{

    "1Bit":          Palette1Bit,
    "2BitGrayScale": Palette2BitGrayScale,
    "3Bit":          Palette3Bit,
    "CGA":           PaletteCGA,

    "15PDX": Palette15PDX,
    "20PDX": Palette20PDX,

    "AAP16":       PaletteAAP16,
    "AAP64":       PaletteAAP64,
    "Splendor128": PaletteSplendor128,

    "Arne16":   PaletteArne16,
    "Famicube": PaletteFamicube,

    "EDG16": PaletteEDG16,
    "EDG32": PaletteEDG32,
    "EDG36": PaletteEDG36,
    "EDG64": PaletteEDG64,
    "EDG8":  PaletteEDG8,
    "EN4":   PaletteEN4,
    "ARQ4":  PaletteARQ4,

    "Ink":     PaletteInk,
    "Ammo8":   PaletteAmmo8,
    "NYX8":    PaletteNYX8,
    "Night16": PaletteNight16,
    "PICO8":   PalettePICO8,

    "Tango": PaletteTango,
    "Go":    PaletteGo,
}

PaletteByName is a map of all palettes by name.

var PaletteCGA = Palette{
    {0x00, 0x00, 0x00, 0xFF},
    {0x55, 0x55, 0x55, 0xFF},
    {0xAA, 0xAA, 0xAA, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
    {0x00, 0x00, 0xAA, 0xFF},
    {0x55, 0x55, 0xFF, 0xFF},
    {0x00, 0xAA, 0x00, 0xFF},
    {0x55, 0xFF, 0x55, 0xFF},
    {0x00, 0xAA, 0xAA, 0xFF},
    {0x55, 0xFF, 0xFF, 0xFF},
    {0xAA, 0x00, 0x00, 0xFF},
    {0xFF, 0x55, 0x55, 0xFF},
    {0xAA, 0x00, 0xAA, 0xFF},
    {0xFF, 0x55, 0xFF, 0xFF},
    {0xAA, 0x55, 0x00, 0xFF},
    {0xFF, 0xFF, 0x55, 0xFF},
}

PaletteCGA is the Color Graphics Adapter palette.

CGA was a graphics card released in 1981 for the IBM PC. The standard mode uses one of two 4-color palettes (each with a low-intensity and high-intensity mode), but a hack allows use of all 16. #cga

https://lospec.com/palette-list/color-graphics-adapter

var PaletteEDG16 = Palette{
    {0xE4, 0xA6, 0x72, 0xFF},
    {0xB8, 0x6F, 0x50, 0xFF},
    {0x74, 0x3F, 0x39, 0xFF},
    {0x3F, 0x28, 0x32, 0xFF},
    {0x9E, 0x28, 0x35, 0xFF},
    {0xE5, 0x3B, 0x44, 0xFF},
    {0xFB, 0x92, 0x2B, 0xFF},
    {0xFF, 0xE7, 0x62, 0xFF},
    {0x63, 0xC6, 0x4D, 0xFF},
    {0x32, 0x73, 0x45, 0xFF},
    {0x19, 0x3D, 0x3F, 0xFF},
    {0x4F, 0x67, 0x81, 0xFF},
    {0xAF, 0xBF, 0xD2, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
    {0x2C, 0xE8, 0xF4, 0xFF},
    {0x04, 0x84, 0xD1, 0xFF},
}

PaletteEDG16 is the Endesga 16 palette.

Created by Endesga. #EDG16

https://lospec.com/palette-list/endesga-16

var PaletteEDG32 = Palette{
    {0xBE, 0x4A, 0x2F, 0xFF},
    {0xD7, 0x76, 0x43, 0xFF},
    {0xEA, 0xD4, 0xAA, 0xFF},
    {0xE4, 0xA6, 0x72, 0xFF},
    {0xB8, 0x6F, 0x50, 0xFF},
    {0x73, 0x3E, 0x39, 0xFF},
    {0x3E, 0x27, 0x31, 0xFF},
    {0xA2, 0x26, 0x33, 0xFF},
    {0xE4, 0x3B, 0x44, 0xFF},
    {0xF7, 0x76, 0x22, 0xFF},
    {0xFE, 0xAE, 0x34, 0xFF},
    {0xFE, 0xE7, 0x61, 0xFF},
    {0x63, 0xC7, 0x4D, 0xFF},
    {0x3E, 0x89, 0x48, 0xFF},
    {0x26, 0x5C, 0x42, 0xFF},
    {0x19, 0x3C, 0x3E, 0xFF},
    {0x12, 0x4E, 0x89, 0xFF},
    {0x00, 0x99, 0xDB, 0xFF},
    {0x2C, 0xE8, 0xF5, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
    {0xC0, 0xCB, 0xDC, 0xFF},
    {0x8B, 0x9B, 0xB4, 0xFF},
    {0x5A, 0x69, 0x88, 0xFF},
    {0x3A, 0x44, 0x66, 0xFF},
    {0x26, 0x2B, 0x44, 0xFF},
    {0x18, 0x14, 0x25, 0xFF},
    {0xFF, 0x00, 0x44, 0xFF},
    {0x68, 0x38, 0x6C, 0xFF},
    {0xB5, 0x50, 0x88, 0xFF},
    {0xF6, 0x75, 0x7A, 0xFF},
    {0xE8, 0xB7, 0x96, 0xFF},
    {0xC2, 0x85, 0x69, 0xFF},
}

PaletteEDG32 is the Endesga 32 palette.

Created by Endesga for his game NYKRA. #EDG32

https://lospec.com/palette-list/endesga-32

var PaletteEDG36 = Palette{
    {0xDB, 0xE0, 0xE7, 0xFF},
    {0xA3, 0xAC, 0xBE, 0xFF},
    {0x67, 0x70, 0x8B, 0xFF},
    {0x4E, 0x53, 0x71, 0xFF},
    {0x39, 0x3A, 0x56, 0xFF},
    {0x26, 0x24, 0x3A, 0xFF},
    {0x14, 0x10, 0x20, 0xFF},
    {0x7B, 0xCF, 0x5C, 0xFF},
    {0x50, 0x9B, 0x4B, 0xFF},
    {0x2E, 0x6A, 0x42, 0xFF},
    {0x1A, 0x45, 0x3B, 0xFF},
    {0x0F, 0x27, 0x38, 0xFF},
    {0x0D, 0x2F, 0x6D, 0xFF},
    {0x0F, 0x4D, 0xA3, 0xFF},
    {0x0E, 0x82, 0xCE, 0xFF},
    {0x13, 0xB2, 0xF2, 0xFF},
    {0x41, 0xF3, 0xFC, 0xFF},
    {0xF0, 0xD2, 0xAF, 0xFF},
    {0xE5, 0xAE, 0x78, 0xFF},
    {0xC5, 0x81, 0x58, 0xFF},
    {0x94, 0x55, 0x42, 0xFF},
    {0x62, 0x35, 0x30, 0xFF},
    {0x46, 0x21, 0x1F, 0xFF},
    {0x97, 0x43, 0x2A, 0xFF},
    {0xE5, 0x70, 0x28, 0xFF},
    {0xF7, 0xAC, 0x37, 0xFF},
    {0xFB, 0xDF, 0x6B, 0xFF},
    {0xFE, 0x97, 0x9B, 0xFF},
    {0xED, 0x52, 0x59, 0xFF},
    {0xC4, 0x2C, 0x36, 0xFF},
    {0x78, 0x1F, 0x2C, 0xFF},
    {0x35, 0x14, 0x28, 0xFF},
    {0x4D, 0x23, 0x52, 0xFF},
    {0x7F, 0x3B, 0x86, 0xFF},
    {0xB4, 0x5E, 0xB3, 0xFF},
    {0xE3, 0x8D, 0xD6, 0xFF},
}

PaletteEDG36 is the Endesga 36 palette.

Created by Endesga. #EDG36

https://lospec.com/palette-list/endesga-36

var PaletteEDG64 = Palette{
    {0xFF, 0x00, 0x40, 0xFF},
    {0x13, 0x13, 0x13, 0xFF},
    {0x1B, 0x1B, 0x1B, 0xFF},
    {0x27, 0x27, 0x27, 0xFF},
    {0x3D, 0x3D, 0x3D, 0xFF},
    {0x5D, 0x5D, 0x5D, 0xFF},
    {0x85, 0x85, 0x85, 0xFF},
    {0xB4, 0xB4, 0xB4, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
    {0xC7, 0xCF, 0xDD, 0xFF},
    {0x92, 0xA1, 0xB9, 0xFF},
    {0x65, 0x73, 0x92, 0xFF},
    {0x42, 0x4C, 0x6E, 0xFF},
    {0x2A, 0x2F, 0x4E, 0xFF},
    {0x1A, 0x19, 0x32, 0xFF},
    {0x0E, 0x07, 0x1B, 0xFF},
    {0x1C, 0x12, 0x1C, 0xFF},
    {0x39, 0x1F, 0x21, 0xFF},
    {0x5D, 0x2C, 0x28, 0xFF},
    {0x8A, 0x48, 0x36, 0xFF},
    {0xBF, 0x6F, 0x4A, 0xFF},
    {0xE6, 0x9C, 0x69, 0xFF},
    {0xF6, 0xCA, 0x9F, 0xFF},
    {0xF9, 0xE6, 0xCF, 0xFF},
    {0xED, 0xAB, 0x50, 0xFF},
    {0xE0, 0x74, 0x38, 0xFF},
    {0xC6, 0x45, 0x24, 0xFF},
    {0x8E, 0x25, 0x1D, 0xFF},
    {0xFF, 0x50, 0x00, 0xFF},
    {0xED, 0x76, 0x14, 0xFF},
    {0xFF, 0xA2, 0x14, 0xFF},
    {0xFF, 0xC8, 0x25, 0xFF},
    {0xFF, 0xEB, 0x57, 0xFF},
    {0xD3, 0xFC, 0x7E, 0xFF},
    {0x99, 0xE6, 0x5F, 0xFF},
    {0x5A, 0xC5, 0x4F, 0xFF},
    {0x33, 0x98, 0x4B, 0xFF},
    {0x1E, 0x6F, 0x50, 0xFF},
    {0x13, 0x4C, 0x4C, 0xFF},
    {0x0C, 0x2E, 0x44, 0xFF},
    {0x00, 0x39, 0x6D, 0xFF},
    {0x00, 0x69, 0xAA, 0xFF},
    {0x00, 0x98, 0xDC, 0xFF},
    {0x00, 0xCD, 0xF9, 0xFF},
    {0x0C, 0xF1, 0xFF, 0xFF},
    {0x94, 0xFD, 0xFF, 0xFF},
    {0xFD, 0xD2, 0xED, 0xFF},
    {0xF3, 0x89, 0xF5, 0xFF},
    {0xDB, 0x3F, 0xFD, 0xFF},
    {0x7A, 0x09, 0xFA, 0xFF},
    {0x30, 0x03, 0xD9, 0xFF},
    {0x0C, 0x02, 0x93, 0xFF},
    {0x03, 0x19, 0x3F, 0xFF},
    {0x3B, 0x14, 0x43, 0xFF},
    {0x62, 0x24, 0x61, 0xFF},
    {0x93, 0x38, 0x8F, 0xFF},
    {0xCA, 0x52, 0xC9, 0xFF},
    {0xC8, 0x50, 0x86, 0xFF},
    {0xF6, 0x81, 0x87, 0xFF},
    {0xF5, 0x55, 0x5D, 0xFF},
    {0xEA, 0x32, 0x3C, 0xFF},
    {0xC4, 0x24, 0x30, 0xFF},
    {0x89, 0x1E, 0x2B, 0xFF},
    {0x57, 0x1C, 0x27, 0xFF},
}

PaletteEDG64 is the Endesga 64 palette.

"Honed over years of palette creation, refined for materialistic pixelart and design. High contrast, high saturation, shaped around painting the organic and structured life of the heptaverse." Created by Endesga. #EDG64

https://lospec.com/palette-list/endesga-64

var PaletteEDG8 = Palette{
    {0xFD, 0xFD, 0xF8, 0xFF},
    {0xD3, 0x27, 0x34, 0xFF},
    {0xDA, 0x7D, 0x22, 0xFF},
    {0xE6, 0xDA, 0x29, 0xFF},
    {0x28, 0xC6, 0x41, 0xFF},
    {0x2D, 0x93, 0xDD, 0xFF},
    {0x7B, 0x53, 0xAD, 0xFF},
    {0x1B, 0x1C, 0x33, 0xFF},
}

PaletteEDG8 is the Endesga 8 palette.

Created by Endesga. #EDG8

https://lospec.com/palette-list/endesga-8

var PaletteEN4 = Palette{
    {0xFB, 0xF7, 0xF3, 0xFF},
    {0xE5, 0xB0, 0x83, 0xFF},
    {0x42, 0x6E, 0x5D, 0xFF},
    {0x20, 0x28, 0x3D, 0xFF},
}

PaletteEN4 is the EN4 palette.

Created by Endesga. #EN4

https://lospec.com/palette-list/en4

var PaletteFamicube = Palette{
    {0x00, 0x00, 0x00, 0xFF},
    {0x00, 0x17, 0x7D, 0xFF},
    {0x02, 0x4A, 0xCA, 0xFF},
    {0x00, 0x84, 0xFF, 0xFF},
    {0x5B, 0xA8, 0xFF, 0xFF},
    {0x98, 0xDC, 0xFF, 0xFF},
    {0x9B, 0xA0, 0xEF, 0xFF},
    {0x62, 0x64, 0xDC, 0xFF},
    {0x3D, 0x34, 0xA5, 0xFF},
    {0x21, 0x16, 0x40, 0xFF},
    {0x5A, 0x19, 0x91, 0xFF},
    {0x6A, 0x31, 0xCA, 0xFF},
    {0xA6, 0x75, 0xFE, 0xFF},
    {0xE2, 0xC9, 0xFF, 0xFF},
    {0xFE, 0xC9, 0xED, 0xFF},
    {0xD5, 0x9C, 0xFC, 0xFF},
    {0xCC, 0x69, 0xE4, 0xFF},
    {0xA3, 0x28, 0xB3, 0xFF},
    {0x87, 0x16, 0x46, 0xFF},
    {0xCF, 0x3C, 0x71, 0xFF},
    {0xFF, 0x82, 0xCE, 0xFF},
    {0xFF, 0xE9, 0xC5, 0xFF},
    {0xF5, 0xB7, 0x84, 0xFF},
    {0xE1, 0x82, 0x89, 0xFF},
    {0xDA, 0x65, 0x5E, 0xFF},
    {0x82, 0x3C, 0x3D, 0xFF},
    {0x4F, 0x15, 0x07, 0xFF},
    {0xE0, 0x3C, 0x28, 0xFF},
    {0xE2, 0xD7, 0xB5, 0xFF},
    {0xC5, 0x97, 0x82, 0xFF},
    {0xAE, 0x6C, 0x37, 0xFF},
    {0x5C, 0x3C, 0x0D, 0xFF},
    {0x23, 0x17, 0x12, 0xFF},
    {0xAD, 0x4E, 0x1A, 0xFF},
    {0xF6, 0x8F, 0x37, 0xFF},
    {0xFF, 0xE7, 0x37, 0xFF},
    {0xFF, 0xBB, 0x31, 0xFF},
    {0xCC, 0x8F, 0x15, 0xFF},
    {0x93, 0x97, 0x17, 0xFF},
    {0xB6, 0xC1, 0x21, 0xFF},
    {0xEE, 0xFF, 0xA9, 0xFF},
    {0xBE, 0xEB, 0x71, 0xFF},
    {0x8C, 0xD6, 0x12, 0xFF},
    {0x6A, 0xB4, 0x17, 0xFF},
    {0x37, 0x6D, 0x03, 0xFF},
    {0x17, 0x28, 0x08, 0xFF},
    {0x00, 0x4E, 0x00, 0xFF},
    {0x13, 0x9D, 0x08, 0xFF},
    {0x58, 0xD3, 0x32, 0xFF},
    {0x20, 0xB5, 0x62, 0xFF},
    {0x00, 0x60, 0x4B, 0xFF},
    {0x00, 0x52, 0x80, 0xFF},
    {0x0A, 0x98, 0xAC, 0xFF},
    {0x25, 0xE2, 0xCD, 0xFF},
    {0xBD, 0xFF, 0xCA, 0xFF},
    {0x71, 0xA6, 0xA1, 0xFF},
    {0x41, 0x5D, 0x66, 0xFF},
    {0x0D, 0x20, 0x30, 0xFF},
    {0x15, 0x15, 0x15, 0xFF},
    {0x34, 0x34, 0x34, 0xFF},
    {0x7B, 0x7B, 0x7B, 0xFF},
    {0xA8, 0xA8, 0xA8, 0xFF},
    {0xD7, 0xD7, 0xD7, 0xFF},
    {0xFF, 0xFF, 0xFF, 0xFF},
}

PaletteFamicube is the Famicube palette.

Created by Arne as part of his Famicube Project.

https://lospec.com/palette-list/famicube

var PaletteGo = Palette{
    {0x00, 0xAD, 0xD8, 0xFF},
    {0x0B, 0xB5, 0xDB, 0xFF},
    {0x31, 0xBE, 0xE0, 0xFF},
    {0x4D, 0xC7, 0xE4, 0xFF},
    {0x68, 0xCC, 0xE7, 0xFF},
    {0x82, 0xD2, 0xE8, 0xFF},
    {0x9C, 0xDB, 0xED, 0xFF},
    {0xB5, 0xE3, 0xF0, 0xFF},
    {0xE9, 0xF3, 0xF9, 0xFF},
    {0x5D, 0xC9, 0xE2, 0xFF},
    {0x7D, 0xD1, 0xE6, 0xFF},
    {0x98, 0xD9, 0xEA, 0xFF},
    {0x98, 0xD5, 0xEC, 0xFF},
    {0xC5, 0xE9, 0xF2, 0xFF},
    {0xD5, 0xEE, 0xF5, 0xFF},
    {0xE3, 0xF4, 0xF8, 0xFF},
    {0xEE, 0xF8, 0xFB, 0xFF},
    {0xF7, 0xFC, 0xFD, 0xFF},
    {0x00, 0xA2, 0x9C, 0xFF},
    {0x5B, 0xC4, 0xBA, 0xFF},
    {0x77, 0xCB, 0xC5, 0xFF},
    {0x94, 0xD5, 0xD1, 0xFF},
    {0xAD, 0xDE, 0xDB, 0xFF},
    {0xC4, 0xE7, 0xE4, 0xFF},
    {0xD7, 0xEE, 0xED, 0xFF},
    {0xE8, 0xF5, 0xF4, 0xFF},
    {0xD8, 0xEE, 0xEB, 0xFF},
    {0xCE, 0x32, 0x62, 0xFF},
    {0xD7, 0x5C, 0x7E, 0xFF},
    {0xDE, 0x7B, 0x96, 0xFF},
    {0xE4, 0x97, 0xAD, 0xFF},
    {0xEB, 0xB1, 0xC1, 0xFF},
    {0xF2, 0xC9, 0xD4, 0xFF},
    {0xF6, 0xDC, 0xE3, 0xFF},
    {0xF9, 0xEA, 0xEE, 0xFF},
    {0xF1, 0xD2, 0xD3, 0xFF},
    {0x00, 0x00, 0x00, 0xFF},
    {0x1B, 0x1A, 0x1A, 0xFF},
    {0x2E, 0x2D, 0x2C, 0xFF},
    {0x40, 0x3D, 0x3D, 0xFF},
    {0x53, 0x50, 0x50, 0xFF},
    {0x68, 0x64, 0x64, 0xFF},
    {0x7F, 0x7C, 0x7B, 0xFF},
    {0x9A, 0x97, 0x96, 0xFF},
    {0xB5, 0xB2, 0xB3, 0xFF},
    {0xFD, 0xDD, 0x00, 0xFF},
    {0xFE, 0xE3, 0x3D, 0xFF},
    {0xFF, 0xE9, 0x67, 0xFF},
    {0xFF, 0xED, 0x88, 0xFF},
    {0xFE, 0xF1, 0xA4, 0xFF},
    {0xFE, 0xF5, 0xBE, 0xFF},
    {0xFE, 0xF9, 0xD5, 0xFF},
    {0xFF, 0xFB, 0xE6, 0xFF},
    {0xFF, 0xFE, 0xF3, 0xFF},
    {0x00, 0x75, 0x8D, 0xFF},
    {0x55, 0x57, 0x59, 0xFF},
    {0x40, 0x2B, 0x56, 0xFF},
    {0xDB, 0xD9, 0xD6, 0xFF},
}

PaletteGo is the Go palette.

https://golang.org/s/brandbook

var PaletteInk = Palette{
    {0x1F, 0x1F, 0x29, 0xFF},
    {0x41, 0x3A, 0x42, 0xFF},
    {0x59, 0x60, 0x70, 0xFF},
    {0x96, 0xA2, 0xB3, 0xFF},
    {0xEA, 0xF0, 0xD8, 0xFF},
}

PaletteInk is the Ink palette.

Created by AprilSundae.

https://lospec.com/palette-list/ink

var PaletteNYX8 = Palette{
    {0x08, 0x14, 0x1E, 0xFF},
    {0x0F, 0x2A, 0x3F, 0xFF},
    {0x20, 0x39, 0x4F, 0xFF},
    {0xF6, 0xD6, 0xBD, 0xFF},
    {0xC3, 0xA3, 0x8A, 0xFF},
    {0x99, 0x75, 0x77, 0xFF},
    {0x81, 0x62, 0x71, 0xFF},
    {0x4E, 0x49, 0x5F, 0xFF},
}

PaletteNYX8 is the NYX8 palette.

Palette created by Javier Guerrero.

https://lospec.com/palette-list/nyx8

var PaletteNight16 = Palette{
    {0x0F, 0x0F, 0x1E, 0xFF},
    {0xFF, 0xF8, 0xBC, 0xFF},
    {0x0C, 0x21, 0x33, 0xFF},
    {0x48, 0x58, 0x6D, 0xFF},
    {0x79, 0xA0, 0xB0, 0xFF},
    {0xB0, 0xCE, 0x9D, 0xFF},
    {0x65, 0x7F, 0x49, 0xFF},
    {0x3F, 0x45, 0x36, 0xFF},
    {0xB9, 0x9D, 0x6A, 0xFF},
    {0xFF, 0xDD, 0x91, 0xFF},
    {0xDD, 0x94, 0x5B, 0xFF},
    {0x9A, 0x51, 0x42, 0xFF},
    {0x64, 0x4B, 0x48, 0xFF},
    {0x33, 0x30, 0x33, 0xFF},
    {0x76, 0x70, 0x88, 0xFF},
    {0xC5, 0xA3, 0xB3, 0xFF},
}

PaletteNight16 is the Night 16 palette.

3rd place winner of the PixelJoint 16 color palette competition (2015). Created by Night.

https://lospec.com/palette-list/night-16

var PalettePICO8 = Palette{
    {0x00, 0x00, 0x00, 0xFF},
    {0x5F, 0x57, 0x4F, 0xFF},
    {0xC2, 0xC3, 0xC7, 0xFF},
    {0xFF, 0xF1, 0xE8, 0xFF},
    {0xFF, 0xEC, 0x27, 0xFF},
    {0xFF, 0xA3, 0x00, 0xFF},
    {0xFF, 0xCC, 0xAA, 0xFF},
    {0xAB, 0x52, 0x36, 0xFF},
    {0xFF, 0x77, 0xA8, 0xFF},
    {0xFF, 0x00, 0x4D, 0xFF},
    {0x83, 0x76, 0x9C, 0xFF},
    {0x7E, 0x25, 0x53, 0xFF},
    {0x29, 0xAD, 0xFF, 0xFF},
    {0x1D, 0x2B, 0x53, 0xFF},
    {0x00, 0x87, 0x51, 0xFF},
    {0x00, 0xE4, 0x36, 0xFF},
}

PalettePICO8 is the palette used by PICO-8.

The PICO-8 is a virtual video game console created by Lexaloffle Games.

https://lospec.com/palette-list/pico-8

var PaletteSplendor128 = Palette{ /* 128 elements not displayed */

}

PaletteSplendor128 is the Splendor 128 palette.

Created by Adigun Polack as a successor to his AAP-64 palette. #Splendor128

https://lospec.com/palette-list/aap-splendor128

var PaletteTango = Palette{
    {0xFC, 0xE9, 0x4F, 0xFF},
    {0xED, 0xD4, 0x00, 0xFF},
    {0xC4, 0xA0, 0x00, 0xFF},
    {0xFC, 0xAF, 0x3E, 0xFF},
    {0xF5, 0x79, 0x00, 0xFF},
    {0xCE, 0x5C, 0x00, 0xFF},
    {0xE9, 0xB9, 0x6E, 0xFF},
    {0xC1, 0x7D, 0x11, 0xFF},
    {0x8F, 0x59, 0x02, 0xFF},
    {0x8A, 0xE2, 0x34, 0xFF},
    {0x73, 0xD2, 0x16, 0xFF},
    {0x4E, 0x9A, 0x06, 0xFF},
    {0x72, 0x9F, 0xCF, 0xFF},
    {0x34, 0x65, 0xA4, 0xFF},
    {0x20, 0x4A, 0x87, 0xFF},
    {0xAD, 0x7F, 0xA8, 0xFF},
    {0x75, 0x50, 0x7B, 0xFF},
    {0x5C, 0x35, 0x66, 0xFF},
    {0xEF, 0x29, 0x29, 0xFF},
    {0xCC, 0x00, 0x00, 0xFF},
    {0xA4, 0x00, 0x00, 0xFF},
    {0xEE, 0xEE, 0xEC, 0xFF},
    {0xD3, 0xD7, 0xCF, 0xFF},
    {0xBA, 0xBD, 0xB6, 0xFF},
    {0x88, 0x8A, 0x85, 0xFF},
    {0x55, 0x57, 0x53, 0xFF},
    {0x2E, 0x34, 0x36, 0xFF},
}

PaletteTango is the Tango palette.

http://en.wikipedia.org/wiki/Tango_Desktop_Project#Palette

var PalettesByNumberOfColors = func() map[int]PaletteLookup {
    pnc := map[int]PaletteLookup{}

    for n, p := range PaletteByName {
        c := len(p)

        if pnc[c] == nil {
            pnc[c] = PaletteLookup{}
        }

        pnc[c][n] = p
    }

    return pnc
}()

PalettesByNumberOfColors is a map of int to Palettes.

var (
    Pi = 3.14159265358979323846264338327950288419716939937510582097494459 // https://oeis.org/A000796
)

Mathematical constants.

var ZP = image.ZP

ZP is the zero image.Point.

var ZR = image.ZR

ZR is the zero image.Rectangle.

var ZV = Vec{0, 0}

ZV is a zero vector.

var ZV3 = Vec3{0, 0, 0}

ZV3 is the zero Vec3

func Base64EncodedPNG Uses

func Base64EncodedPNG(src image.Image) string

Base64EncodedPNG encodes the given image into a string using base64.StdEncoding.

func Base64ImgTag Uses

func Base64ImgTag(src image.Image) string

Base64ImgTag returns a HTML tag for an img with its src set to a base64 encoded PNG.

func Clamp Uses

func Clamp(x, min, max float64) float64

Clamp returns x clamped to the interval [min, max].

If x is less than min, min is returned. If x is more than max, max is returned. Otherwise, x is returned.

Code:

Dump(
    Clamp(-5, 10, 10),
    Clamp(15, 10, 15),
    Clamp(25, 10, 20),
)

Output:

10
15
20

func CmplxCos Uses

func CmplxCos(x complex128) complex128

CmplxCos returns the cosine of x.

Code:

Log("%f %f %f",
    CmplxCos(complex(1, 2)),
    CmplxCos(complex(2, 3)),
    CmplxCos(complex(4, 5)),
)

Output:

(2.032723-3.051898i) (-4.189626-9.109228i) (-48.506859+56.157175i)

func CmplxCosh Uses

func CmplxCosh(x complex128) complex128

CmplxCosh returns the hyperbolic cosine of x.

Code:

Log("%f %f %f",
    CmplxCosh(complex(1, 2)),
    CmplxCosh(complex(2, 3)),
    CmplxCosh(complex(4, 5)),
)

Output:

(-0.642148+1.068607i) (-3.724546+0.511823i) (7.746313-26.168964i)

func CmplxPhase Uses

func CmplxPhase(x complex128) float64

CmplxPhase returns the phase (also called the argument) of x. The returned value is in the range [-Pi, Pi].

Code:

Log("%f %f %f",
    CmplxPhase(complex(1, 2)),
    CmplxPhase(complex(2, 3)),
    CmplxPhase(complex(4, 5)),
)

Output:

1.107149 0.982794 0.896055

func CmplxPow Uses

func CmplxPow(x, y complex128) complex128

CmplxPow returns x**y, the base-x exponential of y.

Code:

Log("%f %f",
    CmplxPow(complex(1, 2), complex(2, 3)),
    CmplxPow(complex(4, 5), complex(5, 6)),
)

Output:

(-0.015133-0.179867i) (-49.591090+4.323851i)

func CmplxSin Uses

func CmplxSin(x complex128) complex128

CmplxSin returns the sine of x.

Code:

Log("%f %f %f",
    CmplxSin(complex(1, 2)),
    CmplxSin(complex(2, 3)),
    CmplxSin(complex(4, 5)),
)

Output:

(3.165779+1.959601i) (9.154499-4.168907i) (-56.162274-48.502455i)

func CmplxSinh Uses

func CmplxSinh(x complex128) complex128

CmplxSinh returns the hyperbolic sine of x.

Code:

Log("%f %f %f",
    CmplxSinh(complex(1, 2)),
    CmplxSinh(complex(2, 3)),
    CmplxSinh(complex(4, 5)),
)

Output:

(-0.489056+1.403119i) (-3.590565+0.530921i) (7.741118-26.186527i)

func CmplxSqrt Uses

func CmplxSqrt(x complex128) complex128

CmplxSqrt returns the square root of x. The result r is chosen so that real(r) ≥ 0 and imag(r) has the same sign as imag(x).

Code:

Log("%f %f %f",
    CmplxSqrt(complex(1, 2)),
    CmplxSqrt(complex(2, 3)),
    CmplxSqrt(complex(4, 5)),
)

Output:

(1.272020+0.786151i) (1.674149+0.895977i) (2.280693+1.096158i)

func CmplxTan Uses

func CmplxTan(x complex128) complex128

CmplxTan returns the tangent of x.

Code:

Log("%f %f %f",
    CmplxTan(complex(1, 2)),
    CmplxTan(complex(2, 3)),
    CmplxTan(complex(4, 5)),
)

Output:

(0.033813+1.014794i) (-0.003764+1.003239i) (0.000090+1.000013i)

func CmplxTanh Uses

func CmplxTanh(x complex128) complex128

CmplxTanh returns the hyperbolic tangent of x.

Code:

Log("%f %f %f",
    CmplxTanh(complex(1, 2)),
    CmplxTanh(complex(2, 3)),
    CmplxTanh(complex(4, 5)),
)

Output:

(1.166736-0.243458i) (0.965386-0.009884i) (1.000563-0.000365i)

func ColorGray Uses

func ColorGray(y uint8) color.Gray

ColorGray construcs a color.Gray.

func ColorGray16 Uses

func ColorGray16(y uint16) color.Gray16

ColorGray16 construcs a color.Gray16.

func ColorNRGBA Uses

func ColorNRGBA(r, g, b, a uint8) color.NRGBA

ColorNRGBA constructs a color.NRGBA.

func ColorRGBA Uses

func ColorRGBA(r, g, b, a uint8) color.RGBA

ColorRGBA constructs a color.RGBA.

func ColorWithAlpha Uses

func ColorWithAlpha(c color.Color, a uint8) color.NRGBA

ColorWithAlpha creates a new color.RGBA based on the provided color.Color and alpha arguments.

func DecodeImage Uses

func DecodeImage(r io.Reader) (image.Image, error)

DecodeImage decodes an image from the provided io.Reader.

func DecodeImageBytes Uses

func DecodeImageBytes(b []byte) (image.Image, error)

DecodeImageBytes decodes an image from the provided []byte.

func DecodePNG Uses

func DecodePNG(r io.Reader) (image.Image, error)

DecodePNG decodes a PNG from the provided io.Reader.

func DecodePNGBytes Uses

func DecodePNGBytes(b []byte) (image.Image, error)

DecodePNGBytes decodes a PNG from the provided []byte.

func Draw Uses

func Draw(dst draw.Image, r image.Rectangle, src image.Image)

Draw draws src on dst, at the zero point using draw.Src.

func DrawCicleFast Uses

func DrawCicleFast(dst draw.Image, u Vec, radius float64, c color.Color)

DrawCicleFast draws a (crude) filled circle.

func DrawCircle Uses

func DrawCircle(dst draw.Image, u Vec, radius, thickness float64, c color.Color)

DrawCircle draws a circle with radius and thickness. (filled if thickness == 0)

Code:

dst := NewPaletted(15, 13, Palette1Bit, ColorWhite)

DrawCircle(dst, V(7, 6), 6, 3, ColorBlack)

for y := 0; y < dst.Bounds().Dy(); y++ {
    for x := 0; x < dst.Bounds().Dx(); x++ {
        if dst.Index(x, y) == 0 {
            Printf("▓▓")
        } else {
            Printf("░░")
        }
    }
    Printf("\n")
}

Output:

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

Code:

dst := NewPaletted(15, 13, Palette1Bit, ColorWhite)

DrawCircle(dst, V(7, 6), 6, 0, ColorBlack)

for y := 0; y < dst.Bounds().Dy(); y++ {
    for x := 0; x < dst.Bounds().Dx(); x++ {
        if dst.Index(x, y) == 0 {
            Printf("▓▓")
        } else {
            Printf("░░")
        }
    }
    Printf("\n")
}

Output:

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

func DrawCircleFilled Uses

func DrawCircleFilled(dst draw.Image, u Vec, radius float64, c color.Color)

DrawCircleFilled draws a filled circle.

func DrawColor Uses

func DrawColor(dst draw.Image, r image.Rectangle, c color.Color)

DrawColor draws an image.Rectangle of uniform color on dst.

func DrawColorOver Uses

func DrawColorOver(dst draw.Image, r image.Rectangle, c color.Color)

DrawColorOver draws an image.Rectangle of uniform color over dst.

func DrawLine Uses

func DrawLine(dst draw.Image, from, to Vec, thickness float64, c color.Color)

DrawLine draws a line of the given color. A thickness of <= 1 is drawn using DrawBresenhamLine.

func DrawLineBresenham Uses

func DrawLineBresenham(dst draw.Image, from, to Vec, c color.Color)

DrawLineBresenham draws a line using Bresenham's line algorithm.

http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

Code:

dst := NewPaletted(10, 5, Palette1Bit, ColorWhite)

DrawLineBresenham(dst, V(1, 1), V(8, 3), ColorBlack)

for y := 0; y < dst.Bounds().Dy(); y++ {
    for x := 0; x < dst.Bounds().Dx(); x++ {
        if dst.Index(x, y) == 0 {
            Printf("▓▓")
        } else {
            Printf("░░")
        }
    }
    Printf("\n")
}

Output:

░░░░░░░░░░░░░░░░░░░░
░░▓▓▓▓░░░░░░░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░░░░░░░▓▓▓▓░░
░░░░░░░░░░░░░░░░░░░░

Code:

dst := NewPaletted(10, 5, Palette1Bit, ColorWhite)

DrawLineBresenham(dst, V(7, 3), V(6, 1), ColorBlack)

for y := 0; y < dst.Bounds().Dy(); y++ {
    for x := 0; x < dst.Bounds().Dx(); x++ {
        if dst.Index(x, y) == 0 {
            Printf("▓▓")
        } else {
            Printf("░░")
        }
    }
    Printf("\n")
}

Output:

░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░▓▓░░░░░░
░░░░░░░░░░░░▓▓░░░░░░
░░░░░░░░░░░░░░▓▓░░░░
░░░░░░░░░░░░░░░░░░░░

func DrawOver Uses

func DrawOver(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point)

DrawOver draws src over dst.

func DrawPalettedImage Uses

func DrawPalettedImage(dst PalettedDrawImage, r image.Rectangle, src PalettedImage)

DrawPalettedImage draws a PalettedImage over a PalettedDrawImage.

func DrawPalettedLayer Uses

func DrawPalettedLayer(dst *Paletted, r image.Rectangle, src *Layer)

DrawPalettedLayer draws a *Layer over a *Paletted. (slightly faster than using the generic DrawPalettedImage)

func DrawPointCircle Uses

func DrawPointCircle(dst draw.Image, p image.Point, radius, thickness float64, c color.Color)

DrawPointCircle draws a circle at the given point.

func DrawPolygon Uses

func DrawPolygon(dst draw.Image, p Polygon, thickness float64, c color.Color)

DrawPolygon filled or as line polygons if the thickness is >= 1.

func DrawPolyline Uses

func DrawPolyline(dst draw.Image, pl Polyline, thickness float64, c color.Color)

DrawPolyline draws a polyline with the given color and thickness.

func DrawSrc Uses

func DrawSrc(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point)

DrawSrc draws src on dst.

func DrawTriangles Uses

func DrawTriangles(dst draw.Image, triangles []Triangle)

DrawTriangles draws triangles on dst.

func DrawTrianglesOver Uses

func DrawTrianglesOver(dst draw.Image, triangles []Triangle)

DrawTrianglesOver draws triangles over dst.

func DrawTrianglesWireframe Uses

func DrawTrianglesWireframe(dst draw.Image, triangles []Triangle)

DrawTrianglesWireframe draws triangles on dst.

func Dump Uses

func Dump(a ...interface{})

Dump all of the arguments to standard output.

Code:

Dump([]string{"foo", "bar"})

Output:

[foo bar]

func EachImageVec Uses

func EachImageVec(src image.Image, dir Vec, fn func(u Vec))

EachImageVec calls the provided function for each Vec in the provided image in the given direction.

gfx.V(1,1) to call the function on each pixel starting from the top left.

func EachPixel Uses

func EachPixel(r image.Rectangle, fn func(x, y int))

EachPixel calls the provided function for each pixel in the provided rectangle.

func EncodePNG Uses

func EncodePNG(w io.Writer, src image.Image) error

EncodePNG encodes an image as PNG to the provided io.Writer.

func Errorf Uses

func Errorf(format string, a ...interface{}) error

Errorf constructs a formatted error.

Code:

err := Errorf("foo %d and bar %s", 123, "abc")

fmt.Println(err)

Output:

foo 123 and bar abc

func Get Uses

func Get(rawurl string) (*http.Response, error)

Get performs a HTTP GET request using the DefaultClient.

func GetImage Uses

func GetImage(rawurl string) (image.Image, error)

GetImage retrieves a remote image using DefaultClient

func GetPNG Uses

func GetPNG(rawurl string) (image.Image, error)

GetPNG retrieves a remote PNG using DefaultClient

func IR Uses

func IR(x0, y0, x1, y1 int) image.Rectangle

IR returns an image.Rectangle for the given input.

func IntAbs Uses

func IntAbs(x int) int

IntAbs returns the absolute value of x.

Code:

Dump(
    IntAbs(10),
    IntAbs(-5),
)

Output:

10
5

func IntClamp Uses

func IntClamp(x, min, max int) int

IntClamp returns x clamped to the interval [min, max].

If x is less than min, min is returned. If x is more than max, max is returned. Otherwise, x is returned.

func IntMax Uses

func IntMax(x, y int) int

IntMax returns the larger of x or y.

Code:

Dump(
    IntMax(1, 2),
    IntMax(2, 1),
    IntMax(-1, -2),
)

Output:

2
2
-1

func IntMin Uses

func IntMin(x, y int) int

IntMin returns the smaller of x or y.

Code:

Dump(
    IntMin(1, 2),
    IntMin(2, 1),
    IntMin(-1, -2),
)

Output:

1
1
-2

func Lerp Uses

func Lerp(a, b, t float64) float64

Lerp does linear interpolation between two values.

Code:

Dump(
    Lerp(0, 2, 0.1),
    Lerp(1, 10, 0.5),
    Lerp(2, 4, 0.5),
)

Output:

0.2
5.5
3

func LerpColors Uses

func LerpColors(c0, c1 color.Color, t float64) color.Color

LerpColors performs linear interpolation between two colors.

func Log Uses

func Log(format string, a ...interface{})

Log to standard output.

Code:

Log("Foo: %d", 123)

Output:

Foo: 123

func MathAbs Uses

func MathAbs(x float64) float64

MathAbs returns the absolute value of x.

Code:

Dump(
    MathAbs(-2),
    MathAbs(-1),
    MathAbs(0),
    MathAbs(1),
    MathAbs(2),
)

Output:

2
1
0
1
2

func MathAtan Uses

func MathAtan(x float64) float64

MathAtan returns the arctangent, in radians, of x.

func MathCeil Uses

func MathCeil(x float64) float64

MathCeil returns the least integer value greater than or equal to x.

Code:

Dump(
    MathCeil(0.2),
    MathCeil(1.4),
    MathCeil(2.6),
)

Output:

1
2
3

func MathCos Uses

func MathCos(x float64) float64

MathCos returns the cosine of the radian argument x.

Code:

Dump(
    MathCos(1),
    MathCos(2),
    MathCos(3),
)

Output:

0.5403023058681398
-0.4161468365471424
-0.9899924966004454

func MathCosh Uses

func MathCosh(x float64) float64

MathCosh returns the hyperbolic cosine of x.

func MathFloor Uses

func MathFloor(x float64) float64

MathFloor returns the greatest integer value less than or equal to x.

Code:

Dump(
    MathFloor(0.2),
    MathFloor(1.4),
    MathFloor(2.6),
)

Output:

0
1
2

func MathHypot Uses

func MathHypot(p, q float64) float64

MathHypot returns Sqrt(p*p + q*q), taking care to avoid unnecessary overflow and underflow.

Code:

Dump(
    MathHypot(15, 8),
    MathHypot(5, 12),
    MathHypot(3, 4),
)

Output:

17
13
5

func MathLog Uses

func MathLog(x float64) float64

MathLog returns the natural logarithm of x.

func MathMax Uses

func MathMax(x, y float64) float64

MathMax returns the larger of x or y.

Code:

Dump(
    MathMax(-1, 1),
    MathMax(1, 2),
    MathMax(3, 2),
)

Output:

1
2
3

func MathMin Uses

func MathMin(x, y float64) float64

MathMin returns the smaller of x or y.

Code:

Dump(
    MathMin(-1, 1),
    MathMin(1, 2),
    MathMin(3, 2),
)

Output:

-1
1
2

func MathPow Uses

func MathPow(x, y float64) float64

MathPow returns x**y, the base-x exponential of y.

func MathRound Uses

func MathRound(x float64) float64

MathRound returns the nearest integer, rounding half away from zero.

func MathSin Uses

func MathSin(x float64) float64

MathSin returns the sine of the radian argument x.

Code:

Dump(
    MathSin(1),
    MathSin(2),
    MathSin(3),
)

Output:

0.8414709848078965
0.9092974268256816
0.1411200080598672

func MathSinh Uses

func MathSinh(x float64) float64

MathSinh returns the hyperbolic sine of x.

func MathSqrt Uses

func MathSqrt(x float64) float64

MathSqrt returns the square root of x.

Code:

Dump(
    MathSqrt(1),
    MathSqrt(2),
    MathSqrt(3),
)

Output:

1
1.4142135623730951
1.7320508075688772

func MathTan Uses

func MathTan(x float64) float64

MathTan returns the tangent of the radian argument x.

func Mix Uses

func Mix(m draw.Image, x, y int, c color.Color)

Mix the current pixel color at x and y with the given color.

func MixPoint Uses

func MixPoint(dst draw.Image, p image.Point, c color.Color)

MixPoint the current pixel color at the image.Point with the given color.

func MustOpenImage Uses

func MustOpenImage(fn string) image.Image

MustOpenImage decodes an image using the provided file name. Panics on error.

func NewGray Uses

func NewGray(r image.Rectangle) *image.Gray

NewGray returns a new Gray image with the given bounds.

func NewGray16 Uses

func NewGray16(r image.Rectangle) *image.Gray16

NewGray16 returns a new Gray16 image with the given bounds. (For example useful for height maps)

func NewImage Uses

func NewImage(w, h int, colors ...color.Color) *image.RGBA

NewImage creates an image of the given size (optionally filled with a color)

func NewNRGBA Uses

func NewNRGBA(r image.Rectangle) *image.NRGBA

NewNRGBA returns a new NRGBA image with the given bounds.

func NewRGBA Uses

func NewRGBA(r image.Rectangle) *image.RGBA

NewRGBA returns a new RGBA image with the given bounds.

func NewResizedImage Uses

func NewResizedImage(src image.Image, w, h int) image.Image

NewResizedImage returns a new image with the provided dimensions.

func NewResizedRGBA Uses

func NewResizedRGBA(src image.Image, r image.Rectangle) *image.RGBA

NewResizedRGBA returns a new RGBA image with the provided dimensions.

func NewScaledImage Uses

func NewScaledImage(src image.Image, s float64) image.Image

NewScaledImage returns a new image scaled by the provided scaling factor.

Code:

src := NewTile(Palette1Bit, 8, []uint8{
    1, 1, 1, 1, 1, 1, 1, 1,
    1, 0, 0, 0, 0, 0, 0, 1,
    1, 0, 0, 1, 1, 0, 0, 1,
    1, 0, 1, 1, 1, 1, 0, 1,
    1, 0, 0, 0, 0, 0, 0, 1,
    1, 1, 1, 1, 1, 1, 1, 1,
})

dst := NewScaledImage(src, 2.0)

func(images ...image.Image) {
    for _, m := range images {
        for y := 0; y < m.Bounds().Dy(); y++ {
            for x := 0; x < m.Bounds().Dx(); x++ {
                if r, _, _, _ := m.At(x, y).RGBA(); r == 0 {
                    Printf("▓▓")
                } else {
                    Printf("░░")
                }
            }
            Printf("\n")
        }
        Printf("\n")
    }
}(src, dst)

Output:

░░░░░░░░░░░░░░░░
░░▓▓▓▓▓▓▓▓▓▓▓▓░░
░░▓▓▓▓░░░░▓▓▓▓░░
░░▓▓░░░░░░░░▓▓░░
░░▓▓▓▓▓▓▓▓▓▓▓▓░░
░░░░░░░░░░░░░░░░

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓░░░░░░░░░░░░░░░░▓▓▓▓░░░░
░░░░▓▓▓▓░░░░░░░░░░░░░░░░▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

func NewScaledRGBA Uses

func NewScaledRGBA(src image.Image, s float64) *image.RGBA

NewScaledRGBA returns a new RGBA image scaled by the provided scaling factor.

func NewUniform Uses

func NewUniform(c color.Color) *image.Uniform

NewUniform creates a new uniform image of the given color.

func OpenImage Uses

func OpenImage(fn string) (image.Image, error)

OpenImage decodes an image using the provided file name.

func Playground Uses

func Playground(src image.Image)

Playground displays image on The Go Playground using the IMAGE: base64 encoded PNG “hack”

func Printf Uses

func Printf(format string, a ...interface{}) (n int, err error)

Printf formats according to a format specifier and writes to standard output.

Code:

Printf("%q %.01f", "foo bar", 1.23)

Output:

"foo bar" 1.2

func Pt Uses

func Pt(x, y int) image.Point

Pt returns an image.Point for the given x and y.

func RandFloat64 Uses

func RandFloat64() float64

RandFloat64 returns, as a float64, a pseudo-random number in [0.0,1.0) from the default Source.

func RandIntn Uses

func RandIntn(n int) int

RandIntn returns, as an int, a non-negative pseudo-random number in [0,n) from the default Source. It panics if n <= 0.

func RandSeed Uses

func RandSeed(seed int64)

RandSeed uses the provided seed value to initialize the default Source to a deterministic state. If Seed is not called, the generator behaves as if seeded by Seed(1). Seed values that have the same remainder when divided by 2^31-1 generate the same pseudo-random sequence. RandSeed, unlike the Rand.Seed method, is safe for concurrent use.

func ReadFile Uses

func ReadFile(fn string, rf ReadFunc) error

ReadFile opens a file and calls the given ReadFunc.

func ReadJSON Uses

func ReadJSON(fn string, v interface{}) error

ReadJSON opens and decodes a JSON file.

func ResizeImage Uses

func ResizeImage(dst draw.Image, src image.Image)

ResizeImage using nearest neighbor scaling on dst from src.

func SavePNG Uses

func SavePNG(fn string, src image.Image) error

SavePNG saves an image using the provided file name.

func Set Uses

func Set(dst draw.Image, x, y int, c color.Color)

Set x and y to the given color.

func SetPoint Uses

func SetPoint(dst draw.Image, p image.Point, c color.Color)

SetPoint to the given color.

func SetVec Uses

func SetVec(dst draw.Image, u Vec, c color.Color)

SetVec to the given color.

func Sign Uses

func Sign(x float64) float64

Sign returns -1 for values < 0, 0 for 0, and 1 for values > 0.

Code:

Dump(
    Sign(-2),
    Sign(0),
    Sign(2),
)

Output:

-1
0
1

func SortSlice Uses

func SortSlice(slice interface{}, less func(i, j int) bool)

SortSlice sorts the provided slice given the provided less function.

func Sprintf Uses

func Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

type Animation Uses

type Animation struct {
    Frames   []image.Image   // The successive images.
    Palettes []color.Palette // The successive palettes.

    Delay int // Delay between each of the frames.

    // LoopCount controls the number of times an animation will be
    // restarted during display.
    // A LoopCount of 0 means to loop forever.
    // A LoopCount of -1 means to show each frame only once.
    // Otherwise, the animation is looped LoopCount+1 times.
    LoopCount int
}

Animation represents multiple images.

func (*Animation) AddFrame Uses

func (a *Animation) AddFrame(frame image.Image, palette color.Palette)

AddFrame adds a frame to the animation.

func (*Animation) AddPalettedImage Uses

func (a *Animation) AddPalettedImage(frame PalettedImage)

AddPalettedImage adds a frame and palette to the animation.

func (*Animation) EncodeGIF Uses

func (a *Animation) EncodeGIF(w io.Writer) error

EncodeGIF writes the animation to w in GIF format with the given loop count and delay between frames.

func (*Animation) SaveGIF Uses

func (a *Animation) SaveGIF(fn string) error

SaveGIF saves the animation to a GIF using the provided file name.

type BasicTarget Uses

type BasicTarget interface {
    Target

    // SetMatrix sets a Matrix that every point will be projected by.
    SetMatrix(Matrix)
}

BasicTarget is a Target with additional basic adjustment methods.

type Batch Uses

type Batch struct {
    // contains filtered or unexported fields
}

Batch is a Target that allows for efficient drawing of many objects with the same Picture.

To put an object into a Batch, just draw it onto it:

object.Draw(batch)

func NewBatch Uses

func NewBatch(container Triangles, pic Picture) *Batch

NewBatch creates an empty Batch with the specified Picture and container.

The container is where objects get accumulated. Batch will support precisely those Triangles properties, that the supplied container supports. If you retain access to the container and change it, call Dirty to notify Batch about the change.

Note, that if the container does not support TrianglesColor, color masking will not work.

func (*Batch) Clear Uses

func (b *Batch) Clear()

Clear removes all objects from the Batch.

func (*Batch) Dirty Uses

func (b *Batch) Dirty()

Dirty notifies Batch about an external modification of it's container. If you retain access to the Batch's container and change it, call Dirty to notify Batch about the change.

container := &gfx.TrianglesData{}
batch := gfx.NewBatch(container, nil)
container.SetLen(10) // container changed from outside of Batch
batch.Dirty()        // notify Batch about the change

func (*Batch) Draw Uses

func (b *Batch) Draw(t Target)

Draw draws all objects that are currently in the Batch onto another Target.

func (*Batch) MakePicture Uses

func (b *Batch) MakePicture(p Picture) TargetPicture

MakePicture returns a specialized copy of the provided Picture that draws onto this Batch.

func (*Batch) MakeTriangles Uses

func (b *Batch) MakeTriangles(t Triangles) TargetTriangles

MakeTriangles returns a specialized copy of the provided Triangles that draws onto this Batch.

func (*Batch) SetMatrix Uses

func (b *Batch) SetMatrix(m Matrix)

SetMatrix sets a Matrix that every point will be projected by.

type Block Uses

type Block struct {
    Pos   Vec3
    Size  Vec3
    Color BlockColor
}

Block has a position, size and color.

func NewBlock Uses

func NewBlock(pos, size Vec3, ic BlockColor) Block

NewBlock creates a new Block.

func (Block) Behind Uses

func (b Block) Behind(a Block) bool

Behind checks if the box for b is in front of the box for a.

func (Block) Box Uses

func (b Block) Box() Box

Box creates a box for the Block.

func (Block) Corners Uses

func (b Block) Corners(origin Vec3) BlockCorners

Corners returns the screen coordinates for the Block corners.

func (Block) Draw Uses

func (b Block) Draw(dst draw.Image, origin Vec3)

Draw block on dst at origin.

func (Block) DrawBounds Uses

func (b Block) DrawBounds(dst draw.Image, origin Vec3)

DrawBounds for block on dst at origin.

func (Block) DrawOver Uses

func (b Block) DrawOver(dst draw.Image, origin Vec3)

DrawOver draws block over dst at origin.

func (Block) DrawPolygons Uses

func (b Block) DrawPolygons(dst draw.Image, origin Vec3)

DrawPolygons for block on dst at origin.

func (Block) DrawRectangles Uses

func (b Block) DrawRectangles(dst draw.Image, origin Vec3)

DrawRectangles for block on dst at origin.

func (Block) DrawWireframe Uses

func (b Block) DrawWireframe(dst draw.Image, origin Vec3)

DrawWireframe block on dst at origin.

func (Block) Polygons Uses

func (b Block) Polygons(origin Vec3) (shape, top, left, right Polygon)

Polygons returns the shape, top, left and right polygons with coordinates based on origin.

func (Block) Rect Uses

func (b Block) Rect(origin Vec3) Rect

Rect for the block.

func (Block) Shape Uses

func (b Block) Shape(origin Vec3) Polygon

Shape returns the shape Polygon

func (Block) Space Uses

func (b Block) Space() BlockSpace

Space returns the BlockSpace for the Block.

func (Block) Triangles Uses

func (b Block) Triangles(origin Vec3) []Triangle

Triangles for the Block

func (Block) TrianglesData Uses

func (b Block) TrianglesData(origin Vec3) *TrianglesData

TrianglesData creates triangles data for the Block.

type BlockColor Uses

type BlockColor struct {
    Light  color.NRGBA
    Medium color.NRGBA
    Dark   color.NRGBA
}

BlockColor contains a Light, Medium and Dark color.

type BlockCorners Uses

type BlockCorners struct {
    LeftUp    Vec
    LeftDown  Vec
    FrontDown Vec
    RightDown Vec
    RightUp   Vec
    BackUp    Vec
    BackDown  Vec
    FrontUp   Vec
}

BlockCorners contains screen coordinates for all of the corners.

func (BlockCorners) Left Uses

func (bc BlockCorners) Left() Polygon

Left face Polygon.

func (BlockCorners) Rect Uses

func (bc BlockCorners) Rect() Rect

Rect for the Block corners.

func (BlockCorners) Right Uses

func (bc BlockCorners) Right() Polygon

Right face Polygon.

func (BlockCorners) Shape Uses

func (bc BlockCorners) Shape() Polygon

Shape Polygon.

func (BlockCorners) Top Uses

func (bc BlockCorners) Top() Polygon

Top face Polygon.

type BlockSpace Uses

type BlockSpace struct {
    LeftUp    Vec3
    LeftDown  Vec3
    FrontDown Vec3
    RightDown Vec3
    RightUp   Vec3
    BackUp    Vec3
    BackDown  Vec3
    FrontUp   Vec3
}

BlockSpace contains 3D space coordinates for the block corners.

func (BlockSpace) CornerBackDown Uses

func (bs BlockSpace) CornerBackDown(origin Vec3) Vec

CornerBackDown returns the screen coordinate for the BackDown corner.

func (BlockSpace) CornerBackUp Uses

func (bs BlockSpace) CornerBackUp(origin Vec3) Vec

CornerBackUp returns the screen coordinate for the BackUp corner.

func (BlockSpace) CornerFrontDown Uses

func (bs BlockSpace) CornerFrontDown(origin Vec3) Vec

CornerFrontDown returns the screen coordinate for the FrontDown corner.

func (BlockSpace) CornerFrontUp Uses

func (bs BlockSpace) CornerFrontUp(origin Vec3) Vec

CornerFrontUp returns the screen coordinate for the FrontUp corner.

func (BlockSpace) CornerLeftDown Uses

func (bs BlockSpace) CornerLeftDown(origin Vec3) Vec

CornerLeftDown returns the screen coordinate for the LeftDown corner.

func (BlockSpace) CornerLeftUp Uses

func (bs BlockSpace) CornerLeftUp(origin Vec3) Vec

CornerLeftUp returns the screen coordinate for the LeftUp corner.

func (BlockSpace) CornerRightDown Uses

func (bs BlockSpace) CornerRightDown(origin Vec3) Vec

CornerRightDown returns the screen coordinate for the RightDown corner.

func (BlockSpace) CornerRightUp Uses

func (bs BlockSpace) CornerRightUp(origin Vec3) Vec

CornerRightUp returns the screen coordinate for the RightUp corner.

func (BlockSpace) Corners Uses

func (bs BlockSpace) Corners(origin Vec3) BlockCorners

Corners returns the screen coordinates for all of the Block corners.

type Blocks Uses

type Blocks []Block

Blocks is a slice of blocks.

func (*Blocks) Add Uses

func (blocks *Blocks) Add(bs ...Block)

Add appends one or more blocks to the slice of Blocks.

func (*Blocks) AddNewBlock Uses

func (blocks *Blocks) AddNewBlock(pos, size Vec3, ic BlockColor)

AddNewBlock creates a new Block and appends it to the slice.

func (Blocks) Draw Uses

func (blocks Blocks) Draw(dst draw.Image, origin Vec3)

Draw all blocks.

func (Blocks) DrawBounds Uses

func (blocks Blocks) DrawBounds(dst draw.Image, origin Vec3)

DrawBounds for all blocks.

func (Blocks) DrawPolygons Uses

func (blocks Blocks) DrawPolygons(dst draw.Image, origin Vec3)

DrawPolygons draws all of the blocks on the dst image. (using the shape, top and left polygons at the given origin)

func (Blocks) DrawRectangles Uses

func (blocks Blocks) DrawRectangles(dst draw.Image, origin Vec3)

DrawRectangles for all blocks.

func (Blocks) DrawWireframes Uses

func (blocks Blocks) DrawWireframes(dst draw.Image, origin Vec3)

DrawWireframes for all blocks.

func (Blocks) Sort Uses

func (blocks Blocks) Sort()

Sort blocks to be drawn starting from max X, max Y and min Z.

type Box Uses

type Box struct {
    Min Vec3
    Max Vec3
}

Box is a 3D cuboid with a min and max Vec3

func B Uses

func B(minX, minY, minZ, maxX, maxY, maxZ float64) Box

B returns a new Box with given the Min and Max coordinates.

func NewBox Uses

func NewBox(min, max Vec3) Box

NewBox creates a new Box.

func (Box) Behind Uses

func (b Box) Behind(a Box) bool

Behind checks if b is in front of the a box.

func (Box) Overlaps Uses

func (b Box) Overlaps(a Box) bool

Overlaps checks if two boxes overlap or not.

type CIELab Uses

type CIELab struct {
    L   float64
    A   float64
    B   float64
}

CIELab represents a color in CIE-L*ab.

func (CIELab) DeltaC Uses

func (c1 CIELab) DeltaC(c2 CIELab) float64

DeltaC calculates Delta C* for two CIE-L*ab colors.

CIE-a*1, CIE-b*1 //Color #1 CIE-L*ab values CIE-a*2, CIE-b*2 //Color #2 CIE-L*ab values

Delta C* = sqrt( ( CIE-a*2 ^ 2 ) + ( CIE-b*2 ^ 2 ) )

- sqrt( ( CIE-a*1 ^ 2 ) + ( CIE-b*1 ^ 2 ) )

func (CIELab) DeltaE Uses

func (c1 CIELab) DeltaE(c2 CIELab) float64

DeltaE calculates Delta E* for two CIE-L*ab colors.

CIE-L*1, CIE-a*1, CIE-b*1 //Color #1 CIE-L*ab values CIE-L*2, CIE-a*2, CIE-b*2 //Color #2 CIE-L*ab values

Delta E* = sqrt( ( ( CIE-L*1 - CIE-L*2 ) ^ 2 )

+ ( ( CIE-a*1 - CIE-a*2 ) ^ 2 )
+ ( ( CIE-b*1 - CIE-b*2 ) ^ 2 ) )

func (CIELab) DeltaH Uses

func (c1 CIELab) DeltaH(c2 CIELab) float64

DeltaH calculates Delta H* for two CIE-L*ab colors.

CIE-a*1, CIE-b*1 //Color #1 CIE-L*ab values CIE-a*2, CIE-b*2 //Color #2 CIE-L*ab values

xDE = sqrt( ( CIE-a*2 ^ 2 ) + ( CIE-b*2 ^ 2 ) )

- sqrt( ( CIE-a*1 ^ 2 ) + ( CIE-b*1 ^ 2 ) )

Delta H* = sqrt( ( CIE-a*2 - CIE-a*1 ) ^ 2

+ ( CIE-b*2 - CIE-b*1 ) ^ 2 - ( xDE ^ 2 ) )

type Circle Uses

type Circle struct {
    Center Vec
    Radius float64
}

Circle is a 2D circle. It is defined by two properties:

- Center vector
- Radius float64

func C Uses

func C(center Vec, radius float64) Circle

C returns a new Circle with the given radius and center coordinates.

Note that a negative radius is valid.

func (Circle) Area Uses

func (c Circle) Area() float64

Area returns the area of the Circle.

func (Circle) Contains Uses

func (c Circle) Contains(u Vec) bool

Contains checks whether a vector `u` is contained within this Circle (including it's perimeter).

func (Circle) Intersect Uses

func (c Circle) Intersect(d Circle) Circle

Intersect returns the maximal Circle which is covered by both `c` and `d`.

If `c` and `d` don't overlap, this function returns a zero-sized circle at the centerpoint between the two Circle's centers.

func (Circle) IntersectRect Uses

func (c Circle) IntersectRect(r Rect) Vec

IntersectRect returns a minimal required Vector, such that moving the circle by that vector would stop the Circle and the Rect intersecting. This function returns a zero-vector if the Circle and Rect do not overlap, and if only the perimeters touch.

This function will return a non-zero vector if:

- The Rect contains the Circle, partially or fully
- The Circle contains the Rect, partially of fully

func (Circle) Moved Uses

func (c Circle) Moved(delta Vec) Circle

Moved returns the Circle moved by the given vector delta.

func (Circle) Norm Uses

func (c Circle) Norm() Circle

Norm returns the Circle in normalized form - this sets the radius to its absolute value.

func (Circle) Resized Uses

func (c Circle) Resized(radiusDelta float64) Circle

Resized returns the Circle resized by the given delta. The Circles center is use as the anchor.

func (Circle) String Uses

func (c Circle) String() string

String returns the string representation of the Circle.

func (Circle) Union Uses

func (c Circle) Union(d Circle) Circle

Union returns the minimal Circle which covers both `c` and `d`.

type Degrees Uses

type Degrees float64

Degrees of arc.

func (Degrees) Radians Uses

func (d Degrees) Radians() float64

Radians convert degrees to radians.

type Domain Uses

type Domain []float64

Domain of values.

func (Domain) Max Uses

func (d Domain) Max() float64

Max value in the Domain.

func (Domain) Min Uses

func (d Domain) Min() float64

Min value in the Domain.

type DrawTarget Uses

type DrawTarget struct {
    // contains filtered or unexported fields
}

DrawTarget draws to a draw.Image, projected through a Matrix.

func NewDrawTarget Uses

func NewDrawTarget(dst draw.Image) *DrawTarget

NewDrawTarget creates a new draw target.

func (*DrawTarget) At Uses

func (dt *DrawTarget) At(x, y int) color.Color

At retrieves the color at (x, y).

func (*DrawTarget) Bounds Uses

func (dt *DrawTarget) Bounds() image.Rectangle

Bounds of the draw target.

func (*DrawTarget) Center Uses

func (dt *DrawTarget) Center() Vec

Center vector of the draw target.

func (*DrawTarget) ColorModel Uses

func (dt *DrawTarget) ColorModel() color.Model

ColorModel of the draw target.

func (*DrawTarget) MakePicture Uses

func (dt *DrawTarget) MakePicture(pic Picture) TargetPicture

MakePicture creates a TargetPicture for the provided Picture.

func (*DrawTarget) MakeTriangles Uses

func (dt *DrawTarget) MakeTriangles(t Triangles) TargetTriangles

MakeTriangles creates TargetTriangles for the given Triangles

func (*DrawTarget) Set Uses

func (dt *DrawTarget) Set(x, y int, c color.Color)

Set the color at (x, y). (Projected through the draw target Matrix)

func (*DrawTarget) SetMatrix Uses

func (dt *DrawTarget) SetMatrix(mat Matrix)

SetMatrix sets the matrix of the draw target.

type Drawer Uses

type Drawer struct {
    Triangles Triangles
    Picture   Picture
    // contains filtered or unexported fields
}

Drawer glues all the fundamental interfaces (Target, Triangles, Picture) into a coherent and the only intended usage pattern.

Drawer makes it possible to draw any combination of Triangles and Picture onto any Target efficiently.

To create a Drawer, just assign it's Triangles and Picture fields:

d := gfx.Drawer{Triangles: t, Picture: p}

If Triangles is nil, nothing will be drawn. If Picture is nil, Triangles will be drawn without a Picture.

Whenever you change the Triangles, call Dirty to notify Drawer that Triangles changed. You don't need to notify Drawer about a change of the Picture.

Note, that Drawer caches the results of MakePicture from Targets it's drawn to for each Picture it's set to. What it means is that using a Drawer with an unbounded number of Pictures leads to a memory leak, since Drawer caches them and never forgets. In such a situation, create a new Drawer for each Picture.

func (*Drawer) Dirty Uses

func (d *Drawer) Dirty()

Dirty marks the Triangles of this Drawer as changed. If not called, changes will not be visible when drawing.

func (*Drawer) Draw Uses

func (d *Drawer) Draw(t Target)

Draw efficiently draws Triangles with Picture onto the provided Target.

If Triangles is nil, nothing will be drawn. If Picture is nil, Triangles will be drawn without a Picture.

type EndShape Uses

type EndShape int

EndShape specifies the shape of an end of a line or a curve.

const (
    // NoEndShape leaves a line point with no special end shape.
    NoEndShape EndShape = iota

    // SharpEndShape is a sharp triangular end shape.
    SharpEndShape

    // RoundEndShape is a circular end shape.
    RoundEndShape
)

type Error Uses

type Error string

Error is a string that implements the error interface.

func (Error) Error Uses

func (e Error) Error() string

Error implements the error interface.

type Float64Scaler Uses

type Float64Scaler interface {
    ScaleFloat64(float64) float64
}

Float64Scaler can scale a float64 to another float64.

type GeoPoint Uses

type GeoPoint struct {
    Lon float64
    Lat float64
}

GeoPoint represents a geographic point with Lat/Lon.

func GP Uses

func GP(lat, lon float64) GeoPoint

GP creates a new GeoPoint

func NewGeoPointFromTileNumbers Uses

func NewGeoPointFromTileNumbers(zoom, x, y int) GeoPoint

NewGeoPointFromTileNumbers creates a new GeoPoint based on the given tile numbers. https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_numbers_to_lon..2Flat.

func (GeoPoint) GeoTile Uses

func (gp GeoPoint) GeoTile(zoom int) GeoTile

GeoTile for the GeoPoint at the given zoom level.

func (GeoPoint) In Uses

func (gp GeoPoint) In(gt GeoTile, tileSize int) Vec

In returns a Vec for the position of the GeoPoint in a GeoTile.

func (GeoPoint) Vec Uses

func (gp GeoPoint) Vec(tileSize, zoom int) Vec

Vec returns a vector for the geo point based on the given tileSize and zoom level.

type GeoTile Uses

type GeoTile struct {
    Zoom int
    X    int
    Y    int
}

GeoTile consists of a Zoom level, X and Y values.

func GT Uses

func GT(zoom, x, y int) GeoTile

GT creates a new GeoTile.

func (GeoTile) AddXY Uses

func (gt GeoTile) AddXY(x, y int) GeoTile

AddXY adds x and y.

func (GeoTile) Bounds Uses

func (gt GeoTile) Bounds(dst image.Image, gp GeoPoint, tileSize int) image.Rectangle

Bounds returns an image.Rectangle for the GeoTile based on the dst, gp and tileSize.

func (GeoTile) Draw Uses

func (gt GeoTile) Draw(dst draw.Image, gp GeoPoint, src image.Image)

Draw the tile on dst.

func (GeoTile) E Uses

func (gt GeoTile) E() GeoTile

E is the tile to the east.

func (GeoTile) GeoPoint Uses

func (gt GeoTile) GeoPoint() GeoPoint

GeoPoint for the GeoTile.

func (GeoTile) GetImage Uses

func (gt GeoTile) GetImage(format string) (image.Image, error)

GetImage for the tile.

func (GeoTile) N Uses

func (gt GeoTile) N() GeoTile

N is the tile to the north.

func (GeoTile) NE Uses

func (gt GeoTile) NE() GeoTile

NE is the tile to the northeast.

func (GeoTile) NW Uses

func (gt GeoTile) NW() GeoTile

NW is the tile to the northwest.

func (GeoTile) Neighbors Uses

func (gt GeoTile) Neighbors() GeoTiles

Neighbors returns the neighboring tiles.

func (GeoTile) Rawurl Uses

func (gt GeoTile) Rawurl(format string) string

Rawurl formats a URL string with Zoom, X and Y.

func (GeoTile) S Uses

func (gt GeoTile) S() GeoTile

S is the tile to the south.

func (GeoTile) SE Uses

func (gt GeoTile) SE() GeoTile

SE is the tile to the southeast.

func (GeoTile) SW Uses

func (gt GeoTile) SW() GeoTile

SW is the tile to the southwest.

func (GeoTile) Vec Uses

func (gt GeoTile) Vec(gp GeoPoint, tileSize int) Vec

Vec returns the Vec for the GeoPoint in the GeoTile.

func (GeoTile) W Uses

func (gt GeoTile) W() GeoTile

W is the tile to the west.

type GeoTileServer Uses

type GeoTileServer struct {
    Format string
}

GeoTileServer represents a tile server.

func GTS Uses

func GTS(format string) GeoTileServer

GTS creates a GeoTileServer.

func (GeoTileServer) DrawNeighbors Uses

func (gts GeoTileServer) DrawNeighbors(dst draw.Image, gt GeoTile, gp GeoPoint) error

DrawNeighbors on dst.

func (GeoTileServer) DrawTile Uses

func (gts GeoTileServer) DrawTile(dst draw.Image, gt GeoTile, gp GeoPoint) error

DrawTile on dst.

func (GeoTileServer) DrawTileAndNeighbors Uses

func (gts GeoTileServer) DrawTileAndNeighbors(dst draw.Image, gt GeoTile, gp GeoPoint) error

DrawTileAndNeighbors on dst.

func (GeoTileServer) GetImage Uses

func (gts GeoTileServer) GetImage(gt GeoTile) (image.Image, error)

GetImage for the given GeoTile from the tile server.

type GeoTiles Uses

type GeoTiles []GeoTile

GeoTiles is a slice of GeoTile.

type HSL Uses

type HSL struct {
    Hue        float64
    Saturation float64
    Lightness  float64
}

HSL is the hue, saturation and lightness color representation. - Hue [0,360] - Saturation [0,1] - Lightness [0,1]

func ColorToHSL Uses

func ColorToHSL(c color.Color) HSL

ColorToHSL converts a color into HSL.

func (HSL) Components Uses

func (hsl HSL) Components() (h, s, l float64)

Components in HSL.

func (HSL) RGBA Uses

func (hsl HSL) RGBA() color.RGBA

RGBA converts a HSL color value to color.RGBA.

type HSV Uses

type HSV struct {
    Hue        float64
    Saturation float64
    Value      float64
}

HSV is the hue, saturation and value color representation. - Hue [0,360] - Saturation [0,1] - Value [0,1]

func ColorToHSV Uses

func ColorToHSV(c color.Color) HSV

ColorToHSV converts a color into HSV.

func (HSV) Components Uses

func (hsv HSV) Components() (h, s, v float64)

Components in HSV.

func (HSV) RGBA Uses

func (hsv HSV) RGBA() color.RGBA

RGBA converts a HSV color value to color.RGBA.

type HTTP Uses

type HTTP struct {
    *http.Client
    UserAgent string
}

HTTP is the HTTP client and user agent used by the gfx package.

type HunterLab Uses

type HunterLab struct {
    L   float64
    A   float64
    B   float64
}

HunterLab represents a color in Hunter-Lab.

func (HunterLab) XYZ Uses

func (h HunterLab) XYZ(ref XYZ) XYZ

XYZ converts from HunterLab to XYZ.

Reference-X, Y and Z refer to specific illuminants and observers. Common reference values are available below in this same page.

var_Ka = ( 175.0 / 198.04 ) * ( Reference-Y + Reference-X ) var_Kb = ( 70.0 / 218.11 ) * ( Reference-Y + Reference-Z )

Y = ( ( Hunter-L / Reference-Y ) ^ 2 ) * 100.0 X = ( Hunter-a / var_Ka * sqrt( Y / Reference-Y ) + ( Y / Reference-Y ) ) * Reference-X Z = - ( Hunter-b / var_Kb * sqrt( Y / Reference-Y ) - ( Y / Reference-Y ) ) * Reference-Z

type IMDraw Uses

type IMDraw struct {
    Color     color.Color
    Picture   Vec
    Intensity float64
    Precision int
    EndShape  EndShape
    // contains filtered or unexported fields
}

IMDraw is an immediate-mode-like shape drawer and BasicTarget. IMDraw supports TrianglesPosition, TrianglesColor, TrianglesPicture and PictureColor.

IMDraw, other than a regular BasicTarget, is used to draw shapes. To draw shapes, you first need to Push some points to IMDraw:

imd := gfx.NewIMDraw(pic) // use nil pic if you only want to draw primitive shapes
imd.Push(gfx.V(100, 100))
imd.Push(gfx.V(500, 100))

Once you have Pushed some points, you can use them to draw a shape, such as a line:

imd.Line(20) // draws a 20 units thick line

Set exported fields to change properties of Pushed points:

imd.Color = gfx.RGB(1, 0, 0)
imd.Push(gfx.V(200, 200))
imd.Circle(400, 0)

Here is the list of all available point properties (need to be set before Pushing a point):

- Color     - applies to all
- Picture   - coordinates, only applies to filled polygons
- Intensity - picture intensity, only applies to filled polygons
- Precision - curve drawing precision, only applies to circles and ellipses
- EndShape  - shape of the end of a line, only applies to lines and outlines

And here's the list of all shapes that can be drawn (all, except for line, can be filled or outlined):

- Line
- Polygon
- Circle
- Circle arc
- Ellipse
- Ellipse arc

func NewIMDraw Uses

func NewIMDraw(pic Picture) *IMDraw

NewIMDraw creates a new empty IMDraw. An optional Picture can be used to draw with a Picture.

If you just want to draw primitive shapes, pass nil as the Picture.

func (*IMDraw) Circle Uses

func (imd *IMDraw) Circle(radius, thickness float64)

Circle draws a circle of the specified radius around each Pushed point. If the thickness is 0, the circle will be filled, otherwise a circle outline of the specified thickness will be drawn.

func (*IMDraw) CircleArc Uses

func (imd *IMDraw) CircleArc(radius, low, high, thickness float64)

CircleArc draws a circle arc of the specified radius around each Pushed point. If the thickness is 0, the arc will be filled, otherwise will be outlined. The arc starts at the low angle and continues to the high angle. If low<high, the arc will be drawn counterclockwise. Otherwise it will be clockwise. The angles are not normalized by any means.

imd.CircleArc(40, 0, 8*math.Pi, 0)

This line will fill the whole circle 4 times.

func (*IMDraw) Clear Uses

func (imd *IMDraw) Clear()

Clear removes all drawn shapes from the IM. This does not remove Pushed points.

func (*IMDraw) Draw Uses

func (imd *IMDraw) Draw(t Target)

Draw draws all currently drawn shapes inside the IM onto another Target.

Note, that IMDraw's matrix have no effect here.

func (*IMDraw) Ellipse Uses

func (imd *IMDraw) Ellipse(radius Vec, thickness float64)

Ellipse draws an ellipse of the specified radius in each axis around each Pushed points. If the thickness is 0, the ellipse will be filled, otherwise an ellipse outline of the specified thickness will be drawn.

func (*IMDraw) EllipseArc Uses

func (imd *IMDraw) EllipseArc(radius Vec, low, high, thickness float64)

EllipseArc draws an ellipse arc of the specified radius in each axis around each Pushed point. If the thickness is 0, the arc will be filled, otherwise will be outlined. The arc starts at the low angle and continues to the high angle. If low<high, the arc will be drawn counterclockwise. Otherwise it will be clockwise. The angles are not normalized by any means.

imd.EllipseArc(gfx.V(100, 50), 0, 8*math.Pi, 0)

This line will fill the whole ellipse 4 times.

func (*IMDraw) Line Uses

func (imd *IMDraw) Line(thickness float64)

Line draws a polyline of the specified thickness between the Pushed points.

func (*IMDraw) MakePicture Uses

func (imd *IMDraw) MakePicture(p Picture) TargetPicture

MakePicture returns a specialized copy of the provided Picture that draws onto this IMDraw.

func (*IMDraw) MakeTriangles Uses

func (imd *IMDraw) MakeTriangles(t Triangles) TargetTriangles

MakeTriangles returns a specialized copy of the provided Triangles that draws onto this IMDraw.

func (*IMDraw) Polygon Uses

func (imd *IMDraw) Polygon(thickness float64)

Polygon draws a polygon from the Pushed points. If the thickness is 0, the convex polygon will be filled. Otherwise, an outline of the specified thickness will be drawn. The outline does not have to be convex.

Note, that the filled polygon does not have to be strictly convex. The way it's drawn is that a triangle is drawn between each two adjacent points and the first Pushed point. You can use this property to draw certain kinds of concave polygons.

func (*IMDraw) Push Uses

func (imd *IMDraw) Push(pts ...Vec)

Push adds some points to the IM queue. All Pushed points will have the same properties except for the position.

func (*IMDraw) Rectangle Uses

func (imd *IMDraw) Rectangle(thickness float64)

Rectangle draws a rectangle between each two subsequent Pushed points. Drawing a rectangle between two points means drawing a rectangle with sides parallel to the axes of the coordinate system, where the two points specify it's two opposite corners.

If the thickness is 0, rectangles will be filled, otherwise will be outlined with the given thickness.

func (*IMDraw) Reset Uses

func (imd *IMDraw) Reset()

Reset restores all point properties to defaults and removes all Pushed points.

This does not affect matrix set by SetMatrix.

func (*IMDraw) SetMatrix Uses

func (imd *IMDraw) SetMatrix(m Matrix)

SetMatrix sets a Matrix that all further points will be transformed by.

type Layer Uses

type Layer struct {
    Tileset *Tileset
    Width   int // Width of the layer in number of tiles.
    Data    LayerData
}

Layer represents a layer of paletted tiles.

func NewLayer Uses

func NewLayer(tileset *Tileset, width int, data LayerData) *Layer

NewLayer creates a new layer.

func (*Layer) AlphaAt Uses

func (l *Layer) AlphaAt(x, y int) uint8

AlphaAt returns the alpha value at (x, y).

func (*Layer) At Uses

func (l *Layer) At(x, y int) color.Color

At returns the color at (x, y).

func (*Layer) Bounds Uses

func (l *Layer) Bounds() image.Rectangle

Bounds returns the bounds of the paletted layer.

func (*Layer) ColorIndexAt Uses

func (l *Layer) ColorIndexAt(x, y int) uint8

ColorIndexAt returns the palette index of the pixel at (x, y).

func (*Layer) ColorModel Uses

func (l *Layer) ColorModel() color.Model

ColorModel returns the color model for the paletted layer.

func (*Layer) ColorPalette Uses

func (l *Layer) ColorPalette() color.Palette

ColorPalette retrieves the layer palette.

func (*Layer) DataAt Uses

func (l *Layer) DataAt(dx, dy int) int

DataAt returns the data at (dx, dy).

func (*Layer) GfxPalette Uses

func (l *Layer) GfxPalette() Palette

GfxPalette retrieves the layer palette.

func (*Layer) Index Uses

func (l *Layer) Index(x, y int) int

Index returns the tile index at (x, y). (Short for TileIndexAt)

func (*Layer) NRGBAAt Uses

func (l *Layer) NRGBAAt(x, y int) color.NRGBA

NRGBAAt returns the color.RGBA at (x, y).

func (*Layer) Put Uses

func (l *Layer) Put(dx, dy, index int)

Put changes the tile index at (dx, dy). (Short for SetTileIndex)

func (*Layer) SetTileIndex Uses

func (l *Layer) SetTileIndex(dx, dy, index int)

SetTileIndex changes the tile index at (dx, dy).

func (*Layer) TileAt Uses

func (l *Layer) TileAt(x, y int) image.PalettedImage

TileAt returns the tile image at (x, y).

func (*Layer) TileIndexAt Uses

func (l *Layer) TileIndexAt(x, y int) int

TileIndexAt returns the tile index at (x, y).

func (*Layer) TileSize Uses

func (l *Layer) TileSize() image.Point

TileSize returns the tileset tile size.

type LayerData Uses

type LayerData []int

LayerData is the data for a layer.

func (LayerData) Size Uses

func (ld LayerData) Size(cols int) image.Point

Size returns the size of the layer data given the number of columns.

type LinearScaler Uses

type LinearScaler struct {
    // contains filtered or unexported fields
}

LinearScaler can scale domain values to a range values.

func NewLinearScaler Uses

func NewLinearScaler() LinearScaler

NewLinearScaler creates a new linear scaler.

func (LinearScaler) Domain Uses

func (ls LinearScaler) Domain(d ...float64) LinearScaler

Domain returns a LinearScaler with the given domain.

func (LinearScaler) Range Uses

func (ls LinearScaler) Range(r ...float64) LinearScaler

Range returns a LinearScaler with the given range.

func (LinearScaler) ScaleFloat64 Uses

func (ls LinearScaler) ScaleFloat64(x float64) float64

ScaleFloat64 from domain to range.

OLD PERCENT = (x - OLD MIN) / (OLD MAX - OLD MIN) NEW X = ((NEW MAX - NEW MIN) * OLD PERCENT) + NEW MIN

type Matrix Uses

type Matrix [6]float64

Matrix is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such as movement, scaling and rotations.

Matrix has a handful of useful methods, each of which adds a transformation to the matrix. For example:

gfx.IM.Moved(gfx.V(100, 200)).Rotated(gfx.ZV, math.Pi/2)

This code creates a Matrix that first moves everything by 100 units horizontally and 200 units vertically and then rotates everything by 90 degrees around the origin.

Layout is: [0] [2] [4] [1] [3] [5]

0   0   1  (implicit row)

func (Matrix) Chained Uses

func (m Matrix) Chained(next Matrix) Matrix

Chained adds another Matrix to this one. All tranformations by the next Matrix will be applied after the transformations of this Matrix.

func (Matrix) Moved Uses

func (m Matrix) Moved(delta Vec) Matrix

Moved moves everything by the delta vector.

func (Matrix) Project Uses

func (m Matrix) Project(u Vec) Vec

Project applies all transformations added to the Matrix to a vector u and returns the result.

Time complexity is O(1).

func (Matrix) Rotated Uses

func (m Matrix) Rotated(around Vec, angle float64) Matrix

Rotated rotates everything around a given point by the given angle in radians.

func (Matrix) RotatedDegrees Uses

func (m Matrix) RotatedDegrees(around Vec, degrees float64) Matrix

RotatedDegrees rotates everything around a given point by the given number of degrees.

func (Matrix) Scaled Uses

func (m Matrix) Scaled(around Vec, scale float64) Matrix

Scaled scales everything around a given point by the scale factor.

func (Matrix) ScaledXY Uses

func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix

ScaledXY scales everything around a given point by the scale factor in each axis respectively.

func (Matrix) String Uses

func (m Matrix) String() string

String returns a string representation of the Matrix.

m := gfx.IM
fmt.Println(m) // Matrix(1 0 0 | 0 1 0)

func (Matrix) Unproject Uses

func (m Matrix) Unproject(u Vec) Vec

Unproject does the inverse operation to Project.

Time complexity is O(1).

type Palette Uses

type Palette []color.NRGBA

Palette is a slice of colors.

func (Palette) AsColorPalette Uses

func (p Palette) AsColorPalette() color.Palette

AsColorPalette converts the Palette to a color.Palette.

func (Palette) At Uses

func (p Palette) At(t float64) color.Color

At returns the color at the given float64 value (range 0-1)

func (Palette) CmplxPhaseAt Uses

func (p Palette) CmplxPhaseAt(z complex128) color.Color

CmplxPhaseAt returns the color at the phase of the given complex128 value.

func (Palette) Color Uses

func (p Palette) Color(n int) color.NRGBA

Color returns the color at index n.

func (Palette) Convert Uses

func (p Palette) Convert(c color.Color) color.Color

Convert returns the palette color closest to c in Euclidean R,G,B space.

func (Palette) Index Uses

func (p Palette) Index(c color.Color) int

Index returns the index of the palette color closest to c in Euclidean R,G,B,A space.

func (Palette) Len Uses

func (p Palette) Len() int

Len returns the number of colors in the palette.

func (Palette) Random Uses

func (p Palette) Random() color.NRGBA

Random color from the palette.

func (Palette) Sort Uses

func (p Palette) Sort(less func(i, j int) bool)

Sort palette.

func (Palette) SortByHue Uses

func (p Palette) SortByHue()

SortByHue sorts based on (HSV) Hue.

func (Palette) Tile Uses

func (p Palette) Tile(src image.Image) *Paletted

Tile returns a new image based on the input image, but with colors from the palette.

type PaletteLookup Uses

type PaletteLookup map[PaletteName]Palette

PaletteLookup is a map of PaletteName to Palette.

type PaletteName Uses

type PaletteName string

PaletteName is a palette name.

type Paletted Uses

type Paletted struct {
    // Pix holds the image's pixels, as palette indices. The pixel at
    // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1].
    Pix []uint8
    // Stride is the Pix stride (in bytes) between vertically adjacent pixels.
    Stride int
    // Rect is the image's bounds.
    Rect image.Rectangle
    // Palette is the image's palette.
    Palette Palette
}

Paletted is an in-memory image of uint8 indices into a given palette.

func NewPaletted Uses

func NewPaletted(w, h int, p Palette, colors ...color.Color) *Paletted

NewPaletted returns a new paletted image with the given width, height and palette.

func NewPalettedImage Uses

func NewPalettedImage(r image.Rectangle, p Palette) *Paletted

NewPalettedImage returns a new paletted image with the given bounds and palette.

func NewResizedPalettedImage Uses

func NewResizedPalettedImage(src PalettedImage, w, h int) *Paletted

NewResizedPalettedImage returns an image with the provided dimensions.

func NewScaledPalettedImage Uses

func NewScaledPalettedImage(src PalettedImage, s float64) *Paletted

NewScaledPalettedImage returns a paletted image scaled by the provided scaling factor.

func NewTile Uses

func NewTile(p Palette, cols int, pix []uint8) *Paletted

NewTile returns a new paletted image with the given pix, stride and palette.

func (*Paletted) AlphaAt Uses

func (p *Paletted) AlphaAt(x, y int) uint8

AlphaAt returns the alpha value at (x, y).

func (*Paletted) At Uses

func (p *Paletted) At(x, y int) color.Color

At returns the color at (x, y).

func (*Paletted) Bounds Uses

func (p *Paletted) Bounds() image.Rectangle

Bounds returns the bounds of the paletted image.

func (*Paletted) ColorIndexAt Uses

func (p *Paletted) ColorIndexAt(x, y int) uint8

ColorIndexAt returns the color index at (x, y).

func (*Paletted) ColorModel Uses

func (p *Paletted) ColorModel() color.Model

ColorModel returns the color model of the paletted image.

func (*Paletted) ColorPalette Uses

func (p *Paletted) ColorPalette() color.Palette

ColorPalette returns the color palette of the paletted image.

func (*Paletted) GfxPalette Uses

func (p *Paletted) GfxPalette() Palette

GfxPalette returns the gfx palette of the paletted image.

func (*Paletted) Index Uses

func (p *Paletted) Index(x, y int) uint8

Index returns the color index at (x, y). (Short for ColorIndexAt)

func (*Paletted) NRGBAAt Uses

func (p *Paletted) NRGBAAt(x, y int) color.NRGBA

NRGBAAt returns the color.NRGBA at (x, y).

func (*Paletted) Opaque Uses

func (p *Paletted) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque.

func (*Paletted) PixOffset Uses

func (p *Paletted) PixOffset(x, y int) int

PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).

func (*Paletted) Pixels Uses

func (p *Paletted) Pixels() []uint8

Pixels returns the pixels of the paletted image as a []uint8.

func (*Paletted) Put Uses

func (p *Paletted) Put(x, y int, index uint8)

Put changes the color index at (x, y). (Short for SetColorIndex)

func (*Paletted) Set Uses

func (p *Paletted) Set(x, y int, c color.Color)

Set changes the color at (x, y).

func (*Paletted) SetColorIndex Uses

func (p *Paletted) SetColorIndex(x, y int, index uint8)

SetColorIndex changes the color index at (x, y).

func (*Paletted) SubImage Uses

func (p *Paletted) SubImage(r image.Rectangle) image.Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type PalettedDrawImage Uses

type PalettedDrawImage interface {
    SetColorIndex(int, int, uint8)
    PalettedImage
}

PalettedDrawImage interface is implemented by *Paletted

type PalettedImage Uses

type PalettedImage interface {
    GfxPalette() Palette
    ColorPalette() color.Palette
    NRGBAAt(int, int) color.NRGBA
    AlphaAt(int, int) uint8
    image.PalettedImage
}

PalettedImage interface is implemented by *Paletted

type Palettes Uses

type Palettes []Palette

Palettes is a slice of Palette.

type Picture Uses

type Picture interface {
    // Bounds returns the rectangle of the Picture. All data is located witih this rectangle.
    // Querying properties outside the rectangle should return default value of that property.
    Bounds() Rect
}

Picture represents a rectangular area of raster data, such as a color. It has Bounds which specify the rectangle where data is located.

type PictureColor Uses

type PictureColor interface {
    Picture
    Color(at Vec) color.NRGBA
}

PictureColor specifies Picture with Color property, so that every position inside the Picture's Bounds has a color.

Positions outside the Picture's Bounds must return full transparent (Alpha(0)).

type Points Uses

type Points []image.Point

Points are a list of points.

func (Points) Polygon Uses

func (pts Points) Polygon() Polygon

Polygon based on the points.

type Polygon Uses

type Polygon []Vec

Polygon is represented by a list of vectors.

func (Polygon) Bounds Uses

func (p Polygon) Bounds() image.Rectangle

Bounds return the bounds of the polygon rectangle.

func (Polygon) EachPixel Uses

func (p Polygon) EachPixel(m image.Image, fn func(x, y int))

EachPixel calls the provided function for each pixel in the polygon rectangle bounds.

func (Polygon) Fill Uses

func (p Polygon) Fill(dst draw.Image, c color.Color) (drawCount int)

Fill polygon on the image with the given color.

func (Polygon) Outline Uses

func (p Polygon) Outline(dst draw.Image, thickness float64, c color.Color)

Outline draws an outline of the polygon on dst.

func (Polygon) Project Uses

func (p Polygon) Project(m Matrix) Polygon

Project creates a new Polygon with all vertexes projected through the given Matrix.

func (Polygon) Rect Uses

func (p Polygon) Rect() Rect

Rect is the polygon rectangle.

type Polyline Uses

type Polyline []Polygon

Polyline is a slice of polygons forming a line.

func NewPolyline Uses

func NewPolyline(p Polygon, t float64) Polyline

NewPolyline constructs a slice of line polygons.

type Range Uses

type Range []float64

Range of values.

func (Range) First Uses

func (r Range) First() float64

First value in the Range.

func (Range) Last Uses

func (r Range) Last() float64

Last value in the Range.

type ReadFunc Uses

type ReadFunc func(r io.Reader) error

ReadFunc is a func that takes a io.Reader and returns an error.

func DecodeJSONFunc Uses

func DecodeJSONFunc(v interface{}) ReadFunc

DecodeJSONFunc returns a function that takes a reader, and decodes into the given value.

type Rect Uses

type Rect struct {
    Min, Max Vec
}

Rect is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two points, Min and Max.

The invariant should hold, that Max's components are greater or equal than Min's components respectively.

func BoundsToRect Uses

func BoundsToRect(ir image.Rectangle) Rect

BoundsToRect converts an image.Rectangle to a Rect.

func NewRect Uses

func NewRect(min, max Vec) Rect

NewRect creates a new Rect.

func R Uses

func R(minX, minY, maxX, maxY float64) Rect

R returns a new Rect given the Min and Max coordinates.

Note that the returned rectangle is not automatically normalized.

func (Rect) Area Uses

func (r Rect) Area() float64

Area returns the area of r. If r is not normalized, area may be negative.

func (Rect) Bounds Uses

func (r Rect) Bounds() image.Rectangle

Bounds returns the bounds of the rectangle.

func (Rect) Center Uses

func (r Rect) Center() Vec

Center returns the position of the center of the Rect.

func (Rect) CenterOrigin Uses

func (r Rect) CenterOrigin(v Vec, z float64) Vec3

CenterOrigin returns a Vec3 based on Rect.Center() scaled by v, and its Z component set to the provided z.

func (Rect) Contains Uses

func (r Rect) Contains(u Vec) bool

Contains checks whether a vector u is contained within this Rect (including it's borders).

func (Rect) Draw Uses

func (r Rect) Draw(dst draw.Image, src image.Image)

Draw draws Rect to src over dst, at the zero point.

func (Rect) DrawColor Uses

func (r Rect) DrawColor(dst draw.Image, c color.Color)

DrawColor draws Rect with a uniform color on dst.

func (Rect) DrawColorOver Uses

func (r Rect) DrawColorOver(dst draw.Image, c color.Color)

DrawColorOver draws Rect with a uniform color over dst.

func (Rect) EachVec Uses

func (r Rect) EachVec(dir Vec, fn func(p Vec))

EachVec calls the provided function for each vec in the given direction.

func (Rect) H Uses

func (r Rect) H() float64

H returns the height of the Rect.

func (Rect) Intersect Uses

func (r Rect) Intersect(s Rect) Rect

Intersect returns the maximal Rect which is covered by both r and s. Rects r and s must be normalized.

If r and s don't overlap, this function returns R(0, 0, 0, 0).

func (Rect) IntersectCircle Uses

func (r Rect) IntersectCircle(c Circle) Vec

IntersectCircle returns a minimal required Vector, such that moving the circle by that vector would stop the Circle and the Rect intersecting. This function returns a zero-vector if the Circle and Rect do not overlap, and if only the perimeters touch.

This function will return a non-zero vector if:

- The Rect contains the Circle, partially or fully
- The Circle contains the Rect, partially of fully

func (Rect) Moved Uses

func (r Rect) Moved(delta Vec) Rect

Moved returns the Rect moved (both Min and Max) by the given vector delta.

func (Rect) Norm Uses

func (r Rect) Norm() Rect

Norm returns the Rect in normal form, such that Max is component-wise greater or equal than Min.

func (Rect) Overlaps Uses

func (r Rect) Overlaps(s Rect) bool

Overlaps checks whether one Rect overlaps another Rect.

func (Rect) Resized Uses

func (r Rect) Resized(anchor, size Vec) Rect

Resized returns the Rect resized to the given size while keeping the position of the given anchor.

r.Resized(r.Min, size)      // resizes while keeping the position of the lower-left corner
r.Resized(r.Max, size)      // same with the top-right corner
r.Resized(r.Center(), size) // resizes around the center

This function does not make sense for resizing a rectangle of zero area and will panic. Use ResizedMin in the case of zero area.

func (Rect) ResizedMin Uses

func (r Rect) ResizedMin(size Vec) Rect

ResizedMin returns the Rect resized to the given size while keeping the position of the Rect's Min.

Sizes of zero area are safe here.

func (Rect) Size Uses

func (r Rect) Size() Vec

Size returns the vector of width and height of the Rect.

func (Rect) String Uses

func (r Rect) String() string

String returns the string representation of the Rect.

r := gfx.R(100, 50, 200, 300)
r.String()     // returns "gfx.R(100, 50, 200, 300)"
fmt.Println(r) // gfx.R(100, 50, 200, 300)

func (Rect) Union Uses

func (r Rect) Union(s Rect) Rect

Union returns the minimal Rect which covers both r and s. Rects r and s must be normalized.

func (Rect) W Uses

func (r Rect) W() float64

W returns the width of the Rect.

type SignedDistance Uses

type SignedDistance struct {
    Vec
}

SignedDistance holds 2D signed distance functions based on https://iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm

func (SignedDistance) Annular Uses

func (sd SignedDistance) Annular(v, r float64) float64

Annular signed distance function shape

func (SignedDistance) Circle Uses

func (sd SignedDistance) Circle(r float64) float64

Circle primitive

func (SignedDistance) CircleFunc Uses

func (SignedDistance) CircleFunc(r float64) SignedDistanceFunc

CircleFunc creates a SignedDistanceFunc for a circle with the given radius.

func (SignedDistance) EquilateralTriangle Uses

func (sd SignedDistance) EquilateralTriangle(s float64) float64

EquilateralTriangle primitive

func (SignedDistance) EquilateralTriangleFunc Uses

func (SignedDistance) EquilateralTriangleFunc(s float64) SignedDistanceFunc

EquilateralTriangleFunc creates a SignedDistanceFunc for an equilateral triangle with the given size.

func (SignedDistance) IsoscelesTriangle Uses

func (sd SignedDistance) IsoscelesTriangle(q Vec) float64

IsoscelesTriangle primitive

func (SignedDistance) IsoscelesTriangleFunc Uses

func (SignedDistance) IsoscelesTriangleFunc(q Vec) SignedDistanceFunc

IsoscelesTriangleFunc creates a SignedDistanceFunc for an isosceles triangle with the given size.

func (SignedDistance) Line Uses

func (sd SignedDistance) Line(a, b Vec) float64

Line primitive

func (SignedDistance) LineFunc Uses

func (SignedDistance) LineFunc(a, b Vec) SignedDistanceFunc

LineFunc cleates a SignedDistanceFunc for a line with the given start and end.

func (SignedDistance) OpIntersection Uses

func (sd SignedDistance) OpIntersection(x, y float64) float64

OpIntersection basic boolean operation for intersection.

func (SignedDistance) OpMoved Uses

func (sd SignedDistance) OpMoved(d Vec, sdf SignedDistanceFunc) float64

OpMoved moves result of sdf by the given delta. (Relative to the identity matrix)

func (SignedDistance) OpRepeat Uses

func (sd SignedDistance) OpRepeat(c Vec, sdf SignedDistanceFunc) float64

OpRepeat repeats based on the given c vector.

func (SignedDistance) OpSmoothIntersection Uses

func (sd SignedDistance) OpSmoothIntersection(x, y, k float64) float64

OpSmoothIntersection smooth operation for intersection.

func (SignedDistance) OpSmoothSubtraction Uses

func (sd SignedDistance) OpSmoothSubtraction(x, y, k float64) float64

OpSmoothSubtraction smooth operation for subtraction.

func (SignedDistance) OpSmoothUnion Uses

func (sd SignedDistance) OpSmoothUnion(x, y, k float64) float64

OpSmoothUnion smooth operation for union.

func (SignedDistance) OpSubtraction Uses

func (sd SignedDistance) OpSubtraction(x, y float64) float64

OpSubtraction basic boolean operation for subtraction.

func (SignedDistance) OpSymX Uses

func (sd SignedDistance) OpSymX(sdf SignedDistanceFunc) float64

OpSymX symmetry operation for X.

func (SignedDistance) OpSymXY Uses

func (sd SignedDistance) OpSymXY(sdf SignedDistanceFunc) float64

OpSymXY symmetry operation for X and Y.

func (SignedDistance) OpSymY Uses

func (sd SignedDistance) OpSymY(sdf SignedDistanceFunc) float64

OpSymY symmetry operation for Y.

func (SignedDistance) OpTx Uses

func (sd SignedDistance) OpTx(t Matrix, sdf SignedDistanceFunc) float64

OpTx translates using the given matrix.

func (SignedDistance) OpUnion Uses

func (sd SignedDistance) OpUnion(x, y float64) float64

OpUnion basic boolean operation for union.

func (SignedDistance) Rectangle Uses

func (sd SignedDistance) Rectangle(b Vec) float64

Rectangle primitive

func (SignedDistance) RectangleFunc Uses

func (SignedDistance) RectangleFunc(b Vec) SignedDistanceFunc

RectangleFunc creates a SignedDistanceFunc for a rectangle with the given size.

func (SignedDistance) Rhombus Uses

func (sd SignedDistance) Rhombus(b Vec) float64

Rhombus primitive

func (SignedDistance) RhombusFunc Uses

func (SignedDistance) RhombusFunc(b Vec) SignedDistanceFunc

RhombusFunc creates a SignedDistanceFunc for a rhombus with the given size.

func (SignedDistance) Rounded Uses

func (sd SignedDistance) Rounded(v, r float64) float64

Rounded signed distance function shape

type SignedDistanceFunc Uses

type SignedDistanceFunc func(SignedDistance) float64

SignedDistanceFunc is a func that takes a SignedDistance and returns a float64.

type SimplexNoise Uses

type SimplexNoise struct {
    // contains filtered or unexported fields
}

SimplexNoise is a speed-improved simplex noise algorithm for 2D, 3D and 4D.

Based on example code by Stefan Gustavson (stegu@itn.liu.se). Optimisations by Peter Eastman (peastman@drizzle.stanford.edu). Better rank ordering method by Stefan Gustavson in 2012.

This could be speeded up even further, but it's useful as it is.

Version 2012-03-09

This code was placed in the public domain by its original author, Stefan Gustavson. You may use it as you see fit, but attribution is appreciated.

func NewSimplexNoise Uses

func NewSimplexNoise(seed int64) *SimplexNoise

NewSimplexNoise creates a new simplex noise instance with the given seed

func (*SimplexNoise) Noise2D Uses

func (sn *SimplexNoise) Noise2D(xin, yin float64) float64

Noise2D performs 2D simplex noise

func (*SimplexNoise) Noise3D Uses

func (sn *SimplexNoise) Noise3D(xin, yin, zin float64) float64

Noise3D performs 3D simplex noise

func (*SimplexNoise) Noise4D Uses

func (sn *SimplexNoise) Noise4D(x, y, z, w float64) float64

Noise4D performs 4D simplex noise, better simplex rank ordering method 2012-03-09

type Target Uses

type Target interface {
    // MakeTriangles generates a specialized copy of the provided Triangles.
    //
    // When calling Draw method on the returned TargetTriangles, the TargetTriangles will be
    // drawn onto the Target that generated them.
    //
    // Note, that not every Target has to recognize all possible types of Triangles. Some may
    // only recognize TrianglesPosition and TrianglesColor and ignore all other properties (if
    // present) when making new TargetTriangles. This varies from Target to Target.
    MakeTriangles(Triangles) TargetTriangles

    // MakePicture generates a specialized copy of the provided Picture.
    //
    // When calling Draw method on the returned TargetPicture, the TargetPicture will be drawn
    // onto the Target that generated it together with the TargetTriangles supplied to the Draw
    // method.
    MakePicture(Picture) TargetPicture
}

Target is something that can be drawn onto, such as a window, a canvas, and so on.

You can notice, that there are no "drawing" methods in a Target. That's because all drawing happens indirectly through Triangles and Picture instances generated via MakeTriangles and MakePicture method.

type TargetPicture Uses

type TargetPicture interface {
    Picture

    // Draw draws the supplied TargetTriangles (which must be generated by the same Target as
    // this TargetPicture) with this TargetPicture. The TargetTriangles should utilize the data
    // from this TargetPicture in some way.
    Draw(TargetTriangles)
}

TargetPicture is a Picture generated by a Target using MakePicture method. This Picture can be drawn onto that (no other) Target together with a TargetTriangles generated by the same Target.

The TargetTriangles specify where, shape and how the Picture should be drawn.

type TargetTriangles Uses

type TargetTriangles interface {
    Triangles

    // Draw draws Triangles onto an associated Target.
    Draw()
}

TargetTriangles are Triangles generated by a Target with MakeTriangles method. They can be drawn onto that (no other) Target.

type Tiles Uses

type Tiles []PalettedImage

Tiles is a slice of paletted images.

type Tileset Uses

type Tileset struct {
    Palette Palette     // Palette of the tileset.
    Size    image.Point // Size is the size of each tile.
    Tiles   Tiles       // Images contains all of the images in the tileset.
}

Tileset is a paletted tileset.

func GetTileset Uses

func GetTileset(p Palette, tileSize image.Point, rawurl string) (*Tileset, error)

GetTileset retrieves a remote tileset using GetPNG.

func NewTileset Uses

func NewTileset(p Palette, s image.Point, td TilesetData) *Tileset

NewTileset creates a new paletted tileset.

func NewTilesetFromImage Uses

func NewTilesetFromImage(p Palette, tileSize image.Point, src image.Image) *Tileset

NewTilesetFromImage creates a new paletted tileset based on the provided palette, tile size and image.

type TilesetData Uses

type TilesetData [][]uint8

TilesetData is the raw data in a tileset

type Triangle Uses

type Triangle [3]Vertex

Triangle is an array of three vertexes

func NewTriangle Uses

func NewTriangle(i int, td *TrianglesData) Triangle

NewTriangle creates a new triangle.

func T Uses

func T(a, b, c Vertex) Triangle

T constructs a new triangle based on three vertexes.

Code:

t := T(
    Vx(V(1, 2), ColorRed),
    Vx(V(3, 4), ColorGreen, V(1, 1)),
    Vx(V(5, 6), ColorBlue, 0.5),
)

Log("%v\n%v\n%v", t[0], t[1], t[2])

Output:

{gfx.V(1, 2) {255 0 0 255} gfx.V(0, 0) 0}
{gfx.V(3, 4) {0 255 0 255} gfx.V(1, 1) 0}
{gfx.V(5, 6) {0 0 255 255} gfx.V(0, 0) 0.5}

func (Triangle) Bounds Uses

func (t Triangle) Bounds() image.Rectangle

Bounds returns the bounds of the triangle.

func (Triangle) Centroid Uses

func (t Triangle) Centroid() Vec

Centroid returns the centroid O of the triangle.

func (Triangle) Color Uses

func (t Triangle) Color(u Vec) color.Color

Color returns the color at vector u.

func (Triangle) Colors Uses

func (t Triangle) Colors() (color.NRGBA, color.NRGBA, color.NRGBA)

Colors returns the three colors.

func (Triangle) Contains Uses

func (t Triangle) Contains(u Vec) bool

Contains returns true if the given vector is inside the triangle.

func (Triangle) Draw Uses

func (t Triangle) Draw(dst draw.Image) (drawCount int)

Draw the first color in the triangle to dst.

func (Triangle) DrawColor Uses

func (t Triangle) DrawColor(dst draw.Image, c color.Color) (drawCount int)

DrawColor draws the triangle on dst using the given color.

func (Triangle) DrawColorOver Uses

func (t Triangle) DrawColorOver(dst draw.Image, c color.Color) (drawCount int)

DrawColorOver draws the triangle over dst using the given color.

func (Triangle) DrawOver Uses

func (t Triangle) DrawOver(dst draw.Image) (drawCount int)

DrawOver draws the first color in the triangle over dst.

func (Triangle) DrawWireframe Uses

func (t Triangle) DrawWireframe(dst draw.Image, c color.Color) (drawCount int)

DrawWireframe draws the triangle as a wireframe on dst.

func (Triangle) EachPixel Uses

func (t Triangle) EachPixel(tf TriangleFunc)

EachPixel calls the given TriangleFunc for each pixel in the triangle.

func (Triangle) Positions Uses

func (t Triangle) Positions() (Vec, Vec, Vec)

Positions returns the three positions.

func (Triangle) Rect Uses

func (t Triangle) Rect() Rect

Rect returns the triangle Rect.

type TriangleFunc Uses

type TriangleFunc func(u Vec, t Triangle)

TriangleFunc is a function type that is called by Triangle.EachPixel

type Triangles Uses

type Triangles interface {
    // Len returns the number of vertices. The number of triangles is the number of vertices
    // divided by 3.
    Len() int

    // SetLen resizes Triangles to len vertices. If Triangles B were obtained by calling Slice
    // method on Triangles A, the relationship between A and B is undefined after calling SetLen
    // on either one of them.
    SetLen(len int)

    // Slice returns a sub-Triangles of this Triangles, covering vertices in range [i, j).
    //
    // If Triangles B were obtained by calling Slice(4, 9) on Triangles A, then A and B must
    // share the same underlying data. Modifying B must change the contents of A in range
    // [4, 9). The vertex with index 0 at B is the vertex with index 4 in A, and so on.
    //
    // Returned Triangles must have the same underlying type.
    Slice(i, j int) Triangles

    // Update copies vertex properties from the supplied Triangles into this Triangles.
    //
    // Properties not supported by these Triangles should be ignored. Properties not supported by
    // the supplied Triangles should be left untouched.
    //
    // The two Triangles must have the same Len.
    Update(Triangles)

    // Copy creates an exact independent copy of this Triangles (with the same underlying type).
    Copy() Triangles
}

Triangles represents a list of vertices, where each three vertices form a triangle. (First, second and third is the first triangle, fourth, fifth and sixth is the second triangle, etc.)

type TrianglesColor Uses

type TrianglesColor interface {
    Triangles
    Color(i int) color.NRGBA
}

TrianglesColor specifies Triangles with Color property.

type TrianglesData Uses

type TrianglesData []Vertex

TrianglesData specifies a list of Triangles vertices with three common properties: TrianglesPosition, TrianglesColor and TrianglesPicture.

func MakeTrianglesData Uses

func MakeTrianglesData(len int) *TrianglesData

MakeTrianglesData creates Vertexes of length len initialized with default property values.

Prefer this function to make(Vertexes, len), because make zeros them, while this function does the correct intialization.

func (*TrianglesData) Color Uses

func (td *TrianglesData) Color(i int) color.NRGBA

Color returns the color property of i-th vertex.

func (*TrianglesData) Copy Uses

func (td *TrianglesData) Copy() Triangles

Copy returns an exact independent copy of this Vertexes.

func (*TrianglesData) Len Uses

func (td *TrianglesData) Len() int

Len returns the number of vertices in Vertexes.

func (*TrianglesData) Picture Uses

func (td *TrianglesData) Picture(i int) (pic Vec, intensity float64)

Picture returns the picture property of i-th vertex.

func (*TrianglesData) Position Uses

func (td *TrianglesData) Position(i int) Vec

Position returns the position property of i-th vertex.

func (*TrianglesData) SetLen Uses

func (td *TrianglesData) SetLen(length int)

SetLen resizes Vertexes to len, while keeping the original content.

If len is greater than Vertexes's current length, the new data is filled with default values ((0, 0), white, (0, 0), 0).

func (*TrianglesData) Slice Uses

func (td *TrianglesData) Slice(i, j int) Triangles

Slice returns a sub-Triangles of this TrianglesData.

func (*TrianglesData) Update Uses

func (td *TrianglesData) Update(t Triangles)

Update copies vertex properties from the supplied Triangles into this Vertexes.

TrianglesPosition, TrianglesColor and TrianglesTexture are supported.

type TrianglesPicture Uses

type TrianglesPicture interface {
    Triangles
    Picture(i int) (pic Vec, intensity float64)
}

TrianglesPicture specifies Triangles with Picture propery.

The first value returned from Picture method is Picture coordinates. The second one specifies the weight of the Picture. Value of 0 means, that Picture should be completely ignored, 1 means that is should be fully included and anything in between means anything in between.

type TrianglesPosition Uses

type TrianglesPosition interface {
    Triangles
    Position(i int) Vec
}

TrianglesPosition specifies Triangles with Position property.

type Vec Uses

type Vec struct {
    X, Y float64
}

Vec is a 2D vector type with X and Y coordinates.

Create vectors with the V constructor:

u := gfx.V(1, 2)
v := gfx.V(8, -3)

Use various methods to manipulate them:

  w := u.Add(v)
  fmt.Println(w)        // gfx.V(9, -1)
  fmt.Println(u.Sub(v)) // gfx.V(-7, 5)
  u = gfx.V(2, 3)
  v = gfx.V(8, 1)
  if u.X < 0 {
	     fmt.Println("this won't happen")
  }
  x := u.Unit().Dot(v.Unit())

func BoundsCenter Uses

func BoundsCenter(ir image.Rectangle) Vec

BoundsCenter returns the vector in the center of an image.Rectangle

func Centroid Uses

func Centroid(a, b, c Vec) Vec

Centroid returns the centroid O of three vectors.

Code:

Dump(
    Centroid(V(1, 1), V(6, 1), V(3, 4)),
    Centroid(V(0, 0), V(10, 0), V(5, 10)),
)

Output:

gfx.V(3.3333333333333335, 2)
gfx.V(5, 3.3333333333333335)

func IV Uses

func IV(x, y int) Vec

IV returns a new 2d vector based on the given int x, y pair.

func PV Uses

func PV(p image.Point) Vec

PV returns a new 2D vector based on the given image.Point.

func Unit Uses

func Unit(angle float64) Vec

Unit returns a vector of length 1 facing the given angle.

func V Uses

func V(x, y float64) Vec

V returns a new 2D vector with the given coordinates.

func (Vec) Abs Uses

func (u Vec) Abs() Vec

Abs returns the absolute vector of the vector u.

func (Vec) Add Uses

func (u Vec) Add(v Vec) Vec

Add returns the sum of vectors u and v.

func (Vec) AddXY Uses

func (u Vec) AddXY(x, y float64) Vec

AddXY returns the sum of x and y added to v.

func (Vec) Angle Uses

func (u Vec) Angle() float64

Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].

func (Vec) B Uses

func (u Vec) B(v Vec) image.Rectangle

B creates a new image.Rectangle for the vectors u and v.

func (Vec) Bounds Uses

func (u Vec) Bounds(l, t, r, b float64) image.Rectangle

Bounds returns the bounds around the vector based on the provided Left, Top, Right, Bottom values.

func (Vec) Cross Uses

func (u Vec) Cross(v Vec) float64

Cross return the cross product of vectors u and v.

func (Vec) Dot Uses

func (u Vec) Dot(v Vec) float64

Dot returns the dot product of vectors u and v.

func (Vec) Eq Uses

func (u Vec) Eq(v Vec) bool

Eq checks the equality of two vectors.

func (Vec) In Uses

func (u Vec) In(p Polygon) bool

In returns true if the vector is inside the given polygon.

func (Vec) Len Uses

func (u Vec) Len() float64

Len returns the length of the vector u.

func (Vec) Lerp Uses

func (u Vec) Lerp(v Vec, t float64) Vec

Lerp returns a linear interpolation between vectors u and v.

This function basically returns a point along the line between a and b and t chooses which one. If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will return the appropriate point between a and b and so on.

func (Vec) Map Uses

func (u Vec) Map(f func(float64) float64) Vec

Map applies the function f to both x and y components of the vector u and returns the modified vector.

u := gfx.V(10.5, -1.5)
v := u.Map(math.Floor)   // v is gfx.V(10, -2), both components of u floored

func (Vec) Max Uses

func (u Vec) Max(v Vec) Vec

Max returns the maximum vector of u and v.

func (Vec) Min Uses

func (u Vec) Min(v Vec) Vec

Min returns the minimum vector of u and v.

func (Vec) Mod Uses

func (u Vec) Mod(v Vec) Vec

Mod returns the floating-point remainder vector of x and y.

func (Vec) Normal Uses

func (u Vec) Normal() Vec

Normal returns a vector normal to u. Equivalent to u.Rotated(math.Pi / 2), but faster.

func (Vec) Project Uses

func (u Vec) Project(v Vec) Vec

Project returns a projection (or component) of vector u in the direction of vector v.

Behaviour is undefined if v is a zero vector.

func (Vec) Pt Uses

func (u Vec) Pt() image.Point

Pt returns the image.Point for the vector.

func (Vec) R Uses

func (u Vec) R(v Vec) Rect

R creates a new Rect for the vectors u and v.

Note that the returned rectangle is not automatically normalized.

func (Vec) Rect Uses

func (u Vec) Rect(l, t, r, b float64) Rect

Rect constructs a Rect around the vector based on the provided Left, Top, Right, Bottom values.

func (Vec) Rotated Uses

func (u Vec) Rotated(angle float64) Vec

Rotated returns the vector u rotated by the given angle in radians.

func (Vec) Scaled Uses

func (u Vec) Scaled(c float64) Vec

Scaled returns the vector u multiplied by c.

func (Vec) ScaledXY Uses

func (u Vec) ScaledXY(v Vec) Vec

ScaledXY returns the vector u multiplied by the vector v component-wise.

func (Vec) String Uses

func (u Vec) String() string

String returns the string representation of the vector u.

u := gfx.V(4.5, -1.3)
u.String()     // returns "gfx.V(4.5, -1.3)"
fmt.Println(u) // gfx.V(4.5, -1.3)

func (Vec) Sub Uses

func (u Vec) Sub(v Vec) Vec

Sub returns the difference betweeen vectors u and v.

func (Vec) To Uses

func (u Vec) To(v Vec) Vec

To returns the vector from u to v. Equivalent to v.Sub(u).

func (Vec) Unit Uses

func (u Vec) Unit() Vec

Unit returns a vector of length 1 facing the direction of u (has the same angle).

func (Vec) Vec3 Uses

func (u Vec) Vec3(z float64) Vec3

Vec3 converts the vector into a Vec3.

func (Vec) XY Uses

func (u Vec) XY() (x, y float64)

XY returns the components of the vector in two return values.

type Vec3 Uses

type Vec3 struct {
    X, Y, Z float64
}

Vec3 is a 3D vector type with X, Y and Z coordinates.

Create vectors with the V3 constructor:

u := gfx.V3(1, 2, 3)
v := gfx.V3(8, -3, 4)

func BoundsCenterOrigin Uses

func BoundsCenterOrigin(ir image.Rectangle, v Vec, z float64) Vec3

BoundsCenterOrigin returns the center origin for the given image.Rectangle and z value.

func IV3 Uses

func IV3(x, y, z int) Vec3

IV3 returns a new 3D vector based on the given int x, y, z values.

func V3 Uses

func V3(x, y, z float64) Vec3

V3 is shorthand for Vec3{X: x, Y: y, Z: z}.

func (Vec3) Add Uses

func (u Vec3) Add(v Vec3) Vec3

Add returns the sum of vectors u and v.

func (Vec3) AddXYZ Uses

func (u Vec3) AddXYZ(x, y, z float64) Vec3

AddXYZ returns the sum of x, y and z added to u.

func (Vec3) Dist Uses

func (u Vec3) Dist(v Vec3) float64

Dist returns the euclidian distance between two vectors.

func (Vec3) Div Uses

func (u Vec3) Div(s float64) Vec3

Div returns the vector v/s.

func (Vec3) Dot Uses

func (u Vec3) Dot(v Vec3) float64

Dot returns the dot product of vectors u and v.

func (Vec3) Eq Uses

func (u Vec3) Eq(v Vec3) bool

Eq checks the equality of two vectors.

func (Vec3) Len Uses

func (u Vec3) Len() float64

Len returns the length (euclidian norm) of a vector.

func (Vec3) Lerp Uses

func (u Vec3) Lerp(v Vec3, t float64) Vec3

Lerp returns the linear interpolation between v and w by amount t. The amount t is usually a value between 0 and 1. If t=0 v will be returned; if t=1 w will be returned.

func (Vec3) Map Uses

func (u Vec3) Map(f func(float64) float64) Vec3

Map applies the function f to the x, y and z components of the vector u and returns the modified vector.

func (Vec3) Scaled Uses

func (u Vec3) Scaled(s float64) Vec3

Scaled returns the vector u multiplied by c.

func (Vec3) ScaledXYZ Uses

func (u Vec3) ScaledXYZ(v Vec3) Vec3

ScaledXYZ returns the component-wise multiplication of two vectors.

func (Vec3) SqDist Uses

func (u Vec3) SqDist(v Vec3) float64

SqDist returns the square of the euclidian distance between two vectors.

func (Vec3) SqLen Uses

func (u Vec3) SqLen() float64

SqLen returns the square of the length (euclidian norm) of a vector.

func (Vec3) String Uses

func (u Vec3) String() string

String returns the string representation of the vector u.

func (Vec3) Sub Uses

func (u Vec3) Sub(v Vec3) Vec3

Sub returns the difference betweeen vectors u and v.

func (Vec3) Unit Uses

func (u Vec3) Unit() Vec3

Unit returns the normalized vector of a vector.

func (Vec3) Vec Uses

func (u Vec3) Vec() Vec

Vec returns a Vec with X, Y coordinates.

func (Vec3) XYZ Uses

func (u Vec3) XYZ() (x, y, z float64)

XYZ returns the components of the vector in three return values.

type Vertex Uses

type Vertex struct {
    Position  Vec
    Color     color.NRGBA
    Picture   Vec
    Intensity float64
}

Vertex holds Position, Color, Picture and Intensity.

func NewVertex Uses

func NewVertex(pos Vec, args ...interface{}) Vertex

NewVertex returns a new vertex with the given position.

func Vx Uses

func Vx(pos Vec, args ...interface{}) Vertex

Vx returns a new vertex with the given coordinates.

Code:

vx := Vx(V(6, 122), ColorWhite, V(1, 1), 0.5)

Dump(vx)

Output:

{Position:gfx.V(6, 122) Color:{R:255 G:255 B:255 A:255} Picture:gfx.V(1, 1) Intensity:0.5}

type XYZ Uses

type XYZ struct {
    X   float64
    Y   float64
    Z   float64
}

XYZ color space.

func ColorToXYZ Uses

func ColorToXYZ(c color.Color) XYZ

ColorToXYZ converts a color into XYZ.

R, G and B (Standard RGB) input range = 0 ÷ 255 X, Y and Z output refer to a D65/2° standard illuminant.

func (XYZ) CIELab Uses

func (xyz XYZ) CIELab(ref XYZ) CIELab

CIELab converts from XYZ to CIE-L*ab.

Reference-X, Y and Z refer to specific illuminants and observers. Common reference values are available below in this same page.

var_X = X / Reference-X var_Y = Y / Reference-Y var_Z = Z / Reference-Z

if ( var_X > 0.008856 ) var_X = var_X ^ ( 1/3 ) else var_X = ( 7.787 * var_X ) + ( 16 / 116 ) if ( var_Y > 0.008856 ) var_Y = var_Y ^ ( 1/3 ) else var_Y = ( 7.787 * var_Y ) + ( 16 / 116 ) if ( var_Z > 0.008856 ) var_Z = var_Z ^ ( 1/3 ) else var_Z = ( 7.787 * var_Z ) + ( 16 / 116 )

CIE-L* = ( 116 * var_Y ) - 16 CIE-a* = 500 * ( var_X - var_Y ) CIE-b* = 200 * ( var_Y - var_Z )

func (XYZ) HunterLab Uses

func (xyz XYZ) HunterLab(ref XYZ) HunterLab

HunterLab converts from XYZ to HunterLab.

Reference-X, Y and Z refer to specific illuminants and observers. Common reference values are available below in this same page.

var_Ka = ( 175.0 / 198.04 ) * ( Reference-Y + Reference-X ) var_Kb = ( 70.0 / 218.11 ) * ( Reference-Y + Reference-Z )

Hunter-L = 100.0 * sqrt( Y / Reference-Y ) Hunter-a = var_Ka * ( ( ( X / Reference-X ) - ( Y / Reference-Y ) ) / sqrt( Y / Reference-Y ) ) Hunter-b = var_Kb * ( ( ( Y / Reference-Y ) - ( Z / Reference-Z ) ) / sqrt( Y / Reference-Y ) )

type XYZReference Uses

type XYZReference struct {
    A   XYZ // Incandescent/tungsten
    B   XYZ // Old direct sunlight at noon
    C   XYZ // Old daylight
    D50 XYZ // ICC profile PCS
    D55 XYZ // Mid-morning daylight
    D65 XYZ // Daylight, sRGB, Adobe-RGB
    D75 XYZ // North sky daylight
    E   XYZ // Equal energy
    F1  XYZ // Daylight Fluorescent
    F2  XYZ // Cool fluorescent
    F3  XYZ // White Fluorescent
    F4  XYZ // Warm White Fluorescent
    F5  XYZ // Daylight Fluorescent
    F6  XYZ // Lite White Fluorescent
    F7  XYZ // Daylight fluorescent, D65 simulator
    F8  XYZ // Sylvania F40, D50 simulator
    F9  XYZ // Cool White Fluorescent
    F10 XYZ // Ultralume 50, Philips TL85
    F11 XYZ // Ultralume 40, Philips TL84
    F12 XYZ // Ultralume 30, Philips TL83
}

XYZReference values of a perfect reflecting diffuser.

Package gfx imports 18 packages (graph) and is imported by 8 packages. Updated 2019-10-12. Refresh now. Tools for package owners.