gfx package - github.com/peterhellberg/gfx - Go Packages

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

View Source

const (
	Pi = 3.14159265358979323846264338327950288419716939937510582097494459 
)

Mathematical constants.

View Source

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 = 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.

View Source

var (
	
	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 = []BlockColor{
		BlockColorYellow,
		BlockColorOrange,
		BlockColorBrown,
		BlockColorGreen,
		BlockColorBlue,
		BlockColorPurple,
		BlockColorRed,
		BlockColorWhite,
		BlockColorBlack,
	}

	
	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 = []BlockColor{
		BlockColorGoGopherBlue,
		BlockColorGoLightBlue,
		BlockColorGoAqua,
		BlockColorGoFuchsia,
		BlockColorGoBlack,
		BlockColorGoYellow,
	}

	
	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.

Stdout, and Stderr are open Files pointing to the standard output, and standard error file descriptors.

View Source

var (
	
	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 = 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},
	}
)

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

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

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

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

View Source

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

View Source

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

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

View Source

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

View Source

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

View Source

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.

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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.

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

View Source

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

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

View Source

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

View Source

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.

ZP is the zero image.Point.

ZR is the zero image.Rectangle.

ZV is a zero vector.

ZV3 is the zero Vec3

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

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

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.

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

CmplxCos returns the cosine of x.

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)

CmplxCosh returns the hyperbolic cosine of x.

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)

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

Log("%f %f %f",
	CmplxPhase(complex(1, 2)),
	CmplxPhase(complex(2, 3)),
	CmplxPhase(complex(4, 5)),
)
Output:
1.107149 0.982794 0.896055

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

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)

CmplxSin returns the sine of x.

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)

CmplxSinh returns the hyperbolic sine of x.

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)

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).

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)

CmplxTan returns the tangent of x.

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)

CmplxTanh returns the hyperbolic tangent of x.

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)

ColorGray construcs a color.Gray.

ColorGray16 construcs a color.Gray16.

ColorNRGBA constructs a color.NRGBA.

ColorRGBA constructs a color.RGBA.

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

CreateFile creates or truncates the named file.

DecodeImage decodes an image from the provided io.Reader.

DecodeImageBytes decodes an image from the provided []byte.

DecodePNG decodes a PNG from the provided io.Reader.

DecodePNGBytes decodes a PNG from the provided []byte.

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

DrawCicleFast draws a (crude) filled circle.

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

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:

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
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:

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

DrawCircleFilled draws a filled circle.

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

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

DrawIntCircle draws a circle given a point and radius

DrawIntFilledCircle draws a filled circle given a point and radius

DrawIntFilledRectangle draws a filled rectangle given a point, width and height

DrawIntFilledTriangle draws a filled triangle given three points

DrawIntLine draws a line between two points

DrawIntRectangle draws a rectangle given a point, width and height

DrawIntTriangle draws a triangle given three points

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

DrawLineBresenham draws a line using Bresenham's line algorithm.

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

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:

░░░░░░░░░░░░░░░░░░░░
░░▓▓▓▓░░░░░░░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░░░░░░░▓▓▓▓░░
░░░░░░░░░░░░░░░░░░░░
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:

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

DrawOver draws src over dst.

DrawPalettedImage draws a PalettedImage over a PalettedDrawImage.

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

DrawPointCircle draws a circle at the given point.

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

DrawPolyline draws a polyline with the given color and thickness.

DrawSrc draws src on dst.

DrawTriangles draws triangles on dst.

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

DrawTrianglesOver draws triangles over dst.

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

DrawTrianglesWireframe draws triangles on dst.

func Dump(a ...interface{})

Dump all of the arguments to standard output.

Dump([]string{"foo", "bar"})
Output:
[foo bar]
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.

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

EncodeJSON creates a new JSON encoder and encodes the provided value.

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

Errorf constructs a formatted error.

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

fmt.Println(err)
Output:
foo 123 and bar abc
func Fatal(v ...interface{})

Fatal prints to os.Stderr, followed by a call to os.Exit(1).

Get performs a HTTP GET request using the DefaultClient.

GetImage retrieves a remote image using DefaultClient

GetPNG retrieves a remote PNG using DefaultClient

IR returns an image.Rectangle for the given input.

IntAbs returns the absolute value of x.

Dump(
	IntAbs(10),
	IntAbs(-5),
)
Output:
10
5
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.

IntMax returns the larger of x or y.

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

IntMin returns the smaller of x or y.

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

JSONIndent configures the prefix and indent level of a JSON encoder.

Lerp does linear interpolation between two values.

Dump(
	Lerp(0, 2, 0.1),
	Lerp(1, 10, 0.5),
	Lerp(2, 4, 0.5),
)
Output:
0.2
5.5
3

LerpColors performs linear interpolation between two colors.

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

Log to standard output.

Log("Foo: %d", 123)
Output:
Foo: 123

MathAbs returns the absolute value of x.

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

MathAtan returns the arctangent, in radians, of x.

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

Dump(
	MathCeil(0.2),
	MathCeil(1.4),
	MathCeil(2.6),
)
Output:
1
2
3

MathCos returns the cosine of the radian argument x.

Dump(
	MathCos(1),
	MathCos(2),
	MathCos(3),
)
Output:
0.5403023058681398
-0.4161468365471424
-0.9899924966004454

MathCosh returns the hyperbolic cosine of x.

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

Dump(
	MathFloor(0.2),
	MathFloor(1.4),
	MathFloor(2.6),
)
Output:
0
1
2

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

Dump(
	MathHypot(15, 8),
	MathHypot(5, 12),
	MathHypot(3, 4),
)
Output:
17
13
5

MathLog returns the natural logarithm of x.

MathMax returns the larger of x or y.

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

MathMin returns the smaller of x or y.

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

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

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

MathSin returns the sine of the radian argument x.

Dump(
	MathSin(1),
	MathSin(2),
	MathSin(3),
)
Output:
0.8414709848078965
0.9092974268256816
0.1411200080598672

MathSinh returns the hyperbolic sine of x.

MathSqrt returns the square root of x.

Dump(
	MathSqrt(1),
	MathSqrt(2),
	MathSqrt(3),
)
Output:
1
1.4142135623730951
1.7320508075688772

MathTan returns the tangent of the radian argument x.

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

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

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

NewGray returns a new Gray image with the given bounds.

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

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

NewJSONEncoder creates a new JSON encoder for the given io.Writer.

NewNRGBA returns a new NRGBA image with the given bounds.

NewRGBA returns a new RGBA image with the given bounds.

NewResizedImage returns a new image with the provided dimensions.

NewResizedRGBA returns a new RGBA image with the provided dimensions.

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

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:

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

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

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

NewUniform creates a new uniform image of the given color.

OpenFile opens the named file for reading.

OpenImage decodes an image using the provided file name.

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

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

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

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

func RandFloat64

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

func RandIntn

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

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.

ReadFile opens a file and calls the given ReadFunc.

ReadJSON opens and decodes a JSON file.

ResizeImage using nearest neighbor scaling on dst from src.

SavePNG saves an image using the provided file name.

Set x and y to the given color.

SetPoint to the given color.

SetVec to the given color.

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

Dump(
	Sign(-2),
	Sign(0),
	Sign(2),
)
Output:
-1
0
1
func SortSlice(slice interface{}, less func(i, j int) bool)

SortSlice sorts the provided slice given the provided less function.

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

Animation represents multiple images.

AddFrame adds a frame to the animation.

func (a *Animation) AddPalettedImage(frame PalettedImage)

AddPalettedImage adds a frame and palette to the animation.

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

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

type BasicTarget interface {
	Target

	
	SetMatrix(Matrix)
}

BasicTarget is a Target with additional basic adjustment methods.

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(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.

Clear removes all objects from the Batch.

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 (b *Batch) Draw(t Target)

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

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

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

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

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

func (b *Batch) SetMatrix(m Matrix)

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

type Block struct {
	Pos   Vec3
	Size  Vec3
	Color BlockColor
}

Block has a position, size and color.

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

NewBlock creates a new Block.

func (b Block) Behind(a Block) bool

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

Box creates a box for the Block.

func (b Block) Corners(origin Vec3) BlockCorners

Corners returns the screen coordinates for the Block corners.

Draw block on dst at origin.

DrawBounds for block on dst at origin.

DrawOver draws block over dst at origin.

DrawPolygons for block on dst at origin.

DrawRectangles for block on dst at origin.

DrawWireframe block on dst at origin.

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 (b Block) Rect(origin Vec3) Rect

Rect for the block.

func (b Block) Shape(origin Vec3) Polygon

Shape returns the shape Polygon

func (b Block) Space() BlockSpace

Space returns the BlockSpace for the Block.

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

Triangles for the Block

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

TrianglesData creates triangles data for the Block.

BlockColor contains a Light, Medium and Dark color.

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 (bc BlockCorners) Left() Polygon

Left face Polygon.

func (bc BlockCorners) Rect() Rect

Rect for the Block corners.

func (bc BlockCorners) Right() Polygon

Right face Polygon.

func (bc BlockCorners) Shape() Polygon

Shape Polygon.

func (bc BlockCorners) Top() Polygon

Top face Polygon.

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 (bs BlockSpace) CornerBackDown(origin Vec3) Vec

CornerBackDown returns the screen coordinate for the BackDown corner.

func (bs BlockSpace) CornerBackUp(origin Vec3) Vec

CornerBackUp returns the screen coordinate for the BackUp corner.

func (bs BlockSpace) CornerFrontDown(origin Vec3) Vec

CornerFrontDown returns the screen coordinate for the FrontDown corner.

func (bs BlockSpace) CornerFrontUp(origin Vec3) Vec

CornerFrontUp returns the screen coordinate for the FrontUp corner.

func (bs BlockSpace) CornerLeftDown(origin Vec3) Vec

CornerLeftDown returns the screen coordinate for the LeftDown corner.

func (bs BlockSpace) CornerLeftUp(origin Vec3) Vec

CornerLeftUp returns the screen coordinate for the LeftUp corner.

func (bs BlockSpace) CornerRightDown(origin Vec3) Vec

CornerRightDown returns the screen coordinate for the RightDown corner.

func (bs BlockSpace) CornerRightUp(origin Vec3) Vec

CornerRightUp returns the screen coordinate for the RightUp corner.

func (bs BlockSpace) Corners(origin Vec3) BlockCorners

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

Blocks is a slice of blocks.

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

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

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

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

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

DrawBounds for all blocks.

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 Blocks) DrawRectangles(dst draw.Image, origin Vec3)

DrawRectangles for all blocks.

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

DrawWireframes for all blocks.

func (blocks Blocks) Sort()

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

type Box struct {
	Min Vec3
	Max Vec3
}

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

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

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

func NewBox(min, max Vec3) Box

NewBox creates a new Box.

func (b Box) Behind(a Box) bool

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

func (b Box) Overlaps(a Box) bool

Overlaps checks if two boxes overlap or not.

CIELab represents a color in CIE-L*ab.

var (
	rgba   = ColorRGBA(255, 0, 0, 255)
	xyz    = ColorToXYZ(rgba)
	hunter = xyz.HunterLab(XYZReference2.D65)
	cieLab = xyz.CIELab(XYZReference2.D65)
)

Dump(
	"RGBA",
	rgba,
	"XYZ",
	xyz,
	"Hunter",
	hunter,
	"CIE-L*ab",
	cieLab,
)

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 ) )

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 ) )

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 struct {
	Center Vec
	Radius float64
}

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

  • Center vector
  • Radius float64

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

Note that a negative radius is valid.

Area returns the area of the Circle.

func (c Circle) Contains(u Vec) bool

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

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 (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 (c Circle) Moved(delta Vec) Circle

Moved returns the Circle moved by the given vector delta.

func (c Circle) Norm() Circle

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

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

String returns the string representation of the Circle.

func (c Circle) Union(d Circle) Circle

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

Degrees of arc.

Radians convert degrees to radians.

type Domain

Domain of values.

func (Domain) Max

Max value in the Domain.

func (Domain) Min

Min value in the Domain.

type DrawTarget struct {
	
}

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

NewDrawTarget creates a new draw target.

At retrieves the color at (x, y).

Bounds of the draw target.

func (dt *DrawTarget) Center() Vec

Center vector of the draw target.

ColorModel of the draw target.

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

MakePicture creates a TargetPicture for the provided Picture.

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

MakeTriangles creates TargetTriangles for the given Triangles

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

func (dt *DrawTarget) SetMatrix(mat Matrix)

SetMatrix sets the matrix of the draw target.

type Drawer struct {
	Triangles Triangles
	Picture   Picture
	
}

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.

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

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.

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

const (
	
	NoEndShape EndShape = iota

	
	SharpEndShape

	
	RoundEndShape
)

Error is a string that implements the error interface.

Error implements the error interface.

Float64Scaler can scale a float64 to another float64.

GeoPoint represents a geographic point with Lat/Lon.

GP creates a new GeoPoint

func (gp GeoPoint) GeoTile(zoom int) GeoTile

GeoTile for the GeoPoint at the given zoom level.

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

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

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

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

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

func GT(zoom, x, y int) GeoTile

GT creates a new GeoTile.

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

AddXY adds x and y.

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

func (gt GeoTile) E() GeoTile

E is the tile to the east.

func (gt GeoTile) GeoPoint() GeoPoint

GeoPoint for the GeoTile.

func (gt GeoTile) N() GeoTile

N is the tile to the north.

func (gt GeoTile) NE() GeoTile

NE is the tile to the northeast.

func (gt GeoTile) NW() GeoTile

NW is the tile to the northwest.

func (gt GeoTile) Neighbors() GeoTiles

Neighbors returns the neighboring tiles.

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

func (gt GeoTile) S() GeoTile

S is the tile to the south.

func (gt GeoTile) SE() GeoTile

SE is the tile to the southeast.

func (gt GeoTile) SW() GeoTile

SW is the tile to the southwest.

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

Vec returns the Vec for the GeoPoint in the GeoTile.

func (gt GeoTile) W() GeoTile

W is the tile to the west.

type GeoTileServer struct {
	Format string
}

GeoTileServer represents a tile server.

GTS creates a GeoTileServer.

GetImage for the given GeoTile from the tile server.

GeoTiles is a slice of GeoTile.

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

ColorToHSL converts a color into HSL.

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

Components in HSL.

RGBA converts a HSL color value to color.RGBA.

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

ColorToHSV converts a color into HSV.

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

Components in HSV.

RGBA converts a HSV color value to color.RGBA.

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

HunterLab represents a color in Hunter-Lab.

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

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(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 (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 (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 (imd *IMDraw) Clear()

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

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 (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 (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.

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

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

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

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

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

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 (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 (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 (imd *IMDraw) Reset()

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

This does not affect matrix set by SetMatrix.

func (imd *IMDraw) SetMatrix(m Matrix)

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

type Layer struct {
	Tileset *Tileset
	Width   int 
	Data    LayerData
}

Layer represents a layer of paletted tiles.

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

NewLayer creates a new layer.

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

At returns the color at (x, y).

Bounds returns the bounds of the paletted layer.

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

ColorModel returns the color model for the paletted layer.

ColorPalette retrieves the layer palette.

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

DataAt returns the data at (dx, dy).

func (l *Layer) GfxPalette() Palette

GfxPalette retrieves the layer palette.

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

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

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

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

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

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

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

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

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

TileSize returns the tileset tile size.

LayerData is the data for a layer.

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

type LinearScaler struct {
	
}

LinearScaler can scale domain values to a range values.

func NewLinearScaler() LinearScaler

NewLinearScaler creates a new linear scaler.

func (LinearScaler) Domain

Domain returns a LinearScaler with the given domain.

Range returns a LinearScaler with the given range.

ScaleFloat64 from domain to range.

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

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 (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 (m Matrix) Moved(delta Vec) Matrix

Moved moves everything by the delta vector.

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).

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

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

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

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

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

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

String returns a string representation of the Matrix.

m := gfx.IM
fmt.Println(m) // Matrix(1 0 0 | 0 1 0)
func (m Matrix) Unproject(u Vec) Vec

Unproject does the inverse operation to Project.

Time complexity is O(1).

Palette is a slice of colors.

AsColorPalette converts the Palette to a color.Palette.

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

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

Color returns the color at index n.

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

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

func (p Palette) Len() int

Len returns the number of colors in the palette.

func (Palette) Random

Random color from the palette.

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

Sort palette.

func (p Palette) SortByHue()

SortByHue sorts based on (HSV) Hue.

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

type PaletteLookup map[PaletteName]Palette

PaletteLookup is a map of PaletteName to Palette.

PaletteName is a palette name.

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

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

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

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

NewResizedPalettedImage returns an image with the provided dimensions.

func NewScaledPalettedImage(src PalettedImage, s float64) *Paletted

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

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

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

At returns the color at (x, y).

Bounds returns the bounds of the paletted image.

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

ColorModel returns the color model of the paletted image.

ColorPalette returns the color palette of the paletted image.

func (p *Paletted) GfxPalette() Palette

GfxPalette returns the gfx palette of the paletted image.

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

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

func (p *Paletted) Opaque() bool

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

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).

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

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

Set changes the color at (x, y).

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

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

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 interface {
	SetColorIndex(int, int, uint8)
	PalettedImage
}

PalettedDrawImage interface is implemented by *Paletted

PalettedImage interface is implemented by *Paletted

Palettes is a slice of Palette.

type Picture interface {
	
	
	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 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)).

Points are a list of points.

func (pts Points) Polygon() Polygon

Polygon based on the points.

Polygon is represented by a list of vectors.

Bounds return the bounds of the polygon rectangle.

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

Fill polygon on the image with the given color.

Outline draws an outline of the polygon on dst.

func (p Polygon) Project(m Matrix) Polygon

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

func (p Polygon) Rect() Rect

Rect is the polygon rectangle.

Polyline is a slice of polygons forming a line.

NewPolyline constructs a slice of line polygons.

Range of values.

First value in the Range.

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

func DecodeJSONFunc(v interface{}) ReadFunc

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

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.

BoundsToRect converts an image.Rectangle to a Rect.

func NewRect(min, max Vec) Rect

NewRect creates a new Rect.

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.

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

Bounds returns the bounds of the rectangle.

func (r Rect) Center() Vec

Center returns the position of the center of the Rect.

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

func (r Rect) Contains(u Vec) bool

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

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

DrawColor draws Rect with a uniform color on dst.

DrawColorOver draws Rect with a uniform color over dst.

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

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

H returns the height of the Rect.

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 (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 (r Rect) Moved(delta Vec) Rect

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

func (r Rect) Norm() Rect

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

func (r Rect) Overlaps(s Rect) bool

Overlaps checks whether one Rect overlaps another Rect.

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 (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.

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

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 (r Rect) Union(s Rect) Rect

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

W returns the width of the Rect.

type SignedDistance struct {
	Vec
}

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

Annular signed distance function shape

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

EquilateralTriangle primitive

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

IsoscelesTriangle primitive

func (SignedDistance) IsoscelesTriangleFunc(q Vec) SignedDistanceFunc

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

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

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

OpIntersection basic boolean operation for intersection.

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

OpRepeat repeats based on the given c vector.

OpSmoothIntersection smooth operation for intersection.

OpSmoothSubtraction smooth operation for subtraction.

OpSmoothUnion smooth operation for union.

OpSubtraction basic boolean operation for subtraction.

OpSymX symmetry operation for X.

OpSymXY symmetry operation for X and Y.

OpSymY symmetry operation for Y.

OpTx translates using the given matrix.

OpUnion basic boolean operation for union.

func (SignedDistance) RectangleFunc(b Vec) SignedDistanceFunc

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

func (SignedDistance) RhombusFunc(b Vec) SignedDistanceFunc

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

Rounded signed distance function shape

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

type SimplexNoise struct {
	
}

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(seed int64) *SimplexNoise

NewSimplexNoise creates a new simplex noise instance with the given seed

Noise2D performs 2D simplex noise

Noise3D performs 3D simplex noise

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

type Target interface {
	
	
	
	
	
	
	
	
	MakeTriangles(Triangles) TargetTriangles

	
	
	
	
	
	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 interface {
	Picture

	
	
	
	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 interface {
	Triangles

	
	Draw()
}

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

type Tiles []PalettedImage

Tiles is a slice of paletted images.

type Tileset struct {
	Palette Palette     
	Size    image.Point 
	Tiles   Tiles       
}

Tileset is a paletted tileset.

GetTileset retrieves a remote tileset using GetPNG.

NewTileset creates a new paletted tileset.

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

type TilesetData [][]uint8

TilesetData is the raw data in a tileset

Triangle is an array of three vertexes

func NewTriangle(i int, td *TrianglesData) Triangle

NewTriangle creates a new triangle.

func T(a, b, c Vertex) Triangle

T constructs a new triangle based on three vertexes.

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.00000000, 2.00000000) {255 0 0 255} gfx.V(0.00000000, 0.00000000) 0}
{gfx.V(3.00000000, 4.00000000) {0 255 0 255} gfx.V(1.00000000, 1.00000000) 0}
{gfx.V(5.00000000, 6.00000000) {0 0 255 255} gfx.V(0.00000000, 0.00000000) 0.5}

Bounds returns the bounds of the triangle.

func (t Triangle) Centroid() Vec

Centroid returns the centroid O of the triangle.

Color returns the color at vector u.

Colors returns the three colors.

func (t Triangle) Contains(u Vec) bool

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

Draw the triangle to dst.

DrawColor draws the triangle on dst using the given color.

DrawColorOver draws the triangle over dst using the given color.

DrawOver draws the first color in the triangle over dst.

DrawWireframe draws the triangle as a wireframe on dst.

func (t Triangle) EachPixel(tf TriangleFunc)

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

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

Positions returns the three positions.

func (t Triangle) Rect() Rect

Rect returns the triangle Rect.

type TriangleFunc func(u Vec, t Triangle)

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

type Triangles interface {
	
	
	Len() int

	
	
	
	SetLen(len int)

	
	
	
	
	
	
	
	Slice(i, j int) Triangles

	
	
	
	
	
	
	Update(Triangles)

	
	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.)

TrianglesColor specifies Triangles with Color property.

type TrianglesData []Vertex

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

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.

Color returns the color property of i-th vertex.

func (td *TrianglesData) Copy() Triangles

Copy returns an exact independent copy of this Vertexes.

Len returns the number of vertices in Vertexes.

Picture returns the picture property of i-th vertex.

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

Position returns the position property of i-th vertex.

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 (td *TrianglesData) Slice(i, j int) Triangles

Slice returns a sub-Triangles of this TrianglesData.

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 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 interface {
	Triangles
	Position(i int) Vec
}

TrianglesPosition specifies Triangles with Position property.

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())

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

func Centroid(a, b, c Vec) Vec

Centroid returns the centroid O of three vectors.

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.33333333, 2.00000000)
gfx.V(5.00000000, 3.33333333)
func CubicBezierCurve(p0, p1, p2, p3 Vec, inc float64) []Vec

CubicBezierCurve returns a slice of vectors representing a cubic bezier curve

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

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

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

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

Abs returns the absolute vector of the vector u.

Dump(
	V(1, -1).Abs(),
	V(-2, -2).Abs(),
	V(3, 6).Abs(),
)
Output:
gfx.V(1.00000000, 1.00000000)
gfx.V(2.00000000, 2.00000000)
gfx.V(3.00000000, 6.00000000)
func (u Vec) Add(v Vec) Vec

Add returns the sum of vectors u and v.

Dump(
	V(1, 1).Add(V(2, 3)),
	V(3, 3).Add(V(-1, -2)),
)
Output:
gfx.V(3.00000000, 4.00000000)
gfx.V(2.00000000, 1.00000000)

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

Dump(
	V(1, 1).AddXY(2, 3),
	V(3, 3).AddXY(-1, -2),
)
Output:
gfx.V(3.00000000, 4.00000000)
gfx.V(2.00000000, 1.00000000)

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

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

Dump(
	V(1, 2).B(V(3, 4)),
	V(5, 2).B(V(3, 4)),
)
Output:
(1,2)-(3,4)
(5,2)-(3,4)

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

Dump(
	V(10, 10).Bounds(-1, -2, 3, 4),
	V(3, 4).Bounds(1.5, 2.2, 3.3, 4.5),
)
Output:
(9,8)-(13,14)
(4,6)-(6,8)

Cross return the cross product of vectors u and v.

Dump(
	V(1, 1).Cross(V(2.5, 3)),
	V(2, 5.5).Cross(V(2, 3)),
)
Output:
0.5
-5

Dot returns the dot product of vectors u and v.

Dump(
	V(1, 1).Dot(V(2.5, 3)),
	V(2, 5.5).Dot(V(2, 3)),
)
Output:
5.5
20.5

Eq checks the equality of two vectors.

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

Len returns the length of the vector u.

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.

a, b := V(1, 2), V(30, 40)

Dump(
	a.Lerp(b, 0),
	a.Lerp(b, 0.1),
	a.Lerp(b, 0.5),
	a.Lerp(b, 0.9),
	a.Lerp(b, 1),
)
Output:
gfx.V(1.00000000, 2.00000000)
gfx.V(3.90000000, 5.80000000)
gfx.V(15.50000000, 21.00000000)
gfx.V(27.10000000, 36.20000000)
gfx.V(30.00000000, 40.00000000)

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
Dump(
	V(1.1, 1).Map(math.Ceil),
	V(1.1, 2.5).Map(math.Round),
)
Output:
gfx.V(2.00000000, 1.00000000)
gfx.V(1.00000000, 3.00000000)
func (u Vec) Max(v Vec) Vec

Max returns the maximum vector of u and v.

Dump(
	V(1, 1).Max(V(2.5, 3)),
	V(2, 5.5).Max(V(2, 3)),
)
Output:
gfx.V(2.50000000, 3.00000000)
gfx.V(2.00000000, 5.50000000)
func (u Vec) Min(v Vec) Vec

Min returns the minimum vector of u and v.

Dump(
	V(1, 1).Min(V(2.5, 3)),
	V(2, 5.5).Min(V(2, 3)),
)
Output:
gfx.V(1.00000000, 1.00000000)
gfx.V(2.00000000, 3.00000000)
func (u Vec) Mod(v Vec) Vec

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

Dump(
	V(1, 1).Mod(V(2.5, 3)),
	V(2, 5.5).Mod(V(2, 3)),
)
Output:
gfx.V(1.00000000, 1.00000000)
gfx.V(0.00000000, 2.50000000)
func (u Vec) Normal() Vec

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

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.

Dump(
	V(1, 1).Project(V(2.5, 3)),
	V(2, 5.5).Project(V(2, 3)),
)
Output:
gfx.V(0.90163934, 1.08196721)
gfx.V(3.15384615, 4.73076923)

Pt returns the image.Point for the vector.

Dump(
	V(1, 2).Pt(),
	V(3, 4).Pt(),
)
Output:
(1,2)
(3,4)
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.

Dump(
	V(1, 2).R(V(3, 4)),
	V(5, 2).R(V(3, 4)),
)
Output:
gfx.R(1, 2, 3, 4)
gfx.R(5, 2, 3, 4)

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

Dump(
	V(10, 10).Rect(-1, -2, 3, 4),
	V(3, 4).Rect(1.5, 2.2, 3.3, 4.5),
)
Output:
gfx.R(9, 8, 13, 14)
gfx.R(4.5, 6.2, 6.3, 8.5)

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

Scaled returns the vector u multiplied by c.

func (u Vec) ScaledXY(v Vec) Vec

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

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 (u Vec) Sub(v Vec) Vec

Sub returns the difference betweeen vectors u and v.

Dump(
	V(1, 1).Sub(V(2, 3)),
	V(3, 3).Sub(V(-1, -2)),
)
Output:
gfx.V(-1.00000000, -2.00000000)
gfx.V(4.00000000, 5.00000000)
func (u Vec) To(v Vec) Vec

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

Dump(
	V(1, 1).To(V(2, 3)),
	V(3, 3).To(V(-1, -2)),
)
Output:
gfx.V(1.00000000, 2.00000000)
gfx.V(-4.00000000, -5.00000000)

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

Vec3 converts the vector into a Vec3.

Dump(
	V(1, 2).Vec3(3),
	V(4, 5).Vec3(6),
)
Output:
gfx.V3(1, 2, 3)
gfx.V3(4, 5, 6)

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

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)

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

func IV3(x, y, z int) Vec3

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

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

func (u Vec3) Add(v Vec3) Vec3

Add returns the sum of vectors u and v.

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

Dist returns the euclidian distance between two vectors.

Div returns the vector v/s.

Dot returns the dot product of vectors u and v.

Eq checks the equality of two vectors.

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

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.

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

Scaled returns the vector u multiplied by c.

func (u Vec3) ScaledXYZ(v Vec3) Vec3

ScaledXYZ returns the component-wise multiplication of two vectors.

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

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

String returns the string representation of the vector u.

func (u Vec3) Sub(v Vec3) Vec3

Sub returns the difference betweeen vectors u and v.

func (u Vec3) Unit() Vec3

Unit returns the normalized vector of a vector.

Vec returns a Vec with X, Y coordinates.

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

Vertex holds Position, Color, Picture and Intensity.

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

NewVertex returns a new vertex with the given position.

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

Vx returns a new vertex with the given coordinates.

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

Dump(vx)
Output:
{Position:gfx.V(6.00000000, 122.00000000) Color:{R:255 G:255 B:255 A:255} Picture:gfx.V(1.00000000, 1.00000000) Intensity:0.5}

XYZ color space.

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 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 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 struct {
	A   XYZ 
	B   XYZ 
	C   XYZ 
	D50 XYZ 
	D55 XYZ 
	D65 XYZ 
	D75 XYZ 
	E   XYZ 
	F1  XYZ 
	F2  XYZ 
	F3  XYZ 
	F4  XYZ 
	F5  XYZ 
	F6  XYZ 
	F7  XYZ 
	F8  XYZ 
	F9  XYZ 
	F10 XYZ 
	F11 XYZ 
	F12 XYZ 
}

XYZReference values of a perfect reflecting diffuser.