# gfx

package module
v0.0.0-...-9885a9f Latest Latest

Go to latest
Published: Sep 8, 2023 License: MIT

### gfx

Convenience package for dealing with graphics in my pixel drawing experiments.

#### Triangles

Triangles can be drawn to an image using a `*gfx.DrawTarget`.

``````package main

import "github.com/peterhellberg/gfx"

var p = gfx.PaletteFamicube

func main() {
n := 50
m := gfx.NewPaletted(900, 270, p, p.Color(n+7))
t := gfx.NewDrawTarget(m)

t.MakeTriangles(&gfx.TrianglesData{
vx(114, 16, n+1), vx(56, 142, n+2), vx(352, 142, n+3),
vx(350, 142, n+4), vx(500, 50, n+5), vx(640, 236, n+6),
vx(640, 70, n+8), vx(820, 160, n+9), vx(670, 236, n+10),
}).Draw()

gfx.SavePNG("gfx-example-triangles.png", m)
}

func vx(x, y float64, n int) gfx.Vertex {
return gfx.Vertex{Position: gfx.V(x, y), Color: p.Color(n)}
}
``````

#### Polygons

A `gfx.Polygon` is represented by a list of vectors. There is also `gfx.Polyline` which is a slice of polygons forming a line.

``````package main

import "github.com/peterhellberg/gfx"

var edg32 = gfx.PaletteEDG32

func main() {
m := gfx.NewNRGBA(gfx.IR(0, 0, 1024, 256))
p := gfx.Polygon{
{80, 40},
{440, 60},
{700, 200},
{250, 230},
{310, 140},
}

p.EachPixel(m, func(x, y int) {
pv := gfx.IV(x, y)
l := pv.To(p.Rect().Center()).Len()

gfx.Mix(m, x, y, edg32.Color(int(l/18)%32))
})

for n, v := range p {
c := edg32.Color(n * 4)

gfx.DrawCircle(m, v, 15, 8, gfx.ColorWithAlpha(c, 96))
gfx.DrawCircle(m, v, 16, 1, c)
}

gfx.SavePNG("gfx-example-polygon.png", m)
}
``````

#### Blocks

You can draw (isometric) blocks using the `gfx.Blocks` and `gfx.Block` types.

``````package main

import "github.com/peterhellberg/gfx"

func main() {
var (
dst    = gfx.NewPaletted(898, 330, gfx.PaletteGo, gfx.PaletteGo[14])
rect   = gfx.BoundsToRect(dst.Bounds())
origin = rect.Center().ScaledXY(gfx.V(1.5, -2.5)).Vec3(0.55)
blocks gfx.Blocks
)

for i, bc := range gfx.BlockColorsGo {
var (
f    = float64(i) + 0.5
v    = f * 11
pos  = gfx.V3(290+(v*3), 8.5*v, 9*(f+2))
size = gfx.V3(90, 90, 90)
)

}

blocks.Draw(dst, origin)

gfx.SavePNG("gfx-example-blocks.png", dst)
}
``````

#### Signed Distance Functions

The `gfx.SignedDistance` type allows you to use basic signed distance functions (and operations) to produce some interesting graphics.

``````package main

import "github.com/peterhellberg/gfx"

func main() {
c := gfx.PaletteEDG36.Color
m := gfx.NewImage(1024, 256, c(5))

gfx.EachPixel(m.Bounds(), func(x, y int) {
sd := gfx.SignedDistance{gfx.IV(x, y)}

if d := sd.OpRepeat(gfx.V(128, 128), func(sd gfx.SignedDistance) float64 {
return sd.OpSubtraction(sd.Circle(50), sd.Line(gfx.V(0, 0), gfx.V(64, 64)))
}); d < 40 {
m.Set(x, y, c(int(gfx.MathAbs(d/5))))
}
})

gfx.SavePNG("gfx-example-sdf.png", m)
}
``````

#### Domain Coloring

You can use the `CmplxPhaseAt` method on a `gfx.Palette` to do domain coloring.

``````package main

import "github.com/peterhellberg/gfx"

const (
w, h        = 1800, 540
fovY        = 1.9
aspectRatio = float64(w) / float64(h)
centerReal  = 0
centerImag  = 0
ahc         = aspectRatio*fovY/2.0 + centerReal
hfc         = fovY/2.0 + centerImag
)

func pixelCoordinates(px, py int) gfx.Vec {
return gfx.V(
((float64(px)/(w-1))*2-1)*ahc,
((float64(h-py-1)/(h-1))*2-1)*hfc,
)
}

func main() {
var (
p  = gfx.PaletteEN4
p0 = pixelCoordinates(0, 0)
p1 = pixelCoordinates(w-1, h-1)
y  = p0.Y
d  = gfx.V((p1.X-p0.X)/(w-1), (p1.Y-p0.Y)/(h-1))
m  = gfx.NewImage(w, h)
)

for py := 0; py < h; py++ {
x := p0.X

for px := 0; px < w; px++ {
cc := p.CmplxPhaseAt(gfx.CmplxCos(gfx.CmplxSin(0.42 / complex(y*x, x*x))))

m.Set(px, py, cc)

x += d.X
}

y += d.Y
}

gfx.SavePNG("gfx-example-domain-coloring.png", m)
}
``````

#### Animation

There is rudimentary support for making animations using `gfx.Animation`, the animations can then be encoded into GIF.

``````package main

import "github.com/peterhellberg/gfx"

func main() {
a := &gfx.Animation{}
p := gfx.PaletteEDG36

var fireflower = []uint8{
0, 1, 1, 1, 1, 1, 1, 0,
1, 1, 2, 2, 2, 2, 1, 1,
1, 2, 3, 3, 3, 3, 2, 1,
1, 1, 2, 2, 2, 2, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 4, 4, 0, 0, 0,
0, 0, 0, 4, 4, 0, 0, 0,
4, 4, 0, 4, 4, 0, 4, 4,
0, 4, 0, 4, 4, 0, 4, 0,
0, 4, 4, 4, 4, 4, 4, 0,
0, 0, 4, 4, 4, 4, 0, 0,
}

for i := 0; i < len(p)-4; i++ {
t := gfx.NewTile(p[i:i+4], 8, fireflower)

}

a.SaveGIF("gfx-example-animation.gif")
}
``````

#### Line drawing

##### DrawInt functions

Drawing functions based on TinyDraw, which in turn is based on the Adafruit GFX library.

``````package main

import "github.com/peterhellberg/gfx"

func main() {
m := gfx.NewImage(160, 128, gfx.ColorTransparent)

p := gfx.PaletteNight16

gfx.DrawIntLine(m, 10, 10, 94, 10, p.Color(0))
gfx.DrawIntLine(m, 94, 16, 10, 16, p.Color(1))
gfx.DrawIntLine(m, 10, 20, 10, 118, p.Color(2))
gfx.DrawIntLine(m, 16, 118, 16, 20, p.Color(4))

gfx.DrawIntLine(m, 40, 40, 80, 80, p.Color(5))
gfx.DrawIntLine(m, 40, 40, 80, 70, p.Color(6))
gfx.DrawIntLine(m, 40, 40, 80, 60, p.Color(7))
gfx.DrawIntLine(m, 40, 40, 80, 50, p.Color(8))
gfx.DrawIntLine(m, 40, 40, 80, 40, p.Color(9))

gfx.DrawIntLine(m, 100, 100, 40, 100, p.Color(10))
gfx.DrawIntLine(m, 100, 100, 40, 90, p.Color(11))
gfx.DrawIntLine(m, 100, 100, 40, 80, p.Color(12))
gfx.DrawIntLine(m, 100, 100, 40, 70, p.Color(13))
gfx.DrawIntLine(m, 100, 100, 40, 60, p.Color(14))
gfx.DrawIntLine(m, 100, 100, 40, 50, p.Color(15))

gfx.DrawIntRectangle(m, 30, 106, 120, 20, p.Color(14))
gfx.DrawIntFilledRectangle(m, 34, 110, 112, 12, p.Color(8))

gfx.DrawIntCircle(m, 120, 30, 20, p.Color(5))
gfx.DrawIntFilledCircle(m, 120, 30, 16, p.Color(4))

gfx.DrawIntTriangle(m, 120, 102, 100, 80, 152, 46, p.Color(9))
gfx.DrawIntFilledTriangle(m, 119, 98, 105, 80, 144, 54, p.Color(6))

s := gfx.NewScaledImage(m, 6)

gfx.SavePNG("gfx-example-draw-int.png", s)
}
``````
##### Bresenham's line algorithm

`gfx.DrawLineBresenham` draws a line using Bresenham's line algorithm.

``````package main

import "github.com/peterhellberg/gfx"

var (
red   = gfx.BlockColorRed.Medium
green = gfx.BlockColorGreen.Medium
blue  = gfx.BlockColorBlue.Medium
)

func main() {
m := gfx.NewImage(32, 16, gfx.ColorTransparent)

gfx.DrawLineBresenham(m, gfx.V(2, 2), gfx.V(2, 14), red)
gfx.DrawLineBresenham(m, gfx.V(6, 2), gfx.V(32, 2), green)
gfx.DrawLineBresenham(m, gfx.V(6, 6), gfx.V(30, 14), blue)

s := gfx.NewScaledImage(m, 16)

gfx.SavePNG("gfx-example-bresenham-line.png", s)
}
``````

#### Geometry and Transformation

The (2D) geometry and transformation types are based on those found in https://github.com/faiface/pixel (but indended for use without Pixel)

##### 2D types
###### Vec

`gfx.Vec` is a 2D vector type with X and Y components.

###### Rect

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

###### Matrix

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

``````package main

import "github.com/peterhellberg/gfx"

var en4 = gfx.PaletteEN4

func main() {
a := &gfx.Animation{Delay: 10}

c := gfx.V(128, 128)

p := gfx.Polygon{
{50, 50},
{50, 206},
{128, 96},
{206, 206},
{206, 50},
}

for d := 0.0; d < 360; d += 2 {
m := gfx.NewPaletted(256, 256, en4, en4.Color(3))

matrix := gfx.IM.RotatedDegrees(c, d)

gfx.DrawPolygon(m, p.Project(matrix), 0, en4.Color(2))
gfx.DrawPolygon(m, p.Project(matrix.Scaled(c, 0.5)), 0, en4.Color(1))

gfx.DrawCircleFilled(m, c, 5, en4.Color(0))

}

}
``````
##### 3D types
###### Vec3

`gfx.Vec3` is a 3D vector type with X, Y and Z components.

###### Box

`gfx.Box` is a 3D box. It is defined by two `gfx.Vec3`, Min and Max

#### Errors

The `gfx.Error` type is a string that implements the `error` interface.

If you are using Ebiten then you can return the provided `gfx.ErrDone` error to exit its run loop.

#### HTTP

You can use `gfx.GetPNG` to download and decode a PNG given an URL.

#### Log

I find that it is fairly common for me to do some logging driven development when experimenting with graphical effects, so I've included `gfx.Log`, `gfx.Dump`, `gfx.Printf` and `gfx.Sprintf` in this package.

#### Math

I have included a few functions that call functions in the `math` package.

There is also `gfx.Sign`, `gfx.Clamp` and `gfx.Lerp` functions for `float64`.

#### Cmplx

I have included a few functions that call functions in the `cmplx` package.

It is fairly common to read files in my experiments, so I've included `gfx.ReadFile` and `gfx.ReadJSON` in this package.

#### Resizing images

You can use `gfx.ResizeImage` to resize an image. (nearest neighbor, mainly useful for pixelated graphics)

#### Noise

Different types of noise is often used in procedural generation.

##### SimplexNoise

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

``````package main

import "github.com/peterhellberg/gfx"

func main() {
sn := gfx.NewSimplexNoise(17)

dst := gfx.NewImage(1024, 256)

gfx.EachImageVec(dst, gfx.ZV, func(u gfx.Vec) {
n := sn.Noise2D(u.X/900, u.Y/900)
c := gfx.PaletteSplendor128.At(n / 2)

gfx.SetVec(dst, u, c)
})

gfx.SavePNG("gfx-example-simplex.png", dst)
}
``````

#### Colors

You can construct new colors using `gfx.ColorRGBA`, `gfx.ColorNRGBA`, `gfx.ColorGray`, `gfx.ColorGray16` and `gfx.ColorWithAlpha`.

There is also a `gfx.LerpColors` function that performs linear interpolation between two colors.

##### Default colors

There are a few default colors in this package, convenient when you just want to experiment, for more ambitious projects I suggest creating a `gfx.Palette` (or even use one of the included palettes).

Variable Color
`gfx.ColorBlack`
`gfx.ColorWhite`
`gfx.ColorTransparent`
`gfx.ColorOpaque`
`gfx.ColorRed`
`gfx.ColorGreen`
`gfx.ColorBlue`
`gfx.ColorCyan`
`gfx.ColorMagenta`
`gfx.ColorYellow`
##### Block colors

Each `gfx.BlockColor` consists of a `Dark`, `Medium` and `Light` shade of the same color.

Variable Block Color
`gfx.BlockColorYellow`
`gfx.BlockColorOrange`
`gfx.BlockColorBrown`
`gfx.BlockColorGreen`
`gfx.BlockColorBlue`
`gfx.BlockColorPurple`
`gfx.BlockColorRed`
`gfx.BlockColorWhite`
`gfx.BlockColorBlack`
`gfx.BlockColorGoGopherBlue`
`gfx.BlockColorGoLightBlue`
`gfx.BlockColorGoAqua`
`gfx.BlockColorGoFuchsia`
`gfx.BlockColorGoBlack`
`gfx.BlockColorGoYellow`
##### Palettes

There are a number of palettes in the `gfx` package, most of them are found in the Lospec Palette List.

Variable Colors Lospec Palette
`gfx.Palette1Bit` 2
`gfx.Palette2BitGrayScale` 4
`gfx.PaletteEN4` 4
`gfx.PaletteARQ4` 4
`gfx.PaletteInk` 5
`gfx.Palette3Bit` 8
`gfx.PaletteEDG8` 8
`gfx.PaletteAmmo8` 8
`gfx.PaletteNYX8` 8
`gfx.Palette15PDX` 15
`gfx.PaletteCGA` 16
`gfx.PalettePICO8` 16
`gfx.PaletteNight16` 16
`gfx.PaletteAAP16` 16
`gfx.PaletteArne16` 16
`gfx.PaletteEDG16` 16
`gfx.Palette20PDX` 20
`gfx.PaletteTango` 27
`gfx.PaletteEDG32` 32
`gfx.PaletteEDG36` 36
`gfx.PaletteEDG64` 64
`gfx.PaletteAAP64` 64
`gfx.PaletteFamicube` 64
`gfx.PaletteSplendor128` 128

The palette images were generated like this:

``````package main

import "github.com/peterhellberg/gfx"

func main() {
for size, paletteLookup := range gfx.PalettesByNumberOfColors {
for name, palette := range paletteLookup {
dst := gfx.NewImage(size, 1)

for x, c := range palette {
dst.Set(x, 0, c)
}

filename := gfx.Sprintf("gfx-Palette%s.png", name)

gfx.SavePNG(filename, gfx.NewResizedImage(dst, 1120, 96))
}
}
}
``````

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Documentation ¶

### Overview ¶

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

### Constants ¶

View Source
```const (
Pi = 3.14159265358979323846264338327950288419716939937510582097494459 // https://oeis.org/A000796
)```

Mathematical constants.

### Variables ¶

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

View Source
```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.

View Source
```var (
Stdout = os.Stdout
Stderr = os.Stderr
)```

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

View Source
```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},
}
)```
View Source
`var DefaultAnimationDelay = 50`

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

View Source
`var ErrDone = Error("done")`

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

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

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

View Source
`var IM = Matrix{1, 0, 0, 1, 0, 0}`

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.

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.

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.

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.

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.

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

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.

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.

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

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

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

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

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

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},
{0x1B, 0x1C, 0x33, 0xFF},
}```

PaletteEDG8 is the Endesga 8 palette.

Created by Endesga. #EDG8

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

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},
{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.

View Source
```var PaletteGo = Palette{
{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},
{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},
{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.

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.

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.

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.

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},
{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.

View Source
```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

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},
{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.

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.

View Source
`var ZP = image.ZP`

ZP is the zero image.Point.

View Source
`var ZR = image.ZR`

ZR is the zero image.Rectangle.

View Source
`var ZV = Vec{0, 0}`

ZV is a zero vector.

View Source
`var ZV3 = Vec3{0, 0, 0}`

ZV3 is the zero Vec3

### Functions ¶

#### func Base64EncodedPNG ¶

`func Base64EncodedPNG(src image.Image) string`

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

#### func Base64ImgTag ¶

`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 ¶

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

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

10
15
20
```

#### func CmplxCos ¶

`func CmplxCos(x complex128) complex128`

CmplxCos returns the cosine of x.

Example
```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 ¶

`func CmplxCosh(x complex128) complex128`

CmplxCosh returns the hyperbolic cosine of x.

Example
```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 ¶

`func CmplxPhase(x complex128) float64`

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

Example
```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 ¶

`func CmplxPow(x, y complex128) complex128`

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

Example
```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 ¶

`func CmplxSin(x complex128) complex128`

CmplxSin returns the sine of x.

Example
```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 ¶

`func CmplxSinh(x complex128) complex128`

CmplxSinh returns the hyperbolic sine of x.

Example
```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 ¶

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

Example
```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 ¶

`func CmplxTan(x complex128) complex128`

CmplxTan returns the tangent of x.

Example
```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 ¶

`func CmplxTanh(x complex128) complex128`

CmplxTanh returns the hyperbolic tangent of x.

Example
```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 ¶

`func ColorGray(y uint8) color.Gray`

ColorGray construcs a color.Gray.

#### func ColorGray16 ¶

`func ColorGray16(y uint16) color.Gray16`

ColorGray16 construcs a color.Gray16.

#### func ColorNRGBA ¶

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

ColorNRGBA constructs a color.NRGBA.

#### func ColorRGBA ¶

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

ColorRGBA constructs a color.RGBA.

#### func ColorWithAlpha ¶

`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 CreateFile ¶

`func CreateFile(fn string) (*os.File, error)`

CreateFile creates or truncates the named file.

#### func DecodeImage ¶

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

DecodeImage decodes an image from the provided io.Reader.

#### func DecodeImageBytes ¶

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

DecodeImageBytes decodes an image from the provided []byte.

#### func DecodePNG ¶

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

DecodePNG decodes a PNG from the provided io.Reader.

#### func DecodePNGBytes ¶

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

DecodePNGBytes decodes a PNG from the provided []byte.

#### func Draw ¶

`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 ¶

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

DrawCicleFast draws a (crude) filled circle.

#### func DrawCircle ¶

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

Example (Annular)
```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:

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓▓▓░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
```
Example (Filled)
```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 ¶

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

DrawCircleFilled draws a filled circle.

#### func DrawColor ¶

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

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

#### func DrawColorOver ¶

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

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

#### func DrawIntCircle ¶

`func DrawIntCircle(dst draw.Image, x0, y0, r int, c color.Color)`

DrawIntCircle draws a circle given a point and radius

#### func DrawIntFilledCircle ¶

`func DrawIntFilledCircle(dst draw.Image, x0, y0, r int, c color.Color)`

DrawIntFilledCircle draws a filled circle given a point and radius

#### func DrawIntFilledRectangle ¶

`func DrawIntFilledRectangle(dst draw.Image, x, y, w, h int, c color.Color)`

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

#### func DrawIntFilledTriangle ¶

`func DrawIntFilledTriangle(dst draw.Image, x0, y0, x1, y1, x2, y2 int, c color.Color)`

DrawIntFilledTriangle draws a filled triangle given three points

#### func DrawIntLine ¶

`func DrawIntLine(dst draw.Image, x0, y0, x1, y1 int, c color.Color)`

DrawIntLine draws a line between two points

#### func DrawIntRectangle ¶

`func DrawIntRectangle(dst draw.Image, x, y, w, h int, c color.Color)`

DrawIntRectangle draws a rectangle given a point, width and height

#### func DrawIntTriangle ¶

`func DrawIntTriangle(dst draw.Image, x0, y0, x1, y1, x2, y2 int, c color.Color)`

DrawIntTriangle draws a triangle given three points

#### func DrawLine ¶

`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 ¶

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

DrawLineBresenham draws a line using Bresenham's line algorithm.

Example
```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:

░░░░░░░░░░░░░░░░░░░░
░░▓▓▓▓░░░░░░░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░░░░░░░▓▓▓▓░░
░░░░░░░░░░░░░░░░░░░░
```
Example (Steep)
```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 ¶

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

DrawOver draws src over dst.

#### func DrawPalettedImage ¶

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

DrawPalettedImage draws a PalettedImage over a PalettedDrawImage.

#### func DrawPalettedLayer ¶

`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 ¶

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

DrawPointCircle draws a circle at the given point.

#### func DrawPolygon ¶

`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 ¶

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

DrawPolyline draws a polyline with the given color and thickness.

#### func DrawSrc ¶

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

DrawSrc draws src on dst.

#### func DrawTriangles ¶

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

DrawTriangles draws triangles on dst.

#### func DrawTrianglesOver ¶

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

DrawTrianglesOver draws triangles over dst.

#### func DrawTrianglesWireframe ¶

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

DrawTrianglesWireframe draws triangles on dst.

#### func Dump ¶

`func Dump(a ...interface{})`

Dump all of the arguments to standard output.

Example
```Dump([]string{"foo", "bar"})
```
```Output:

[foo bar]
```

#### func EachImageVec ¶

`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 ¶

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

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

#### func EncodeJSON ¶

`func EncodeJSON(w io.Writer, v interface{}, options ...func(*json.Encoder)) error`

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

#### func EncodePNG ¶

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

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

#### func Errorf ¶

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

Errorf constructs a formatted error.

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

fmt.Println(err)
```
```Output:

foo 123 and bar abc
```

#### func Fatal ¶

`func Fatal(v ...interface{})`

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

#### func Get ¶

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

Get performs a HTTP GET request using the DefaultClient.

#### func GetImage ¶

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

GetImage retrieves a remote image using DefaultClient

#### func GetPNG ¶

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

GetPNG retrieves a remote PNG using DefaultClient

#### func IR ¶

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

IR returns an image.Rectangle for the given input.

#### func IntAbs ¶

`func IntAbs(x int) int`

IntAbs returns the absolute value of x.

Example
```Dump(
IntAbs(10),
IntAbs(-5),
)
```
```Output:

10
5
```

#### func IntClamp ¶

`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 ¶

`func IntMax(x, y int) int`

IntMax returns the larger of x or y.

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

2
2
-1
```

#### func IntMin ¶

`func IntMin(x, y int) int`

IntMin returns the smaller of x or y.

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

1
1
-2
```

#### func JSONIndent ¶

`func JSONIndent(prefix, indent string) func(*json.Encoder)`

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

#### func Lerp ¶

`func Lerp(a, b, t float64) float64`

Lerp does linear interpolation between two values.

Example
```Dump(
Lerp(0, 2, 0.1),
Lerp(1, 10, 0.5),
Lerp(2, 4, 0.5),
)
```
```Output:

0.2
5.5
3
```

#### func LerpColors ¶

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

LerpColors performs linear interpolation between two colors.

#### func Log ¶

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

Log to standard output.

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

Foo: 123
```

#### func MathAbs ¶

`func MathAbs(x float64) float64`

MathAbs returns the absolute value of x.

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

2
1
0
1
2
```

#### func MathAtan ¶

`func MathAtan(x float64) float64`

MathAtan returns the arctangent, in radians, of x.

#### func MathCeil ¶

`func MathCeil(x float64) float64`

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

Example
```Dump(
MathCeil(0.2),
MathCeil(1.4),
MathCeil(2.6),
)
```
```Output:

1
2
3
```

#### func MathCos ¶

`func MathCos(x float64) float64`

MathCos returns the cosine of the radian argument x.

Example
```Dump(
MathCos(1),
MathCos(2),
MathCos(3),
)
```
```Output:

0.5403023058681398
-0.4161468365471424
-0.9899924966004454
```

#### func MathCosh ¶

`func MathCosh(x float64) float64`

MathCosh returns the hyperbolic cosine of x.

#### func MathFloor ¶

`func MathFloor(x float64) float64`

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

Example
```Dump(
MathFloor(0.2),
MathFloor(1.4),
MathFloor(2.6),
)
```
```Output:

0
1
2
```

#### func MathHypot ¶

`func MathHypot(p, q float64) float64`

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

Example
```Dump(
MathHypot(15, 8),
MathHypot(5, 12),
MathHypot(3, 4),
)
```
```Output:

17
13
5
```

#### func MathLog ¶

`func MathLog(x float64) float64`

MathLog returns the natural logarithm of x.

#### func MathMax ¶

`func MathMax(x, y float64) float64`

MathMax returns the larger of x or y.

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

1
2
3
```

#### func MathMin ¶

`func MathMin(x, y float64) float64`

MathMin returns the smaller of x or y.

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

-1
1
2
```

#### func MathPow ¶

`func MathPow(x, y float64) float64`

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

#### func MathRound ¶

`func MathRound(x float64) float64`

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

#### func MathSin ¶

`func MathSin(x float64) float64`

MathSin returns the sine of the radian argument x.

Example
```Dump(
MathSin(1),
MathSin(2),
MathSin(3),
)
```
```Output:

0.8414709848078965
0.9092974268256816
0.1411200080598672
```

#### func MathSinh ¶

`func MathSinh(x float64) float64`

MathSinh returns the hyperbolic sine of x.

#### func MathSqrt ¶

`func MathSqrt(x float64) float64`

MathSqrt returns the square root of x.

Example
```Dump(
MathSqrt(1),
MathSqrt(2),
MathSqrt(3),
)
```
```Output:

1
1.4142135623730951
1.7320508075688772
```

#### func MathTan ¶

`func MathTan(x float64) float64`

MathTan returns the tangent of the radian argument x.

#### func Mix ¶

`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 ¶

`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 ¶

`func MustOpenImage(fn string) image.Image`

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

#### func NewGray ¶

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

NewGray returns a new Gray image with the given bounds.

#### func NewGray16 ¶

`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 ¶

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

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

#### func NewJSONEncoder ¶

`func NewJSONEncoder(w io.Writer, options ...func(*json.Encoder)) *json.Encoder`

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

#### func NewNRGBA ¶

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

NewNRGBA returns a new NRGBA image with the given bounds.

#### func NewRGBA ¶

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

NewRGBA returns a new RGBA image with the given bounds.

#### func NewResizedImage ¶

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

NewResizedImage returns a new image with the provided dimensions.

#### func NewResizedRGBA ¶

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

NewResizedRGBA returns a new RGBA image with the provided dimensions.

#### func NewScaledImage ¶

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

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

Example
```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 ¶

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

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

#### func NewUniform ¶

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

NewUniform creates a new uniform image of the given color.

#### func OpenFile ¶

`func OpenFile(fn string) (*os.File, error)`

OpenFile opens the named file for reading.

#### func OpenImage ¶

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

OpenImage decodes an image using the provided file name.

#### func Playground ¶

`func Playground(src image.Image)`

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

#### func Printf ¶

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

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

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

"foo bar" 1.2
```

#### func Pt ¶

`func Pt(x, y int) image.Point`

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

#### func RandFloat64 ¶

`func RandFloat64() float64`

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

#### func RandIntn ¶

`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 ¶

`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(fn string, rf ReadFunc) error`

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

ReadJSON opens and decodes a JSON file.

#### func ResizeImage ¶

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

ResizeImage using nearest neighbor scaling on dst from src.

#### func SavePNG ¶

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

SavePNG saves an image using the provided file name.

#### func Set ¶

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

Set x and y to the given color.

#### func SetPoint ¶

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

SetPoint to the given color.

#### func SetVec ¶

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

SetVec to the given color.

#### func Sign ¶

`func Sign(x float64) float64`

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

Example
```Dump(
Sign(-2),
Sign(0),
Sign(2),
)
```
```Output:

-1
0
1
```

#### func SortSlice ¶

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

SortSlice sorts the provided slice given the provided less function.

#### func Sprintf ¶

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

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

### Types ¶

#### type Animation ¶

```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 (a *Animation) AddFrame(frame image.Image, palette color.Palette)`

`func (a *Animation) AddPalettedImage(frame PalettedImage)`

#### func (*Animation) EncodeGIF ¶

`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 ¶

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

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

#### type BasicTarget ¶

```type BasicTarget interface {
Target

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

#### type Batch ¶

```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 ¶

`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 ¶

`func (b *Batch) Clear()`

Clear removes all objects from the Batch.

#### func (*Batch) Dirty ¶

`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 ¶

`func (b *Batch) Draw(t Target)`

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

#### func (*Batch) MakePicture ¶

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

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

#### func (*Batch) MakeTriangles ¶

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

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

#### func (*Batch) SetMatrix ¶

`func (b *Batch) SetMatrix(m Matrix)`

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

#### type Block ¶

```type Block struct {
Pos   Vec3
Size  Vec3
Color BlockColor
}```

Block has a position, size and color.

#### func NewBlock ¶

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

NewBlock creates a new Block.

#### func (Block) Behind ¶

`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 ¶

`func (b Block) Box() Box`

Box creates a box for the Block.

#### func (Block) Corners ¶

`func (b Block) Corners(origin Vec3) BlockCorners`

Corners returns the screen coordinates for the Block corners.

#### func (Block) Draw ¶

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

Draw block on dst at origin.

#### func (Block) DrawBounds ¶

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

DrawBounds for block on dst at origin.

#### func (Block) DrawOver ¶

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

DrawOver draws block over dst at origin.

#### func (Block) DrawPolygons ¶

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

DrawPolygons for block on dst at origin.

#### func (Block) DrawRectangles ¶

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

DrawRectangles for block on dst at origin.

#### func (Block) DrawWireframe ¶

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

DrawWireframe block on dst at origin.

#### func (Block) Polygons ¶

`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 ¶

`func (b Block) Rect(origin Vec3) Rect`

Rect for the block.

#### func (Block) Shape ¶

`func (b Block) Shape(origin Vec3) Polygon`

Shape returns the shape Polygon

#### func (Block) Space ¶

`func (b Block) Space() BlockSpace`

Space returns the BlockSpace for the Block.

#### func (Block) Triangles ¶

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

Triangles for the Block

#### func (Block) TrianglesData ¶

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

TrianglesData creates triangles data for the Block.

#### type BlockColor ¶

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

BlockColor contains a Light, Medium and Dark color.

#### type BlockCorners ¶

```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 ¶

`func (bc BlockCorners) Left() Polygon`

Left face Polygon.

#### func (BlockCorners) Rect ¶

`func (bc BlockCorners) Rect() Rect`

Rect for the Block corners.

#### func (BlockCorners) Right ¶

`func (bc BlockCorners) Right() Polygon`

Right face Polygon.

#### func (BlockCorners) Shape ¶

`func (bc BlockCorners) Shape() Polygon`

Shape Polygon.

#### func (BlockCorners) Top ¶

`func (bc BlockCorners) Top() Polygon`

Top face Polygon.

#### type BlockSpace ¶

```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 ¶

`func (bs BlockSpace) CornerBackDown(origin Vec3) Vec`

CornerBackDown returns the screen coordinate for the BackDown corner.

#### func (BlockSpace) CornerBackUp ¶

`func (bs BlockSpace) CornerBackUp(origin Vec3) Vec`

CornerBackUp returns the screen coordinate for the BackUp corner.

#### func (BlockSpace) CornerFrontDown ¶

`func (bs BlockSpace) CornerFrontDown(origin Vec3) Vec`

CornerFrontDown returns the screen coordinate for the FrontDown corner.

#### func (BlockSpace) CornerFrontUp ¶

`func (bs BlockSpace) CornerFrontUp(origin Vec3) Vec`

CornerFrontUp returns the screen coordinate for the FrontUp corner.

#### func (BlockSpace) CornerLeftDown ¶

`func (bs BlockSpace) CornerLeftDown(origin Vec3) Vec`

CornerLeftDown returns the screen coordinate for the LeftDown corner.

#### func (BlockSpace) CornerLeftUp ¶

`func (bs BlockSpace) CornerLeftUp(origin Vec3) Vec`

CornerLeftUp returns the screen coordinate for the LeftUp corner.

#### func (BlockSpace) CornerRightDown ¶

`func (bs BlockSpace) CornerRightDown(origin Vec3) Vec`

CornerRightDown returns the screen coordinate for the RightDown corner.

#### func (BlockSpace) CornerRightUp ¶

`func (bs BlockSpace) CornerRightUp(origin Vec3) Vec`

CornerRightUp returns the screen coordinate for the RightUp corner.

#### func (BlockSpace) Corners ¶

`func (bs BlockSpace) Corners(origin Vec3) BlockCorners`

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

#### type Blocks ¶

`type Blocks []Block`

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

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

Draw all blocks.

#### func (Blocks) DrawBounds ¶

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

DrawBounds for all blocks.

#### func (Blocks) DrawPolygons ¶

`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 ¶

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

DrawRectangles for all blocks.

#### func (Blocks) DrawWireframes ¶

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

DrawWireframes for all blocks.

#### func (Blocks) Sort ¶

`func (blocks Blocks) Sort()`

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

#### type Box ¶

```type Box struct {
Min Vec3
Max Vec3
}```

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

#### func B ¶

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

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

#### func NewBox ¶

`func NewBox(min, max Vec3) Box`

NewBox creates a new Box.

#### func (Box) Behind ¶

`func (b Box) Behind(a Box) bool`

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

#### func (Box) Overlaps ¶

`func (b Box) Overlaps(a Box) bool`

Overlaps checks if two boxes overlap or not.

#### type CIELab ¶

```type CIELab struct {
L float64
A float64
B float64
}```

CIELab represents a color in CIE-L*ab.

#### func (CIELab) DeltaC ¶

`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 ¶

`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 ¶

`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 ¶

```type Circle struct {
Center Vec
}```

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

• Center vector

#### func C ¶

`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 ¶

`func (c Circle) Area() float64`

Area returns the area of the Circle.

#### func (Circle) Contains ¶

`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 ¶

`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 ¶

`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 ¶

`func (c Circle) Moved(delta Vec) Circle`

Moved returns the Circle moved by the given vector delta.

#### func (Circle) Norm ¶

`func (c Circle) Norm() Circle`

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

#### func (Circle) Resized ¶

`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 ¶

`func (c Circle) String() string`

String returns the string representation of the Circle.

#### func (Circle) Union ¶

`func (c Circle) Union(d Circle) Circle`

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

#### type Degrees ¶

`type Degrees float64`

Degrees of arc.

`func (d Degrees) Radians() float64`

#### type Domain ¶

`type Domain []float64`

Domain of values.

#### func (Domain) Max ¶

`func (d Domain) Max() float64`

Max value in the Domain.

#### func (Domain) Min ¶

`func (d Domain) Min() float64`

Min value in the Domain.

#### type DrawTarget ¶

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

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

#### func NewDrawTarget ¶

`func NewDrawTarget(dst draw.Image) *DrawTarget`

NewDrawTarget creates a new draw target.

#### func (*DrawTarget) At ¶

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

At retrieves the color at (x, y).

#### func (*DrawTarget) Bounds ¶

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

Bounds of the draw target.

#### func (*DrawTarget) Center ¶

`func (dt *DrawTarget) Center() Vec`

Center vector of the draw target.

#### func (*DrawTarget) ColorModel ¶

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

ColorModel of the draw target.

#### func (*DrawTarget) MakePicture ¶

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

MakePicture creates a TargetPicture for the provided Picture.

#### func (*DrawTarget) MakeTriangles ¶

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

MakeTriangles creates TargetTriangles for the given Triangles

#### func (*DrawTarget) Set ¶

`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 ¶

`func (dt *DrawTarget) SetMatrix(mat Matrix)`

SetMatrix sets the matrix of the draw target.

#### type Drawer ¶

```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 ¶

`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 ¶

`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 ¶

`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 ¶

`type Error string`

Error is a string that implements the error interface.

#### func (Error) Error ¶

`func (e Error) Error() string`

Error implements the error interface.

#### type Float64Scaler ¶

```type Float64Scaler interface {
ScaleFloat64(float64) float64
}```

Float64Scaler can scale a float64 to another float64.

#### type GeoPoint ¶

```type GeoPoint struct {
Lon float64
Lat float64
}```

GeoPoint represents a geographic point with Lat/Lon.

#### func GP ¶

`func GP(lat, lon float64) GeoPoint`

GP creates a new GeoPoint

#### func NewGeoPointFromTileNumbers ¶

`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 ¶

`func (gp GeoPoint) GeoTile(zoom int) GeoTile`

GeoTile for the GeoPoint at the given zoom level.

#### func (GeoPoint) In ¶

`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 ¶

`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 ¶

```type GeoTile struct {
Zoom int
X    int
Y    int
}```

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

#### func GT ¶

`func GT(zoom, x, y int) GeoTile`

GT creates a new GeoTile.

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

#### func (GeoTile) Bounds ¶

`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 ¶

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

Draw the tile on dst.

#### func (GeoTile) E ¶

`func (gt GeoTile) E() GeoTile`

E is the tile to the east.

#### func (GeoTile) GeoPoint ¶

`func (gt GeoTile) GeoPoint() GeoPoint`

GeoPoint for the GeoTile.

#### func (GeoTile) GetImage ¶

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

GetImage for the tile.

#### func (GeoTile) N ¶

`func (gt GeoTile) N() GeoTile`

N is the tile to the north.

#### func (GeoTile) NE ¶

`func (gt GeoTile) NE() GeoTile`

NE is the tile to the northeast.

#### func (GeoTile) NW ¶

`func (gt GeoTile) NW() GeoTile`

NW is the tile to the northwest.

#### func (GeoTile) Neighbors ¶

`func (gt GeoTile) Neighbors() GeoTiles`

Neighbors returns the neighboring tiles.

#### func (GeoTile) Rawurl ¶

`func (gt GeoTile) Rawurl(format string) string`

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

#### func (GeoTile) S ¶

`func (gt GeoTile) S() GeoTile`

S is the tile to the south.

#### func (GeoTile) SE ¶

`func (gt GeoTile) SE() GeoTile`

SE is the tile to the southeast.

#### func (GeoTile) SW ¶

`func (gt GeoTile) SW() GeoTile`

SW is the tile to the southwest.

#### func (GeoTile) Vec ¶

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

Vec returns the Vec for the GeoPoint in the GeoTile.

#### func (GeoTile) W ¶

`func (gt GeoTile) W() GeoTile`

W is the tile to the west.

#### type GeoTileServer ¶

```type GeoTileServer struct {
Format string
}```

GeoTileServer represents a tile server.

#### func GTS ¶

`func GTS(format string) GeoTileServer`

GTS creates a GeoTileServer.

#### func (GeoTileServer) DrawNeighbors ¶

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

DrawNeighbors on dst.

#### func (GeoTileServer) DrawTile ¶

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

DrawTile on dst.

#### func (GeoTileServer) DrawTileAndNeighbors ¶

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

DrawTileAndNeighbors on dst.

#### func (GeoTileServer) GetImage ¶

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

GetImage for the given GeoTile from the tile server.

#### type GeoTiles ¶

`type GeoTiles []GeoTile`

GeoTiles is a slice of GeoTile.

#### type HSL ¶

```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 ¶

`func ColorToHSL(c color.Color) HSL`

ColorToHSL converts a color into HSL.

#### func (HSL) Components ¶

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

Components in HSL.

#### func (HSL) RGBA ¶

`func (hsl HSL) RGBA() color.RGBA`

RGBA converts a HSL color value to color.RGBA.

#### type HSV ¶

```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 ¶

`func ColorToHSV(c color.Color) HSV`

ColorToHSV converts a color into HSV.

#### func (HSV) Components ¶

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

Components in HSV.

#### func (HSV) RGBA ¶

`func (hsv HSV) RGBA() color.RGBA`

RGBA converts a HSV color value to color.RGBA.

#### type HTTP ¶

```type HTTP struct {
*http.Client
UserAgent string
}```

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

#### type HunterLab ¶

```type HunterLab struct {
L float64
A float64
B float64
}```

HunterLab represents a color in Hunter-Lab.

#### func (HunterLab) XYZ ¶

`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 ¶

```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 ¶

`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 ¶

`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 ¶

`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 ¶

`func (imd *IMDraw) Clear()`

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

#### func (*IMDraw) Draw ¶

`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 ¶

`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 ¶

`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 ¶

`func (imd *IMDraw) Line(thickness float64)`

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

#### func (*IMDraw) MakePicture ¶

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

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

#### func (*IMDraw) MakeTriangles ¶

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

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

#### func (*IMDraw) Polygon ¶

`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 ¶

`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 ¶

`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 ¶

`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 ¶

`func (imd *IMDraw) SetMatrix(m Matrix)`

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

#### type Layer ¶

```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 ¶

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

NewLayer creates a new layer.

#### func (*Layer) AlphaAt ¶

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

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

#### func (*Layer) At ¶

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

At returns the color at (x, y).

#### func (*Layer) Bounds ¶

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

Bounds returns the bounds of the paletted layer.

#### func (*Layer) ColorIndexAt ¶

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

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

#### func (*Layer) ColorModel ¶

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

ColorModel returns the color model for the paletted layer.

#### func (*Layer) ColorPalette ¶

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

ColorPalette retrieves the layer palette.

#### func (*Layer) DataAt ¶

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

DataAt returns the data at (dx, dy).

#### func (*Layer) GfxPalette ¶

`func (l *Layer) GfxPalette() Palette`

GfxPalette retrieves the layer palette.

#### func (*Layer) Index ¶

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

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

#### func (*Layer) NRGBAAt ¶

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

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

#### func (*Layer) Put ¶

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

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

#### func (*Layer) SetTileIndex ¶

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

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

#### func (*Layer) TileAt ¶

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

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

#### func (*Layer) TileIndexAt ¶

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

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

#### func (*Layer) TileSize ¶

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

TileSize returns the tileset tile size.

#### type LayerData ¶

`type LayerData []int`

LayerData is the data for a layer.

#### func (LayerData) Size ¶

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

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

#### type LinearScaler ¶

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

LinearScaler can scale domain values to a range values.

#### func NewLinearScaler ¶

`func NewLinearScaler() LinearScaler`

NewLinearScaler creates a new linear scaler.

#### func (LinearScaler) Domain ¶

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

Domain returns a LinearScaler with the given domain.

#### func (LinearScaler) Range ¶

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

Range returns a LinearScaler with the given range.

#### func (LinearScaler) ScaleFloat64 ¶

`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 ¶

`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 ¶

`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 ¶

`func (m Matrix) Moved(delta Vec) Matrix`

Moved moves everything by the delta vector.

#### func (Matrix) Project ¶

`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 ¶

`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 ¶

`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 ¶

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

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

#### func (Matrix) ScaledXY ¶

`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 ¶

`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 ¶

`func (m Matrix) Unproject(u Vec) Vec`

Unproject does the inverse operation to Project.

Time complexity is O(1).

#### type Palette ¶

`type Palette []color.NRGBA`

Palette is a slice of colors.

#### func (Palette) AsColorPalette ¶

`func (p Palette) AsColorPalette() color.Palette`

AsColorPalette converts the Palette to a color.Palette.

#### func (Palette) At ¶

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

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

#### func (Palette) CmplxPhaseAt ¶

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

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

#### func (Palette) Color ¶

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

Color returns the color at index n.

#### func (Palette) Convert ¶

`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 ¶

`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 ¶

`func (p Palette) Len() int`

Len returns the number of colors in the palette.

#### func (Palette) Random ¶

`func (p Palette) Random() color.NRGBA`

Random color from the palette.

#### func (Palette) Sort ¶

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

Sort palette.

#### func (Palette) SortByHue ¶

`func (p Palette) SortByHue()`

SortByHue sorts based on (HSV) Hue.

#### func (Palette) Tile ¶

`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 ¶

`type PaletteLookup map[PaletteName]Palette`

PaletteLookup is a map of PaletteName to Palette.

#### type PaletteName ¶

`type PaletteName string`

PaletteName is a palette name.

#### type Paletted ¶

```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 ¶

`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 ¶

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

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

#### func NewResizedPalettedImage ¶

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

NewResizedPalettedImage returns an image with the provided dimensions.

#### func NewScaledPalettedImage ¶

`func NewScaledPalettedImage(src PalettedImage, s float64) *Paletted`

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

#### func NewTile ¶

`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 ¶

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

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

#### func (*Paletted) At ¶

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

At returns the color at (x, y).

#### func (*Paletted) Bounds ¶

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

Bounds returns the bounds of the paletted image.

#### func (*Paletted) ColorIndexAt ¶

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

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

#### func (*Paletted) ColorModel ¶

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

ColorModel returns the color model of the paletted image.

#### func (*Paletted) ColorPalette ¶

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

ColorPalette returns the color palette of the paletted image.

#### func (*Paletted) GfxPalette ¶

`func (p *Paletted) GfxPalette() Palette`

GfxPalette returns the gfx palette of the paletted image.

#### func (*Paletted) Index ¶

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

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

#### func (*Paletted) NRGBAAt ¶

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

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

#### func (*Paletted) Opaque ¶

`func (p *Paletted) Opaque() bool`

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

#### func (*Paletted) PixOffset ¶

`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 ¶

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

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

#### func (*Paletted) Put ¶

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

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

#### func (*Paletted) Set ¶

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

Set changes the color at (x, y).

#### func (*Paletted) SetColorIndex ¶

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

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

#### func (*Paletted) SubImage ¶

`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 ¶

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

PalettedDrawImage interface is implemented by *Paletted

#### type PalettedImage ¶

```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 ¶

`type Palettes []Palette`

Palettes is a slice of Palette.

#### type Picture ¶

```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 ¶

```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 ¶

`type Points []image.Point`

Points are a list of points.

#### func (Points) Polygon ¶

`func (pts Points) Polygon() Polygon`

Polygon based on the points.

#### type Polygon ¶

`type Polygon []Vec`

Polygon is represented by a list of vectors.

#### func (Polygon) Bounds ¶

`func (p Polygon) Bounds() image.Rectangle`

Bounds return the bounds of the polygon rectangle.

#### func (Polygon) EachPixel ¶

`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 ¶

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

Fill polygon on the image with the given color.

#### func (Polygon) Outline ¶

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

Outline draws an outline of the polygon on dst.

#### func (Polygon) Project ¶

`func (p Polygon) Project(m Matrix) Polygon`

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

#### func (Polygon) Rect ¶

`func (p Polygon) Rect() Rect`

Rect is the polygon rectangle.

#### type Polyline ¶

`type Polyline []Polygon`

Polyline is a slice of polygons forming a line.

#### func NewPolyline ¶

`func NewPolyline(p Polygon, t float64) Polyline`

NewPolyline constructs a slice of line polygons.

#### type Range ¶

`type Range []float64`

Range of values.

#### func (Range) First ¶

`func (r Range) First() float64`

First value in the Range.

#### func (Range) Last ¶

`func (r Range) Last() float64`

Last value in the Range.

`type ReadFunc func(r io.Reader) error`

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

#### func DecodeJSONFunc ¶

`func DecodeJSONFunc(v interface{}) ReadFunc`

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

#### type Rect ¶

```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 ¶

`func BoundsToRect(ir image.Rectangle) Rect`

BoundsToRect converts an image.Rectangle to a Rect.

#### func NewRect ¶

`func NewRect(min, max Vec) Rect`

NewRect creates a new Rect.

#### func R ¶

`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 ¶

`func (r Rect) Area() float64`

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

#### func (Rect) Bounds ¶

`func (r Rect) Bounds() image.Rectangle`

Bounds returns the bounds of the rectangle.

#### func (Rect) Center ¶

`func (r Rect) Center() Vec`

Center returns the position of the center of the Rect.

#### func (Rect) CenterOrigin ¶

`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 ¶

`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 ¶

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

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

#### func (Rect) DrawColor ¶

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

DrawColor draws Rect with a uniform color on dst.

#### func (Rect) DrawColorOver ¶

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

DrawColorOver draws Rect with a uniform color over dst.

#### func (Rect) EachVec ¶

`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 ¶

`func (r Rect) H() float64`

H returns the height of the Rect.

#### func (Rect) Intersect ¶

`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 ¶

`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 ¶

`func (r Rect) Moved(delta Vec) Rect`

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

#### func (Rect) Norm ¶

`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 ¶

`func (r Rect) Overlaps(s Rect) bool`

Overlaps checks whether one Rect overlaps another Rect.

#### func (Rect) Resized ¶

`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 ¶

`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 ¶

`func (r Rect) Size() Vec`

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

#### func (Rect) String ¶

`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 ¶

`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 ¶

`func (r Rect) W() float64`

W returns the width of the Rect.

#### type SignedDistance ¶

```type SignedDistance struct {
Vec
}```

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

#### func (SignedDistance) Annular ¶

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

Annular signed distance function shape

#### func (SignedDistance) Circle ¶

`func (sd SignedDistance) Circle(r float64) float64`

Circle primitive

#### func (SignedDistance) CircleFunc ¶

`func (SignedDistance) CircleFunc(r float64) SignedDistanceFunc`

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

#### func (SignedDistance) EquilateralTriangle ¶

`func (sd SignedDistance) EquilateralTriangle(s float64) float64`

EquilateralTriangle primitive

#### func (SignedDistance) EquilateralTriangleFunc ¶

`func (SignedDistance) EquilateralTriangleFunc(s float64) SignedDistanceFunc`

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

#### func (SignedDistance) IsoscelesTriangle ¶

`func (sd SignedDistance) IsoscelesTriangle(q Vec) float64`

IsoscelesTriangle primitive

#### func (SignedDistance) IsoscelesTriangleFunc ¶

`func (SignedDistance) IsoscelesTriangleFunc(q Vec) SignedDistanceFunc`

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

#### func (SignedDistance) Line ¶

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

Line primitive

#### func (SignedDistance) LineFunc ¶

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

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

#### func (SignedDistance) OpIntersection ¶

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

OpIntersection basic boolean operation for intersection.

#### func (SignedDistance) OpMoved ¶

`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 ¶

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

OpRepeat repeats based on the given c vector.

#### func (SignedDistance) OpSmoothIntersection ¶

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

OpSmoothIntersection smooth operation for intersection.

#### func (SignedDistance) OpSmoothSubtraction ¶

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

OpSmoothSubtraction smooth operation for subtraction.

#### func (SignedDistance) OpSmoothUnion ¶

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

OpSmoothUnion smooth operation for union.

#### func (SignedDistance) OpSubtraction ¶

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

OpSubtraction basic boolean operation for subtraction.

#### func (SignedDistance) OpSymX ¶

`func (sd SignedDistance) OpSymX(sdf SignedDistanceFunc) float64`

OpSymX symmetry operation for X.

#### func (SignedDistance) OpSymXY ¶

`func (sd SignedDistance) OpSymXY(sdf SignedDistanceFunc) float64`

OpSymXY symmetry operation for X and Y.

#### func (SignedDistance) OpSymY ¶

`func (sd SignedDistance) OpSymY(sdf SignedDistanceFunc) float64`

OpSymY symmetry operation for Y.

#### func (SignedDistance) OpTx ¶

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

OpTx translates using the given matrix.

#### func (SignedDistance) OpUnion ¶

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

OpUnion basic boolean operation for union.

#### func (SignedDistance) Rectangle ¶

`func (sd SignedDistance) Rectangle(b Vec) float64`

Rectangle primitive

#### func (SignedDistance) RectangleFunc ¶

`func (SignedDistance) RectangleFunc(b Vec) SignedDistanceFunc`

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

#### func (SignedDistance) Rhombus ¶

`func (sd SignedDistance) Rhombus(b Vec) float64`

Rhombus primitive

#### func (SignedDistance) RhombusFunc ¶

`func (SignedDistance) RhombusFunc(b Vec) SignedDistanceFunc`

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

#### func (SignedDistance) Rounded ¶

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

Rounded signed distance function shape

#### type SignedDistanceFunc ¶

`type SignedDistanceFunc func(SignedDistance) float64`

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

#### type SimplexNoise ¶

```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 ¶

`func NewSimplexNoise(seed int64) *SimplexNoise`

NewSimplexNoise creates a new simplex noise instance with the given seed

#### func (*SimplexNoise) Noise2D ¶

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

Noise2D performs 2D simplex noise

#### func (*SimplexNoise) Noise3D ¶

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

Noise3D performs 3D simplex noise

#### func (*SimplexNoise) Noise4D ¶

`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 ¶

```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 ¶

```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 ¶

```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 ¶

`type Tiles []PalettedImage`

Tiles is a slice of paletted images.

#### type Tileset ¶

```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 ¶

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

GetTileset retrieves a remote tileset using GetPNG.

#### func NewTileset ¶

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

NewTileset creates a new paletted tileset.

#### func NewTilesetFromImage ¶

`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 ¶

`type TilesetData [][]uint8`

TilesetData is the raw data in a tileset

#### type Triangle ¶

`type Triangle [3]Vertex`

Triangle is an array of three vertexes

#### func NewTriangle ¶

`func NewTriangle(i int, td *TrianglesData) Triangle`

NewTriangle creates a new triangle.

#### func T ¶

`func T(a, b, c Vertex) Triangle`

T constructs a new triangle based on three vertexes.

Example
```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}
```

#### func (Triangle) Bounds ¶

`func (t Triangle) Bounds() image.Rectangle`

Bounds returns the bounds of the triangle.

#### func (Triangle) Centroid ¶

`func (t Triangle) Centroid() Vec`

Centroid returns the centroid O of the triangle.

#### func (Triangle) Color ¶

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

Color returns the color at vector u.

#### func (Triangle) Colors ¶

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

Colors returns the three colors.

#### func (Triangle) Contains ¶

`func (t Triangle) Contains(u Vec) bool`

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

#### func (Triangle) Draw ¶

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

Draw the triangle to dst.

#### func (Triangle) DrawColor ¶

`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 ¶

`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 ¶

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

DrawOver draws the first color in the triangle over dst.

#### func (Triangle) DrawWireframe ¶

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

DrawWireframe draws the triangle as a wireframe on dst.

#### func (Triangle) EachPixel ¶

`func (t Triangle) EachPixel(tf TriangleFunc)`

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

#### func (Triangle) Positions ¶

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

Positions returns the three positions.

#### func (Triangle) Rect ¶

`func (t Triangle) Rect() Rect`

Rect returns the triangle Rect.

#### type TriangleFunc ¶

`type TriangleFunc func(u Vec, t Triangle)`

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

#### type Triangles ¶

```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 ¶

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

TrianglesColor specifies Triangles with Color property.

#### type TrianglesData ¶

`type TrianglesData []Vertex`

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

#### func MakeTrianglesData ¶

`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 ¶

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

Color returns the color property of i-th vertex.

#### func (*TrianglesData) Copy ¶

`func (td *TrianglesData) Copy() Triangles`

Copy returns an exact independent copy of this Vertexes.

#### func (*TrianglesData) Len ¶

`func (td *TrianglesData) Len() int`

Len returns the number of vertices in Vertexes.

#### func (*TrianglesData) Picture ¶

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

Picture returns the picture property of i-th vertex.

#### func (*TrianglesData) Position ¶

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

Position returns the position property of i-th vertex.

#### func (*TrianglesData) SetLen ¶

`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 ¶

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

Slice returns a sub-Triangles of this TrianglesData.

#### func (*TrianglesData) Update ¶

`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 ¶

```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 ¶

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

TrianglesPosition specifies Triangles with Position property.

#### type Vec ¶

```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 ¶

`func BoundsCenter(ir image.Rectangle) Vec`

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

#### func Centroid ¶

`func Centroid(a, b, c Vec) Vec`

Centroid returns the centroid O of three vectors.

Example
```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 ¶

`func CubicBezierCurve(p0, p1, p2, p3 Vec, inc float64) []Vec`

CubicBezierCurve returns a slice of vectors representing a cubic bezier curve

#### func IV ¶

`func IV(x, y int) Vec`

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

#### func PV ¶

`func PV(p image.Point) Vec`

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

#### func Unit ¶

`func Unit(angle float64) Vec`

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

#### func V ¶

`func V(x, y float64) Vec`

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

#### func (Vec) Abs ¶

`func (u Vec) Abs() Vec`

Abs returns the absolute vector of the vector u.

`func (u Vec) Add(v Vec) Vec`

Add returns the sum of vectors u and v.

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

#### func (Vec) Angle ¶

`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 ¶

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

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

#### func (Vec) Bounds ¶

`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 ¶

`func (u Vec) Cross(v Vec) float64`

Cross return the cross product of vectors u and v.

#### func (Vec) Dot ¶

`func (u Vec) Dot(v Vec) float64`

Dot returns the dot product of vectors u and v.

#### func (Vec) Eq ¶

`func (u Vec) Eq(v Vec) bool`

Eq checks the equality of two vectors.

#### func (Vec) In ¶

`func (u Vec) In(p Polygon) bool`

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

#### func (Vec) Len ¶

`func (u Vec) Len() float64`

Len returns the length of the vector u.

#### func (Vec) Lerp ¶

`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 ¶

`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 ¶

`func (u Vec) Max(v Vec) Vec`

Max returns the maximum vector of u and v.

#### func (Vec) Min ¶

`func (u Vec) Min(v Vec) Vec`

Min returns the minimum vector of u and v.

#### func (Vec) Mod ¶

`func (u Vec) Mod(v Vec) Vec`

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

#### func (Vec) Normal ¶

`func (u Vec) Normal() Vec`

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

#### func (Vec) Project ¶

`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 ¶

`func (u Vec) Pt() image.Point`

Pt returns the image.Point for the vector.

#### func (Vec) R ¶

`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 ¶

`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 ¶

`func (u Vec) Rotated(angle float64) Vec`

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

#### func (Vec) Scaled ¶

`func (u Vec) Scaled(c float64) Vec`

Scaled returns the vector u multiplied by c.

#### func (Vec) ScaledXY ¶

`func (u Vec) ScaledXY(v Vec) Vec`

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

#### func (Vec) String ¶

`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 ¶

`func (u Vec) Sub(v Vec) Vec`

Sub returns the difference betweeen vectors u and v.

#### func (Vec) To ¶

`func (u Vec) To(v Vec) Vec`

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

#### func (Vec) Unit ¶

`func (u Vec) Unit() Vec`

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

#### func (Vec) Vec3 ¶

`func (u Vec) Vec3(z float64) Vec3`

Vec3 converts the vector into a Vec3.

#### func (Vec) XY ¶

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

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

#### type Vec3 ¶

```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 ¶

`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 ¶

`func IV3(x, y, z int) Vec3`

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

#### func V3 ¶

`func V3(x, y, z float64) Vec3`

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.

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

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

#### func (Vec3) Dist ¶

`func (u Vec3) Dist(v Vec3) float64`

Dist returns the euclidian distance between two vectors.

#### func (Vec3) Div ¶

`func (u Vec3) Div(s float64) Vec3`

Div returns the vector v/s.

#### func (Vec3) Dot ¶

`func (u Vec3) Dot(v Vec3) float64`

Dot returns the dot product of vectors u and v.

#### func (Vec3) Eq ¶

`func (u Vec3) Eq(v Vec3) bool`

Eq checks the equality of two vectors.

#### func (Vec3) Len ¶

`func (u Vec3) Len() float64`

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

#### func (Vec3) Lerp ¶

`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 ¶

`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 ¶

`func (u Vec3) Scaled(s float64) Vec3`

Scaled returns the vector u multiplied by c.

#### func (Vec3) ScaledXYZ ¶

`func (u Vec3) ScaledXYZ(v Vec3) Vec3`

ScaledXYZ returns the component-wise multiplication of two vectors.

#### func (Vec3) SqDist ¶

`func (u Vec3) SqDist(v Vec3) float64`

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

#### func (Vec3) SqLen ¶

`func (u Vec3) SqLen() float64`

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

#### func (Vec3) String ¶

`func (u Vec3) String() string`

String returns the string representation of the vector u.

#### func (Vec3) Sub ¶

`func (u Vec3) Sub(v Vec3) Vec3`

Sub returns the difference betweeen vectors u and v.

#### func (Vec3) Unit ¶

`func (u Vec3) Unit() Vec3`

Unit returns the normalized vector of a vector.

#### func (Vec3) Vec ¶

`func (u Vec3) Vec() Vec`

Vec returns a Vec with X, Y coordinates.

#### func (Vec3) XYZ ¶

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

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

#### type Vertex ¶

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

Vertex holds Position, Color, Picture and Intensity.

#### func NewVertex ¶

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

NewVertex returns a new vertex with the given position.

#### func Vx ¶

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

Vx returns a new vertex with the given coordinates.

Example
```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}
```

#### type XYZ ¶

```type XYZ struct {
X float64
Y float64
Z float64
}```

XYZ color space.

#### func ColorToXYZ ¶

`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 ¶

`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 ¶

`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 ¶

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

Path Synopsis
examples