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
Index ¶
- Constants
- Variables
- func Base64EncodedPNG(src image.Image) string
- func Base64ImgTag(src image.Image) string
- func Clamp(x, min, max float64) float64
- func CmplxCos(x complex128) complex128
- func CmplxCosh(x complex128) complex128
- func CmplxPhase(x complex128) float64
- func CmplxPow(x, y complex128) complex128
- func CmplxSin(x complex128) complex128
- func CmplxSinh(x complex128) complex128
- func CmplxSqrt(x complex128) complex128
- func CmplxTan(x complex128) complex128
- func CmplxTanh(x complex128) complex128
- func ColorGray(y uint8) color.Gray
- func ColorGray16(y uint16) color.Gray16
- func ColorNRGBA(r, g, b, a uint8) color.NRGBA
- func ColorRGBA(r, g, b, a uint8) color.RGBA
- func ColorWithAlpha(c color.Color, a uint8) color.NRGBA
- func CreateFile(fn string) (*os.File, error)
- func DecodeImage(r io.Reader) (image.Image, error)
- func DecodeImageBytes(b []byte) (image.Image, error)
- func DecodePNG(r io.Reader) (image.Image, error)
- func DecodePNGBytes(b []byte) (image.Image, error)
- func Draw(dst draw.Image, r image.Rectangle, src image.Image)
- func DrawCicleFast(dst draw.Image, u Vec, radius float64, c color.Color)
- func DrawCircle(dst draw.Image, u Vec, radius, thickness float64, c color.Color)
- func DrawCircleFilled(dst draw.Image, u Vec, radius float64, c color.Color)
- func DrawColor(dst draw.Image, r image.Rectangle, c color.Color)
- func DrawColorOver(dst draw.Image, r image.Rectangle, c color.Color)
- func DrawIntCircle(dst draw.Image, x0, y0, r int, c color.Color)
- func DrawIntFilledCircle(dst draw.Image, x0, y0, r int, c color.Color)
- func DrawIntFilledRectangle(dst draw.Image, x, y, w, h int, c color.Color)
- func DrawIntFilledTriangle(dst draw.Image, x0, y0, x1, y1, x2, y2 int, c color.Color)
- func DrawIntLine(dst draw.Image, x0, y0, x1, y1 int, c color.Color)
- func DrawIntRectangle(dst draw.Image, x, y, w, h int, c color.Color)
- func DrawIntTriangle(dst draw.Image, x0, y0, x1, y1, x2, y2 int, c color.Color)
- func DrawLine(dst draw.Image, from, to Vec, thickness float64, c color.Color)
- func DrawLineBresenham(dst draw.Image, from, to Vec, c color.Color)
- func DrawOver(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point)
- func DrawPalettedImage(dst PalettedDrawImage, r image.Rectangle, src PalettedImage)
- func DrawPalettedLayer(dst *Paletted, r image.Rectangle, src *Layer)
- func DrawPointCircle(dst draw.Image, p image.Point, radius, thickness float64, c color.Color)
- func DrawPolygon(dst draw.Image, p Polygon, thickness float64, c color.Color)
- func DrawPolyline(dst draw.Image, pl Polyline, thickness float64, c color.Color)
- func DrawSrc(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point)
- func DrawTriangles(dst draw.Image, triangles []Triangle)
- func DrawTrianglesOver(dst draw.Image, triangles []Triangle)
- func DrawTrianglesWireframe(dst draw.Image, triangles []Triangle)
- func Dump(a ...interface{})
- func EachImageVec(src image.Image, dir Vec, fn func(u Vec))
- func EachPixel(r image.Rectangle, fn func(x, y int))
- func EncodeJSON(w io.Writer, v interface{}, options ...func(*json.Encoder)) error
- func EncodePNG(w io.Writer, src image.Image) error
- func Errorf(format string, a ...interface{}) error
- func Fatal(v ...interface{})
- func Get(rawurl string) (*http.Response, error)
- func GetImage(rawurl string) (image.Image, error)
- func GetPNG(rawurl string) (image.Image, error)
- func IR(x0, y0, x1, y1 int) image.Rectangle
- func IntAbs(x int) int
- func IntClamp(x, min, max int) int
- func IntMax(x, y int) int
- func IntMin(x, y int) int
- func JSONIndent(prefix, indent string) func(*json.Encoder)
- func Lerp(a, b, t float64) float64
- func LerpColors(c0, c1 color.Color, t float64) color.Color
- func Log(format string, a ...interface{})
- func MathAbs(x float64) float64
- func MathAtan(x float64) float64
- func MathCeil(x float64) float64
- func MathCos(x float64) float64
- func MathCosh(x float64) float64
- func MathFloor(x float64) float64
- func MathHypot(p, q float64) float64
- func MathLog(x float64) float64
- func MathMax(x, y float64) float64
- func MathMin(x, y float64) float64
- func MathPow(x, y float64) float64
- func MathRound(x float64) float64
- func MathSin(x float64) float64
- func MathSinh(x float64) float64
- func MathSqrt(x float64) float64
- func MathTan(x float64) float64
- func Mix(m draw.Image, x, y int, c color.Color)
- func MixPoint(dst draw.Image, p image.Point, c color.Color)
- func MustOpenImage(fn string) image.Image
- func NewGray(r image.Rectangle) *image.Gray
- func NewGray16(r image.Rectangle) *image.Gray16
- func NewImage(w, h int, colors ...color.Color) *image.RGBA
- func NewJSONEncoder(w io.Writer, options ...func(*json.Encoder)) *json.Encoder
- func NewNRGBA(r image.Rectangle) *image.NRGBA
- func NewRGBA(r image.Rectangle) *image.RGBA
- func NewResizedImage(src image.Image, w, h int) image.Image
- func NewResizedRGBA(src image.Image, r image.Rectangle) *image.RGBA
- func NewScaledImage(src image.Image, s float64) image.Image
- func NewScaledRGBA(src image.Image, s float64) *image.RGBA
- func NewUniform(c color.Color) *image.Uniform
- func OpenFile(fn string) (*os.File, error)
- func OpenImage(fn string) (image.Image, error)
- func Playground(src image.Image)
- func Printf(format string, a ...interface{}) (n int, err error)
- func Pt(x, y int) image.Point
- func RandFloat64() float64
- func RandIntn(n int) int
- func RandSeed(seed int64)
- func ReadFile(fn string, rf ReadFunc) error
- func ReadJSON(fn string, v interface{}) error
- func ResizeImage(dst draw.Image, src image.Image)
- func SavePNG(fn string, src image.Image) error
- func Set(dst draw.Image, x, y int, c color.Color)
- func SetPoint(dst draw.Image, p image.Point, c color.Color)
- func SetVec(dst draw.Image, u Vec, c color.Color)
- func Sign(x float64) float64
- func SortSlice(slice interface{}, less func(i, j int) bool)
- func Sprintf(format string, a ...interface{}) string
- type Animation
- type BasicTarget
- type Batch
- type Block
- func (b Block) Behind(a Block) bool
- func (b Block) Box() Box
- func (b Block) Corners(origin Vec3) BlockCorners
- func (b Block) Draw(dst draw.Image, origin Vec3)
- func (b Block) DrawBounds(dst draw.Image, origin Vec3)
- func (b Block) DrawOver(dst draw.Image, origin Vec3)
- func (b Block) DrawPolygons(dst draw.Image, origin Vec3)
- func (b Block) DrawRectangles(dst draw.Image, origin Vec3)
- func (b Block) DrawWireframe(dst draw.Image, origin Vec3)
- func (b Block) Polygons(origin Vec3) (shape, top, left, right Polygon)
- func (b Block) Rect(origin Vec3) Rect
- func (b Block) Shape(origin Vec3) Polygon
- func (b Block) Space() BlockSpace
- func (b Block) Triangles(origin Vec3) []Triangle
- func (b Block) TrianglesData(origin Vec3) *TrianglesData
- type BlockColor
- type BlockCorners
- type BlockSpace
- func (bs BlockSpace) CornerBackDown(origin Vec3) Vec
- func (bs BlockSpace) CornerBackUp(origin Vec3) Vec
- func (bs BlockSpace) CornerFrontDown(origin Vec3) Vec
- func (bs BlockSpace) CornerFrontUp(origin Vec3) Vec
- func (bs BlockSpace) CornerLeftDown(origin Vec3) Vec
- func (bs BlockSpace) CornerLeftUp(origin Vec3) Vec
- func (bs BlockSpace) CornerRightDown(origin Vec3) Vec
- func (bs BlockSpace) CornerRightUp(origin Vec3) Vec
- func (bs BlockSpace) Corners(origin Vec3) BlockCorners
- type Blocks
- func (blocks *Blocks) Add(bs ...Block)
- func (blocks *Blocks) AddNewBlock(pos, size Vec3, ic BlockColor)
- func (blocks Blocks) Draw(dst draw.Image, origin Vec3)
- func (blocks Blocks) DrawBounds(dst draw.Image, origin Vec3)
- func (blocks Blocks) DrawPolygons(dst draw.Image, origin Vec3)
- func (blocks Blocks) DrawRectangles(dst draw.Image, origin Vec3)
- func (blocks Blocks) DrawWireframes(dst draw.Image, origin Vec3)
- func (blocks Blocks) Sort()
- type Box
- type CIELab
- type Circle
- func (c Circle) Area() float64
- func (c Circle) Contains(u Vec) bool
- func (c Circle) Intersect(d Circle) Circle
- func (c Circle) IntersectRect(r Rect) Vec
- func (c Circle) Moved(delta Vec) Circle
- func (c Circle) Norm() Circle
- func (c Circle) Resized(radiusDelta float64) Circle
- func (c Circle) String() string
- func (c Circle) Union(d Circle) Circle
- type Degrees
- type Domain
- type DrawTarget
- func (dt *DrawTarget) At(x, y int) color.Color
- func (dt *DrawTarget) Bounds() image.Rectangle
- func (dt *DrawTarget) Center() Vec
- func (dt *DrawTarget) ColorModel() color.Model
- func (dt *DrawTarget) MakePicture(pic Picture) TargetPicture
- func (dt *DrawTarget) MakeTriangles(t Triangles) TargetTriangles
- func (dt *DrawTarget) Set(x, y int, c color.Color)
- func (dt *DrawTarget) SetMatrix(mat Matrix)
- type Drawer
- type EndShape
- type Error
- type Float64Scaler
- type GeoPoint
- type GeoTile
- func (gt GeoTile) AddXY(x, y int) GeoTile
- func (gt GeoTile) Bounds(dst image.Image, gp GeoPoint, tileSize int) image.Rectangle
- func (gt GeoTile) Draw(dst draw.Image, gp GeoPoint, src image.Image)
- func (gt GeoTile) E() GeoTile
- func (gt GeoTile) GeoPoint() GeoPoint
- func (gt GeoTile) GetImage(format string) (image.Image, error)
- func (gt GeoTile) N() GeoTile
- func (gt GeoTile) NE() GeoTile
- func (gt GeoTile) NW() GeoTile
- func (gt GeoTile) Neighbors() GeoTiles
- func (gt GeoTile) Rawurl(format string) string
- func (gt GeoTile) S() GeoTile
- func (gt GeoTile) SE() GeoTile
- func (gt GeoTile) SW() GeoTile
- func (gt GeoTile) Vec(gp GeoPoint, tileSize int) Vec
- func (gt GeoTile) W() GeoTile
- type GeoTileServer
- func (gts GeoTileServer) DrawNeighbors(dst draw.Image, gt GeoTile, gp GeoPoint) error
- func (gts GeoTileServer) DrawTile(dst draw.Image, gt GeoTile, gp GeoPoint) error
- func (gts GeoTileServer) DrawTileAndNeighbors(dst draw.Image, gt GeoTile, gp GeoPoint) error
- func (gts GeoTileServer) GetImage(gt GeoTile) (image.Image, error)
- type GeoTiles
- type HSL
- type HSV
- type HTTP
- type HunterLab
- type IMDraw
- func (imd *IMDraw) Circle(radius, thickness float64)
- func (imd *IMDraw) CircleArc(radius, low, high, thickness float64)
- func (imd *IMDraw) Clear()
- func (imd *IMDraw) Draw(t Target)
- func (imd *IMDraw) Ellipse(radius Vec, thickness float64)
- func (imd *IMDraw) EllipseArc(radius Vec, low, high, thickness float64)
- func (imd *IMDraw) Line(thickness float64)
- func (imd *IMDraw) MakePicture(p Picture) TargetPicture
- func (imd *IMDraw) MakeTriangles(t Triangles) TargetTriangles
- func (imd *IMDraw) Polygon(thickness float64)
- func (imd *IMDraw) Push(pts ...Vec)
- func (imd *IMDraw) Rectangle(thickness float64)
- func (imd *IMDraw) Reset()
- func (imd *IMDraw) SetMatrix(m Matrix)
- type Layer
- func (l *Layer) AlphaAt(x, y int) uint8
- func (l *Layer) At(x, y int) color.Color
- func (l *Layer) Bounds() image.Rectangle
- func (l *Layer) ColorIndexAt(x, y int) uint8
- func (l *Layer) ColorModel() color.Model
- func (l *Layer) ColorPalette() color.Palette
- func (l *Layer) DataAt(dx, dy int) int
- func (l *Layer) GfxPalette() Palette
- func (l *Layer) Index(x, y int) int
- func (l *Layer) NRGBAAt(x, y int) color.NRGBA
- func (l *Layer) Put(dx, dy, index int)
- func (l *Layer) SetTileIndex(dx, dy, index int)
- func (l *Layer) TileAt(x, y int) image.PalettedImage
- func (l *Layer) TileIndexAt(x, y int) int
- func (l *Layer) TileSize() image.Point
- type LayerData
- type LinearScaler
- type Matrix
- func (m Matrix) Chained(next Matrix) Matrix
- func (m Matrix) Moved(delta Vec) Matrix
- func (m Matrix) Project(u Vec) Vec
- func (m Matrix) Rotated(around Vec, angle float64) Matrix
- func (m Matrix) RotatedDegrees(around Vec, degrees float64) Matrix
- func (m Matrix) Scaled(around Vec, scale float64) Matrix
- func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix
- func (m Matrix) String() string
- func (m Matrix) Unproject(u Vec) Vec
- type Palette
- func (p Palette) AsColorPalette() color.Palette
- func (p Palette) At(t float64) color.Color
- func (p Palette) CmplxPhaseAt(z complex128) color.Color
- func (p Palette) Color(n int) color.NRGBA
- func (p Palette) Convert(c color.Color) color.Color
- func (p Palette) Index(c color.Color) int
- func (p Palette) Len() int
- func (p Palette) Random() color.NRGBA
- func (p Palette) Sort(less func(i, j int) bool)
- func (p Palette) SortByHue()
- func (p Palette) Tile(src image.Image) *Paletted
- type PaletteLookup
- type PaletteName
- type Paletted
- func NewPaletted(w, h int, p Palette, colors ...color.Color) *Paletted
- func NewPalettedImage(r image.Rectangle, p Palette) *Paletted
- func NewResizedPalettedImage(src PalettedImage, w, h int) *Paletted
- func NewScaledPalettedImage(src PalettedImage, s float64) *Paletted
- func NewTile(p Palette, cols int, pix []uint8) *Paletted
- func (p *Paletted) AlphaAt(x, y int) uint8
- func (p *Paletted) At(x, y int) color.Color
- func (p *Paletted) Bounds() image.Rectangle
- func (p *Paletted) ColorIndexAt(x, y int) uint8
- func (p *Paletted) ColorModel() color.Model
- func (p *Paletted) ColorPalette() color.Palette
- func (p *Paletted) GfxPalette() Palette
- func (p *Paletted) Index(x, y int) uint8
- func (p *Paletted) NRGBAAt(x, y int) color.NRGBA
- func (p *Paletted) Opaque() bool
- func (p *Paletted) PixOffset(x, y int) int
- func (p *Paletted) Pixels() []uint8
- func (p *Paletted) Put(x, y int, index uint8)
- func (p *Paletted) Set(x, y int, c color.Color)
- func (p *Paletted) SetColorIndex(x, y int, index uint8)
- func (p *Paletted) SubImage(r image.Rectangle) image.Image
- type PalettedDrawImage
- type PalettedImage
- type Palettes
- type Picture
- type PictureColor
- type Points
- type Polygon
- func (p Polygon) Bounds() image.Rectangle
- func (p Polygon) EachPixel(m image.Image, fn func(x, y int))
- func (p Polygon) Fill(dst draw.Image, c color.Color) (drawCount int)
- func (p Polygon) Outline(dst draw.Image, thickness float64, c color.Color)
- func (p Polygon) Project(m Matrix) Polygon
- func (p Polygon) Rect() Rect
- type Polyline
- type Range
- type ReadFunc
- type Rect
- func (r Rect) Area() float64
- func (r Rect) Bounds() image.Rectangle
- func (r Rect) Center() Vec
- func (r Rect) CenterOrigin(v Vec, z float64) Vec3
- func (r Rect) Contains(u Vec) bool
- func (r Rect) Draw(dst draw.Image, src image.Image)
- func (r Rect) DrawColor(dst draw.Image, c color.Color)
- func (r Rect) DrawColorOver(dst draw.Image, c color.Color)
- func (r Rect) EachVec(dir Vec, fn func(p Vec))
- func (r Rect) H() float64
- func (r Rect) Intersect(s Rect) Rect
- func (r Rect) IntersectCircle(c Circle) Vec
- func (r Rect) Moved(delta Vec) Rect
- func (r Rect) Norm() Rect
- func (r Rect) Overlaps(s Rect) bool
- func (r Rect) Resized(anchor, size Vec) Rect
- func (r Rect) ResizedMin(size Vec) Rect
- func (r Rect) Size() Vec
- func (r Rect) String() string
- func (r Rect) Union(s Rect) Rect
- func (r Rect) W() float64
- type SignedDistance
- func (sd SignedDistance) Annular(v, r float64) float64
- func (sd SignedDistance) Circle(r float64) float64
- func (SignedDistance) CircleFunc(r float64) SignedDistanceFunc
- func (sd SignedDistance) EquilateralTriangle(s float64) float64
- func (SignedDistance) EquilateralTriangleFunc(s float64) SignedDistanceFunc
- func (sd SignedDistance) IsoscelesTriangle(q Vec) float64
- func (SignedDistance) IsoscelesTriangleFunc(q Vec) SignedDistanceFunc
- func (sd SignedDistance) Line(a, b Vec) float64
- func (SignedDistance) LineFunc(a, b Vec) SignedDistanceFunc
- func (sd SignedDistance) OpIntersection(x, y float64) float64
- func (sd SignedDistance) OpMoved(d Vec, sdf SignedDistanceFunc) float64
- func (sd SignedDistance) OpRepeat(c Vec, sdf SignedDistanceFunc) float64
- func (sd SignedDistance) OpSmoothIntersection(x, y, k float64) float64
- func (sd SignedDistance) OpSmoothSubtraction(x, y, k float64) float64
- func (sd SignedDistance) OpSmoothUnion(x, y, k float64) float64
- func (sd SignedDistance) OpSubtraction(x, y float64) float64
- func (sd SignedDistance) OpSymX(sdf SignedDistanceFunc) float64
- func (sd SignedDistance) OpSymXY(sdf SignedDistanceFunc) float64
- func (sd SignedDistance) OpSymY(sdf SignedDistanceFunc) float64
- func (sd SignedDistance) OpTx(t Matrix, sdf SignedDistanceFunc) float64
- func (sd SignedDistance) OpUnion(x, y float64) float64
- func (sd SignedDistance) Rectangle(b Vec) float64
- func (SignedDistance) RectangleFunc(b Vec) SignedDistanceFunc
- func (sd SignedDistance) Rhombus(b Vec) float64
- func (SignedDistance) RhombusFunc(b Vec) SignedDistanceFunc
- func (sd SignedDistance) Rounded(v, r float64) float64
- type SignedDistanceFunc
- type SimplexNoise
- type Target
- type TargetPicture
- type TargetTriangles
- type Tiles
- type Tileset
- type TilesetData
- type Triangle
- func (t Triangle) Bounds() image.Rectangle
- func (t Triangle) Centroid() Vec
- func (t Triangle) Color(u Vec) color.Color
- func (t Triangle) Colors() (color.NRGBA, color.NRGBA, color.NRGBA)
- func (t Triangle) Contains(u Vec) bool
- func (t Triangle) Draw(dst draw.Image) (drawCount int)
- func (t Triangle) DrawColor(dst draw.Image, c color.Color) (drawCount int)
- func (t Triangle) DrawColorOver(dst draw.Image, c color.Color) (drawCount int)
- func (t Triangle) DrawOver(dst draw.Image) (drawCount int)
- func (t Triangle) DrawWireframe(dst draw.Image, c color.Color) (drawCount int)
- func (t Triangle) EachPixel(tf TriangleFunc)
- func (t Triangle) Positions() (Vec, Vec, Vec)
- func (t Triangle) Rect() Rect
- type TriangleFunc
- type Triangles
- type TrianglesColor
- type TrianglesData
- func (td *TrianglesData) Color(i int) color.NRGBA
- func (td *TrianglesData) Copy() Triangles
- func (td *TrianglesData) Len() int
- func (td *TrianglesData) Picture(i int) (pic Vec, intensity float64)
- func (td *TrianglesData) Position(i int) Vec
- func (td *TrianglesData) SetLen(length int)
- func (td *TrianglesData) Slice(i, j int) Triangles
- func (td *TrianglesData) Update(t Triangles)
- type TrianglesPicture
- type TrianglesPosition
- type Vec
- func (u Vec) Abs() Vec
- func (u Vec) Add(v Vec) Vec
- func (u Vec) AddXY(x, y float64) Vec
- func (u Vec) Angle() float64
- func (u Vec) B(v Vec) image.Rectangle
- func (u Vec) Bounds(l, t, r, b float64) image.Rectangle
- func (u Vec) Cross(v Vec) float64
- func (u Vec) Dot(v Vec) float64
- func (u Vec) Eq(v Vec) bool
- func (u Vec) In(p Polygon) bool
- func (u Vec) Len() float64
- func (u Vec) Lerp(v Vec, t float64) Vec
- func (u Vec) Map(f func(float64) float64) Vec
- func (u Vec) Max(v Vec) Vec
- func (u Vec) Min(v Vec) Vec
- func (u Vec) Mod(v Vec) Vec
- func (u Vec) Normal() Vec
- func (u Vec) Project(v Vec) Vec
- func (u Vec) Pt() image.Point
- func (u Vec) R(v Vec) Rect
- func (u Vec) Rect(l, t, r, b float64) Rect
- func (u Vec) Rotated(angle float64) Vec
- func (u Vec) Scaled(c float64) Vec
- func (u Vec) ScaledXY(v Vec) Vec
- func (u Vec) String() string
- func (u Vec) Sub(v Vec) Vec
- func (u Vec) To(v Vec) Vec
- func (u Vec) Unit() Vec
- func (u Vec) Vec3(z float64) Vec3
- func (u Vec) XY() (x, y float64)
- type Vec3
- func (u Vec3) Add(v Vec3) Vec3
- func (u Vec3) AddXYZ(x, y, z float64) Vec3
- func (u Vec3) Dist(v Vec3) float64
- func (u Vec3) Div(s float64) Vec3
- func (u Vec3) Dot(v Vec3) float64
- func (u Vec3) Eq(v Vec3) bool
- func (u Vec3) Len() float64
- func (u Vec3) Lerp(v Vec3, t float64) Vec3
- func (u Vec3) Map(f func(float64) float64) Vec3
- func (u Vec3) Scaled(s float64) Vec3
- func (u Vec3) ScaledXYZ(v Vec3) Vec3
- func (u Vec3) SqDist(v Vec3) float64
- func (u Vec3) SqLen() float64
- func (u Vec3) String() string
- func (u Vec3) Sub(v Vec3) Vec3
- func (u Vec3) Unit() Vec3
- func (u Vec3) Vec() Vec
- func (u Vec3) XYZ() (x, y, z float64)
- type Vertex
- type XYZ
- type XYZReference
Examples ¶
- Centroid
- Clamp
- CmplxCos
- CmplxCosh
- CmplxPhase
- CmplxPow
- CmplxSin
- CmplxSinh
- CmplxSqrt
- CmplxTan
- CmplxTanh
- DrawCircle (Annular)
- DrawCircle (Filled)
- DrawLineBresenham
- DrawLineBresenham (Steep)
- Dump
- Errorf
- IntAbs
- IntMax
- IntMin
- Lerp
- Log
- MathAbs
- MathCeil
- MathCos
- MathFloor
- MathHypot
- MathMax
- MathMin
- MathSin
- MathSqrt
- NewScaledImage
- Printf
- Sign
- T
- Vx
Constants ¶
const (
Pi = 3.14159265358979323846264338327950288419716939937510582097494459 // https://oeis.org/A000796
)
Mathematical constants.
Variables ¶
var ( ColorTransparent = ColorNRGBA(0, 0, 0, 0) ColorOpaque = ColorNRGBA(0xFF, 0xFF, 0xFF, 0xFF) ColorBlack = Palette1Bit.Color(0) ColorWhite = Palette1Bit.Color(1) ColorRed = Palette3Bit.Color(1) ColorGreen = Palette3Bit.Color(2) ColorBlue = Palette3Bit.Color(3) ColorCyan = Palette3Bit.Color(4) ColorMagenta = Palette3Bit.Color(5) ColorYellow = Palette3Bit.Color(6) // ColorByName is a map of all the default colors by name. ColorByName = map[string]color.NRGBA{ "Transparent": ColorTransparent, "Opaque": ColorOpaque, "Black": ColorBlack, "White": ColorWhite, "Red": ColorRed, "Green": ColorGreen, "Blue": ColorBlue, "Cyan": ColorCyan, "Magenta": ColorMagenta, "Yellow": ColorYellow, } )
Standard colors transparent, opaque, black, white, red, green, blue, cyan, magenta, and yellow.
var ( // Default block colors based on PaletteTango. BlockColorYellow = BlockColor{Light: PaletteTango[0], Medium: PaletteTango[1], Dark: PaletteTango[2]} BlockColorOrange = BlockColor{Light: PaletteTango[3], Medium: PaletteTango[4], Dark: PaletteTango[5]} BlockColorBrown = BlockColor{Light: PaletteTango[6], Medium: PaletteTango[7], Dark: PaletteTango[8]} BlockColorGreen = BlockColor{Light: PaletteTango[9], Medium: PaletteTango[10], Dark: PaletteTango[11]} BlockColorBlue = BlockColor{Light: PaletteTango[12], Medium: PaletteTango[13], Dark: PaletteTango[14]} BlockColorPurple = BlockColor{Light: PaletteTango[15], Medium: PaletteTango[16], Dark: PaletteTango[17]} BlockColorRed = BlockColor{Light: PaletteTango[18], Medium: PaletteTango[19], Dark: PaletteTango[20]} BlockColorWhite = BlockColor{Light: PaletteTango[21], Medium: PaletteTango[22], Dark: PaletteTango[23]} BlockColorBlack = BlockColor{Light: PaletteTango[24], Medium: PaletteTango[25], Dark: PaletteTango[26]} // BlockColors is a slice of the default block colors. BlockColors = []BlockColor{ BlockColorYellow, BlockColorOrange, BlockColorBrown, BlockColorGreen, BlockColorBlue, BlockColorPurple, BlockColorRed, BlockColorWhite, BlockColorBlack, } // Block colors based on the Go color palette. BlockColorGoGopherBlue = BlockColor{Dark: PaletteGo[0], Medium: PaletteGo[2], Light: PaletteGo[4]} BlockColorGoLightBlue = BlockColor{Dark: PaletteGo[9], Medium: PaletteGo[11], Light: PaletteGo[13]} BlockColorGoAqua = BlockColor{Dark: PaletteGo[18], Medium: PaletteGo[20], Light: PaletteGo[22]} BlockColorGoFuchsia = BlockColor{Dark: PaletteGo[27], Medium: PaletteGo[29], Light: PaletteGo[31]} BlockColorGoBlack = BlockColor{Dark: PaletteGo[36], Medium: PaletteGo[38], Light: PaletteGo[40]} BlockColorGoYellow = BlockColor{Dark: PaletteGo[45], Medium: PaletteGo[47], Light: PaletteGo[49]} // BlockColorsGo is a slice of block colors based on the Go color palette. BlockColorsGo = []BlockColor{ BlockColorGoGopherBlue, BlockColorGoLightBlue, BlockColorGoAqua, BlockColorGoFuchsia, BlockColorGoBlack, BlockColorGoYellow, } // BlockColorByName is a map of block colors by name. BlockColorByName = map[string]BlockColor{ "Yellow": BlockColorYellow, "Orange": BlockColorOrange, "Brown": BlockColorBrown, "Green": BlockColorGreen, "Blue": BlockColorBlue, "Purple": BlockColorPurple, "Red": BlockColorRed, "White": BlockColorWhite, "Black": BlockColorBlack, "GoGopherBlue": BlockColorGoGopherBlue, "GoLightBlue": BlockColorGoLightBlue, "GoAqua": BlockColorGoAqua, "GoFuchsia": BlockColorGoFuchsia, "GoBlack": BlockColorGoBlack, "GoYellow": BlockColorGoYellow, } )
Block colors, each containing a Light, Medium and Dark color.
var ( Stdout = os.Stdout Stderr = os.Stderr )
Stdout, and Stderr are open Files pointing to the standard output, and standard error file descriptors.
var ( // XYZReference2 for CIE 1931 2° Standard Observer XYZReference2 = XYZReference{ A: XYZ{109.850, 100.000, 35.585}, B: XYZ{99.0927, 100.000, 85.313}, C: XYZ{98.074, 100.000, 118.232}, D50: XYZ{96.422, 100.000, 82.521}, D55: XYZ{95.682, 100.000, 92.149}, D65: XYZ{95.047, 100.000, 108.883}, D75: XYZ{94.972, 100.000, 122.638}, E: XYZ{100.000, 100.000, 100.000}, F1: XYZ{92.834, 100.000, 103.665}, F2: XYZ{99.187, 100.000, 67.395}, F3: XYZ{103.754, 100.000, 49.861}, F4: XYZ{109.147, 100.000, 38.813}, F5: XYZ{90.872, 100.000, 98.723}, F6: XYZ{97.309, 100.000, 60.191}, F7: XYZ{95.044, 100.000, 108.755}, F8: XYZ{96.413, 100.000, 82.333}, F9: XYZ{100.365, 100.000, 67.868}, F10: XYZ{96.174, 100.000, 81.712}, F11: XYZ{100.966, 100.000, 64.370}, F12: XYZ{108.046, 100.000, 39.228}, } // XYZReference10 for CIE 1964 10° Standard Observer XYZReference10 = XYZReference{ A: XYZ{111.144, 100.000, 35.200}, B: XYZ{99.178, 100.000, 84.3493}, C: XYZ{97.285, 100.000, 116.145}, D50: XYZ{96.720, 100.000, 81.427}, D55: XYZ{95.799, 100.000, 90.926}, D65: XYZ{94.811, 100.000, 107.304}, D75: XYZ{94.416, 100.000, 120.641}, E: XYZ{100.000, 100.000, 100.000}, F1: XYZ{94.791, 100.000, 103.191}, F2: XYZ{103.280, 100.000, 69.026}, F3: XYZ{108.968, 100.000, 51.965}, F4: XYZ{114.961, 100.000, 40.963}, F5: XYZ{93.369, 100.000, 98.636}, F6: XYZ{102.148, 100.000, 62.074}, F7: XYZ{95.792, 100.000, 107.687}, F8: XYZ{97.115, 100.000, 81.135}, F9: XYZ{102.116, 100.000, 67.826}, F10: XYZ{99.001, 100.000, 83.134}, F11: XYZ{103.866, 100.000, 65.627}, F12: XYZ{111.428, 100.000, 40.353}, } )
var DefaultAnimationDelay = 50
DefaultAnimationDelay is the default animation delay, in 100ths of a second.
var ErrDone = Error("done")
ErrDone can for example be returned when you are done rendering.
var HTTPClient = HTTP{ Client: &http.Client{ Timeout: 30 * time.Second, }, UserAgent: "gfx.HTTPClient", }
HTTPClient is the default client used by Get/GetPNG/GetTileset, etc.
var IM = Matrix{1, 0, 0, 1, 0, 0}
IM stands for identity matrix. Does nothing, no transformation.
var Palette15PDX = Palette{
{0x6E, 0x32, 0x32, 0xFF},
{0xBB, 0x57, 0x35, 0xFF},
{0xDF, 0x92, 0x45, 0xFF},
{0xEC, 0xD2, 0x74, 0xFF},
{0x83, 0xA8, 0x16, 0xFF},
{0x27, 0x72, 0x24, 0xFF},
{0x17, 0x3B, 0x47, 0xFF},
{0x04, 0x68, 0x94, 0xFF},
{0x17, 0xA1, 0xA9, 0xFF},
{0x81, 0xDB, 0xCD, 0xFF},
{0xFD, 0xF9, 0xF1, 0xFF},
{0xC7, 0xB2, 0x95, 0xFF},
{0x87, 0x71, 0x5B, 0xFF},
{0x46, 0x3F, 0x3C, 0xFF},
{0x20, 0x17, 0x08, 0xFF},
}
Palette15PDX is the 15P DX palette.
Palette created by GrafxKid.
https://lospec.com/palette-list/15p-dx
var Palette1Bit = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
}
Palette1Bit is a basic 1-bit (black and white) palette.
var Palette20PDX = Palette{
{0x17, 0x0D, 0x20, 0xFF},
{0x47, 0x47, 0x57, 0xFF},
{0x78, 0x78, 0x76, 0xFF},
{0xB1, 0xB9, 0xA6, 0xFF},
{0xEB, 0xFF, 0xDA, 0xFF},
{0x68, 0x29, 0x3E, 0xFF},
{0xA9, 0x44, 0x00, 0xFF},
{0xD9, 0x7E, 0x00, 0xFF},
{0xEB, 0xD0, 0x00, 0xFF},
{0x52, 0x3C, 0x14, 0xFF},
{0x81, 0x60, 0x31, 0xFF},
{0xBC, 0x8B, 0x57, 0xFF},
{0xEB, 0xCD, 0x93, 0xFF},
{0x0E, 0x4C, 0x58, 0xFF},
{0x04, 0x6E, 0x92, 0xFF},
{0x01, 0xA3, 0xC3, 0xFF},
{0x55, 0xDE, 0xB7, 0xFF},
{0x17, 0x79, 0x47, 0xFF},
{0x5A, 0xB2, 0x17, 0xFF},
{0xB1, 0xE3, 0x29, 0xFF},
}
Palette20PDX is the 20P DX palette.
Palette created by GrafxKid.
https://lospec.com/palette-list/20p-dx
var Palette2BitGrayScale = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0x67, 0x67, 0x67, 0xFF},
{0xB6, 0xB6, 0xB6, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
}
Palette2BitGrayScale is a grayscale palette calculated using 2-bits per color.
It was used by the original gameboy and a few other computer systems.
https://lospec.com/palette-list/2-bit-grayscale
var Palette3Bit = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0xFF, 0x00, 0x00, 0xFF},
{0x00, 0xFF, 0x00, 0xFF},
{0x00, 0x00, 0xFF, 0xFF},
{0x00, 0xFF, 0xFF, 0xFF},
{0xFF, 0x00, 0xFF, 0xFF},
{0xFF, 0xFF, 0x00, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
}
Palette3Bit is the 3-Bit palette.
A calculated palette using 1 bit for each RGB value. It was used by a number of early computers.
var PaletteAAP16 = Palette{
{0x07, 0x07, 0x08, 0xFF},
{0x33, 0x22, 0x22, 0xFF},
{0x77, 0x44, 0x33, 0xFF},
{0xCC, 0x88, 0x55, 0xFF},
{0x99, 0x33, 0x11, 0xFF},
{0xDD, 0x77, 0x11, 0xFF},
{0xFF, 0xDD, 0x55, 0xFF},
{0xFF, 0xFF, 0x33, 0xFF},
{0x55, 0xAA, 0x44, 0xFF},
{0x11, 0x55, 0x22, 0xFF},
{0x44, 0xEE, 0xBB, 0xFF},
{0x33, 0x88, 0xDD, 0xFF},
{0x55, 0x44, 0xAA, 0xFF},
{0x55, 0x55, 0x77, 0xFF},
{0xAA, 0xBB, 0xBB, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
}
PaletteAAP16 is the AAP-16 palette.
Created by Adigun Polack, meant for beginners.
https://lospec.com/palette-list/aap-16
var PaletteAAP64 = Palette{
{0x06, 0x06, 0x08, 0xFF},
{0x14, 0x10, 0x13, 0xFF},
{0x3B, 0x17, 0x25, 0xFF},
{0x73, 0x17, 0x2D, 0xFF},
{0xB4, 0x20, 0x2A, 0xFF},
{0xDF, 0x3E, 0x23, 0xFF},
{0xFA, 0x6A, 0x0A, 0xFF},
{0xF9, 0xA3, 0x1B, 0xFF},
{0xFF, 0xD5, 0x41, 0xFF},
{0xFF, 0xFC, 0x40, 0xFF},
{0xD6, 0xF2, 0x64, 0xFF},
{0x9C, 0xDB, 0x43, 0xFF},
{0x59, 0xC1, 0x35, 0xFF},
{0x14, 0xA0, 0x2E, 0xFF},
{0x1A, 0x7A, 0x3E, 0xFF},
{0x24, 0x52, 0x3B, 0xFF},
{0x12, 0x20, 0x20, 0xFF},
{0x14, 0x34, 0x64, 0xFF},
{0x28, 0x5C, 0xC4, 0xFF},
{0x24, 0x9F, 0xDE, 0xFF},
{0x20, 0xD6, 0xC7, 0xFF},
{0xA6, 0xFC, 0xDB, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0xFE, 0xF3, 0xC0, 0xFF},
{0xFA, 0xD6, 0xB8, 0xFF},
{0xF5, 0xA0, 0x97, 0xFF},
{0xE8, 0x6A, 0x73, 0xFF},
{0xBC, 0x4A, 0x9B, 0xFF},
{0x79, 0x3A, 0x80, 0xFF},
{0x40, 0x33, 0x53, 0xFF},
{0x24, 0x22, 0x34, 0xFF},
{0x22, 0x1C, 0x1A, 0xFF},
{0x32, 0x2B, 0x28, 0xFF},
{0x71, 0x41, 0x3B, 0xFF},
{0xBB, 0x75, 0x47, 0xFF},
{0xDB, 0xA4, 0x63, 0xFF},
{0xF4, 0xD2, 0x9C, 0xFF},
{0xDA, 0xE0, 0xEA, 0xFF},
{0xB3, 0xB9, 0xD1, 0xFF},
{0x8B, 0x93, 0xAF, 0xFF},
{0x6D, 0x75, 0x8D, 0xFF},
{0x4A, 0x54, 0x62, 0xFF},
{0x33, 0x39, 0x41, 0xFF},
{0x42, 0x24, 0x33, 0xFF},
{0x5B, 0x31, 0x38, 0xFF},
{0x8E, 0x52, 0x52, 0xFF},
{0xBA, 0x75, 0x6A, 0xFF},
{0xE9, 0xB5, 0xA3, 0xFF},
{0xE3, 0xE6, 0xFF, 0xFF},
{0xB9, 0xBF, 0xFB, 0xFF},
{0x84, 0x9B, 0xE4, 0xFF},
{0x58, 0x8D, 0xBE, 0xFF},
{0x47, 0x7D, 0x85, 0xFF},
{0x23, 0x67, 0x4E, 0xFF},
{0x32, 0x84, 0x64, 0xFF},
{0x5D, 0xAF, 0x8D, 0xFF},
{0x92, 0xDC, 0xBA, 0xFF},
{0xCD, 0xF7, 0xE2, 0xFF},
{0xE4, 0xD2, 0xAA, 0xFF},
{0xC7, 0xB0, 0x8B, 0xFF},
{0xA0, 0x86, 0x62, 0xFF},
{0x79, 0x67, 0x55, 0xFF},
{0x5A, 0x4E, 0x44, 0xFF},
{0x42, 0x39, 0x34, 0xFF},
}
PaletteAAP64 is the AAP-64 palette.
Created by Adigun Polack.
https://lospec.com/palette-list/aap-16
var PaletteARQ4 = Palette{
{0xFF, 0xFF, 0xFF, 0xFF},
{0x67, 0x72, 0xA9, 0xFF},
{0x3A, 0x32, 0x77, 0xFF},
{0x00, 0x00, 0x00, 0xFF},
}
PaletteARQ4 is the ARQ4 palette.
Created by Endesga. #ARQ4
https://lospec.com/palette-list/arq4
var PaletteAmmo8 = Palette{
{0x04, 0x0C, 0x06, 0xFF},
{0x11, 0x23, 0x18, 0xFF},
{0x1E, 0x3A, 0x29, 0xFF},
{0x30, 0x5D, 0x42, 0xFF},
{0x4D, 0x80, 0x61, 0xFF},
{0x89, 0xA2, 0x57, 0xFF},
{0xBE, 0xDC, 0x7F, 0xFF},
{0xEE, 0xFF, 0xCC, 0xFF},
}
PaletteAmmo8 is the Ammo-8 palette.
Created by rsvp asap.
https://lospec.com/palette-list/ammo-8
var PaletteArne16 = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0x49, 0x3C, 0x2B, 0xFF},
{0xBE, 0x26, 0x33, 0xFF},
{0xE0, 0x6F, 0x8B, 0xFF},
{0x9D, 0x9D, 0x9D, 0xFF},
{0xA4, 0x64, 0x22, 0xFF},
{0xEB, 0x89, 0x31, 0xFF},
{0xF7, 0xE2, 0x6B, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0x1B, 0x26, 0x32, 0xFF},
{0x2F, 0x48, 0x4E, 0xFF},
{0x44, 0x89, 0x1A, 0xFF},
{0xA3, 0xCE, 0x27, 0xFF},
{0x00, 0x57, 0x84, 0xFF},
{0x31, 0xA2, 0xF2, 0xFF},
{0xB2, 0xDC, 0xEF, 0xFF},
}
PaletteArne16 is the Arne 16 palette.
Created by Arne.
https://lospec.com/palette-list/arne-16
var PaletteByName = PaletteLookup{ "1Bit": Palette1Bit, "2BitGrayScale": Palette2BitGrayScale, "3Bit": Palette3Bit, "CGA": PaletteCGA, "15PDX": Palette15PDX, "20PDX": Palette20PDX, "AAP16": PaletteAAP16, "AAP64": PaletteAAP64, "Splendor128": PaletteSplendor128, "Arne16": PaletteArne16, "Famicube": PaletteFamicube, "EDG16": PaletteEDG16, "EDG32": PaletteEDG32, "EDG36": PaletteEDG36, "EDG64": PaletteEDG64, "EDG8": PaletteEDG8, "EN4": PaletteEN4, "ARQ4": PaletteARQ4, "Ink": PaletteInk, "Ammo8": PaletteAmmo8, "NYX8": PaletteNYX8, "Night16": PaletteNight16, "PICO8": PalettePICO8, "Tango": PaletteTango, "Go": PaletteGo, }
PaletteByName is a map of all palettes by name.
var PaletteCGA = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0x55, 0x55, 0x55, 0xFF},
{0xAA, 0xAA, 0xAA, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0x00, 0x00, 0xAA, 0xFF},
{0x55, 0x55, 0xFF, 0xFF},
{0x00, 0xAA, 0x00, 0xFF},
{0x55, 0xFF, 0x55, 0xFF},
{0x00, 0xAA, 0xAA, 0xFF},
{0x55, 0xFF, 0xFF, 0xFF},
{0xAA, 0x00, 0x00, 0xFF},
{0xFF, 0x55, 0x55, 0xFF},
{0xAA, 0x00, 0xAA, 0xFF},
{0xFF, 0x55, 0xFF, 0xFF},
{0xAA, 0x55, 0x00, 0xFF},
{0xFF, 0xFF, 0x55, 0xFF},
}
PaletteCGA is the Color Graphics Adapter palette.
CGA was a graphics card released in 1981 for the IBM PC. The standard mode uses one of two 4-color palettes (each with a low-intensity and high-intensity mode), but a hack allows use of all 16. #cga
https://lospec.com/palette-list/color-graphics-adapter
var PaletteEDG16 = Palette{
{0xE4, 0xA6, 0x72, 0xFF},
{0xB8, 0x6F, 0x50, 0xFF},
{0x74, 0x3F, 0x39, 0xFF},
{0x3F, 0x28, 0x32, 0xFF},
{0x9E, 0x28, 0x35, 0xFF},
{0xE5, 0x3B, 0x44, 0xFF},
{0xFB, 0x92, 0x2B, 0xFF},
{0xFF, 0xE7, 0x62, 0xFF},
{0x63, 0xC6, 0x4D, 0xFF},
{0x32, 0x73, 0x45, 0xFF},
{0x19, 0x3D, 0x3F, 0xFF},
{0x4F, 0x67, 0x81, 0xFF},
{0xAF, 0xBF, 0xD2, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0x2C, 0xE8, 0xF4, 0xFF},
{0x04, 0x84, 0xD1, 0xFF},
}
PaletteEDG16 is the Endesga 16 palette.
Created by Endesga. #EDG16
https://lospec.com/palette-list/endesga-16
var PaletteEDG32 = Palette{
{0xBE, 0x4A, 0x2F, 0xFF},
{0xD7, 0x76, 0x43, 0xFF},
{0xEA, 0xD4, 0xAA, 0xFF},
{0xE4, 0xA6, 0x72, 0xFF},
{0xB8, 0x6F, 0x50, 0xFF},
{0x73, 0x3E, 0x39, 0xFF},
{0x3E, 0x27, 0x31, 0xFF},
{0xA2, 0x26, 0x33, 0xFF},
{0xE4, 0x3B, 0x44, 0xFF},
{0xF7, 0x76, 0x22, 0xFF},
{0xFE, 0xAE, 0x34, 0xFF},
{0xFE, 0xE7, 0x61, 0xFF},
{0x63, 0xC7, 0x4D, 0xFF},
{0x3E, 0x89, 0x48, 0xFF},
{0x26, 0x5C, 0x42, 0xFF},
{0x19, 0x3C, 0x3E, 0xFF},
{0x12, 0x4E, 0x89, 0xFF},
{0x00, 0x99, 0xDB, 0xFF},
{0x2C, 0xE8, 0xF5, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0xC0, 0xCB, 0xDC, 0xFF},
{0x8B, 0x9B, 0xB4, 0xFF},
{0x5A, 0x69, 0x88, 0xFF},
{0x3A, 0x44, 0x66, 0xFF},
{0x26, 0x2B, 0x44, 0xFF},
{0x18, 0x14, 0x25, 0xFF},
{0xFF, 0x00, 0x44, 0xFF},
{0x68, 0x38, 0x6C, 0xFF},
{0xB5, 0x50, 0x88, 0xFF},
{0xF6, 0x75, 0x7A, 0xFF},
{0xE8, 0xB7, 0x96, 0xFF},
{0xC2, 0x85, 0x69, 0xFF},
}
PaletteEDG32 is the Endesga 32 palette.
Created by Endesga for his game NYKRA. #EDG32
https://lospec.com/palette-list/endesga-32
var PaletteEDG36 = Palette{
{0xDB, 0xE0, 0xE7, 0xFF},
{0xA3, 0xAC, 0xBE, 0xFF},
{0x67, 0x70, 0x8B, 0xFF},
{0x4E, 0x53, 0x71, 0xFF},
{0x39, 0x3A, 0x56, 0xFF},
{0x26, 0x24, 0x3A, 0xFF},
{0x14, 0x10, 0x20, 0xFF},
{0x7B, 0xCF, 0x5C, 0xFF},
{0x50, 0x9B, 0x4B, 0xFF},
{0x2E, 0x6A, 0x42, 0xFF},
{0x1A, 0x45, 0x3B, 0xFF},
{0x0F, 0x27, 0x38, 0xFF},
{0x0D, 0x2F, 0x6D, 0xFF},
{0x0F, 0x4D, 0xA3, 0xFF},
{0x0E, 0x82, 0xCE, 0xFF},
{0x13, 0xB2, 0xF2, 0xFF},
{0x41, 0xF3, 0xFC, 0xFF},
{0xF0, 0xD2, 0xAF, 0xFF},
{0xE5, 0xAE, 0x78, 0xFF},
{0xC5, 0x81, 0x58, 0xFF},
{0x94, 0x55, 0x42, 0xFF},
{0x62, 0x35, 0x30, 0xFF},
{0x46, 0x21, 0x1F, 0xFF},
{0x97, 0x43, 0x2A, 0xFF},
{0xE5, 0x70, 0x28, 0xFF},
{0xF7, 0xAC, 0x37, 0xFF},
{0xFB, 0xDF, 0x6B, 0xFF},
{0xFE, 0x97, 0x9B, 0xFF},
{0xED, 0x52, 0x59, 0xFF},
{0xC4, 0x2C, 0x36, 0xFF},
{0x78, 0x1F, 0x2C, 0xFF},
{0x35, 0x14, 0x28, 0xFF},
{0x4D, 0x23, 0x52, 0xFF},
{0x7F, 0x3B, 0x86, 0xFF},
{0xB4, 0x5E, 0xB3, 0xFF},
{0xE3, 0x8D, 0xD6, 0xFF},
}
PaletteEDG36 is the Endesga 36 palette.
Created by Endesga. #EDG36
https://lospec.com/palette-list/endesga-36
var PaletteEDG64 = Palette{
{0xFF, 0x00, 0x40, 0xFF},
{0x13, 0x13, 0x13, 0xFF},
{0x1B, 0x1B, 0x1B, 0xFF},
{0x27, 0x27, 0x27, 0xFF},
{0x3D, 0x3D, 0x3D, 0xFF},
{0x5D, 0x5D, 0x5D, 0xFF},
{0x85, 0x85, 0x85, 0xFF},
{0xB4, 0xB4, 0xB4, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0xC7, 0xCF, 0xDD, 0xFF},
{0x92, 0xA1, 0xB9, 0xFF},
{0x65, 0x73, 0x92, 0xFF},
{0x42, 0x4C, 0x6E, 0xFF},
{0x2A, 0x2F, 0x4E, 0xFF},
{0x1A, 0x19, 0x32, 0xFF},
{0x0E, 0x07, 0x1B, 0xFF},
{0x1C, 0x12, 0x1C, 0xFF},
{0x39, 0x1F, 0x21, 0xFF},
{0x5D, 0x2C, 0x28, 0xFF},
{0x8A, 0x48, 0x36, 0xFF},
{0xBF, 0x6F, 0x4A, 0xFF},
{0xE6, 0x9C, 0x69, 0xFF},
{0xF6, 0xCA, 0x9F, 0xFF},
{0xF9, 0xE6, 0xCF, 0xFF},
{0xED, 0xAB, 0x50, 0xFF},
{0xE0, 0x74, 0x38, 0xFF},
{0xC6, 0x45, 0x24, 0xFF},
{0x8E, 0x25, 0x1D, 0xFF},
{0xFF, 0x50, 0x00, 0xFF},
{0xED, 0x76, 0x14, 0xFF},
{0xFF, 0xA2, 0x14, 0xFF},
{0xFF, 0xC8, 0x25, 0xFF},
{0xFF, 0xEB, 0x57, 0xFF},
{0xD3, 0xFC, 0x7E, 0xFF},
{0x99, 0xE6, 0x5F, 0xFF},
{0x5A, 0xC5, 0x4F, 0xFF},
{0x33, 0x98, 0x4B, 0xFF},
{0x1E, 0x6F, 0x50, 0xFF},
{0x13, 0x4C, 0x4C, 0xFF},
{0x0C, 0x2E, 0x44, 0xFF},
{0x00, 0x39, 0x6D, 0xFF},
{0x00, 0x69, 0xAA, 0xFF},
{0x00, 0x98, 0xDC, 0xFF},
{0x00, 0xCD, 0xF9, 0xFF},
{0x0C, 0xF1, 0xFF, 0xFF},
{0x94, 0xFD, 0xFF, 0xFF},
{0xFD, 0xD2, 0xED, 0xFF},
{0xF3, 0x89, 0xF5, 0xFF},
{0xDB, 0x3F, 0xFD, 0xFF},
{0x7A, 0x09, 0xFA, 0xFF},
{0x30, 0x03, 0xD9, 0xFF},
{0x0C, 0x02, 0x93, 0xFF},
{0x03, 0x19, 0x3F, 0xFF},
{0x3B, 0x14, 0x43, 0xFF},
{0x62, 0x24, 0x61, 0xFF},
{0x93, 0x38, 0x8F, 0xFF},
{0xCA, 0x52, 0xC9, 0xFF},
{0xC8, 0x50, 0x86, 0xFF},
{0xF6, 0x81, 0x87, 0xFF},
{0xF5, 0x55, 0x5D, 0xFF},
{0xEA, 0x32, 0x3C, 0xFF},
{0xC4, 0x24, 0x30, 0xFF},
{0x89, 0x1E, 0x2B, 0xFF},
{0x57, 0x1C, 0x27, 0xFF},
}
PaletteEDG64 is the Endesga 64 palette.
"Honed over years of palette creation, refined for materialistic pixelart and design. High contrast, high saturation, shaped around painting the organic and structured life of the heptaverse." Created by Endesga. #EDG64
https://lospec.com/palette-list/endesga-64
var PaletteEDG8 = Palette{
{0xFD, 0xFD, 0xF8, 0xFF},
{0xD3, 0x27, 0x34, 0xFF},
{0xDA, 0x7D, 0x22, 0xFF},
{0xE6, 0xDA, 0x29, 0xFF},
{0x28, 0xC6, 0x41, 0xFF},
{0x2D, 0x93, 0xDD, 0xFF},
{0x7B, 0x53, 0xAD, 0xFF},
{0x1B, 0x1C, 0x33, 0xFF},
}
PaletteEDG8 is the Endesga 8 palette.
Created by Endesga. #EDG8
https://lospec.com/palette-list/endesga-8
var PaletteEN4 = Palette{
{0xFB, 0xF7, 0xF3, 0xFF},
{0xE5, 0xB0, 0x83, 0xFF},
{0x42, 0x6E, 0x5D, 0xFF},
{0x20, 0x28, 0x3D, 0xFF},
}
PaletteEN4 is the EN4 palette.
Created by Endesga. #EN4
https://lospec.com/palette-list/en4
var PaletteFamicube = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0x00, 0x17, 0x7D, 0xFF},
{0x02, 0x4A, 0xCA, 0xFF},
{0x00, 0x84, 0xFF, 0xFF},
{0x5B, 0xA8, 0xFF, 0xFF},
{0x98, 0xDC, 0xFF, 0xFF},
{0x9B, 0xA0, 0xEF, 0xFF},
{0x62, 0x64, 0xDC, 0xFF},
{0x3D, 0x34, 0xA5, 0xFF},
{0x21, 0x16, 0x40, 0xFF},
{0x5A, 0x19, 0x91, 0xFF},
{0x6A, 0x31, 0xCA, 0xFF},
{0xA6, 0x75, 0xFE, 0xFF},
{0xE2, 0xC9, 0xFF, 0xFF},
{0xFE, 0xC9, 0xED, 0xFF},
{0xD5, 0x9C, 0xFC, 0xFF},
{0xCC, 0x69, 0xE4, 0xFF},
{0xA3, 0x28, 0xB3, 0xFF},
{0x87, 0x16, 0x46, 0xFF},
{0xCF, 0x3C, 0x71, 0xFF},
{0xFF, 0x82, 0xCE, 0xFF},
{0xFF, 0xE9, 0xC5, 0xFF},
{0xF5, 0xB7, 0x84, 0xFF},
{0xE1, 0x82, 0x89, 0xFF},
{0xDA, 0x65, 0x5E, 0xFF},
{0x82, 0x3C, 0x3D, 0xFF},
{0x4F, 0x15, 0x07, 0xFF},
{0xE0, 0x3C, 0x28, 0xFF},
{0xE2, 0xD7, 0xB5, 0xFF},
{0xC5, 0x97, 0x82, 0xFF},
{0xAE, 0x6C, 0x37, 0xFF},
{0x5C, 0x3C, 0x0D, 0xFF},
{0x23, 0x17, 0x12, 0xFF},
{0xAD, 0x4E, 0x1A, 0xFF},
{0xF6, 0x8F, 0x37, 0xFF},
{0xFF, 0xE7, 0x37, 0xFF},
{0xFF, 0xBB, 0x31, 0xFF},
{0xCC, 0x8F, 0x15, 0xFF},
{0x93, 0x97, 0x17, 0xFF},
{0xB6, 0xC1, 0x21, 0xFF},
{0xEE, 0xFF, 0xA9, 0xFF},
{0xBE, 0xEB, 0x71, 0xFF},
{0x8C, 0xD6, 0x12, 0xFF},
{0x6A, 0xB4, 0x17, 0xFF},
{0x37, 0x6D, 0x03, 0xFF},
{0x17, 0x28, 0x08, 0xFF},
{0x00, 0x4E, 0x00, 0xFF},
{0x13, 0x9D, 0x08, 0xFF},
{0x58, 0xD3, 0x32, 0xFF},
{0x20, 0xB5, 0x62, 0xFF},
{0x00, 0x60, 0x4B, 0xFF},
{0x00, 0x52, 0x80, 0xFF},
{0x0A, 0x98, 0xAC, 0xFF},
{0x25, 0xE2, 0xCD, 0xFF},
{0xBD, 0xFF, 0xCA, 0xFF},
{0x71, 0xA6, 0xA1, 0xFF},
{0x41, 0x5D, 0x66, 0xFF},
{0x0D, 0x20, 0x30, 0xFF},
{0x15, 0x15, 0x15, 0xFF},
{0x34, 0x34, 0x34, 0xFF},
{0x7B, 0x7B, 0x7B, 0xFF},
{0xA8, 0xA8, 0xA8, 0xFF},
{0xD7, 0xD7, 0xD7, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
}
PaletteFamicube is the Famicube palette.
Created by Arne as part of his Famicube Project.
https://lospec.com/palette-list/famicube
var PaletteGo = Palette{
{0x00, 0xAD, 0xD8, 0xFF},
{0x0B, 0xB5, 0xDB, 0xFF},
{0x31, 0xBE, 0xE0, 0xFF},
{0x4D, 0xC7, 0xE4, 0xFF},
{0x68, 0xCC, 0xE7, 0xFF},
{0x82, 0xD2, 0xE8, 0xFF},
{0x9C, 0xDB, 0xED, 0xFF},
{0xB5, 0xE3, 0xF0, 0xFF},
{0xE9, 0xF3, 0xF9, 0xFF},
{0x5D, 0xC9, 0xE2, 0xFF},
{0x7D, 0xD1, 0xE6, 0xFF},
{0x98, 0xD9, 0xEA, 0xFF},
{0x98, 0xD5, 0xEC, 0xFF},
{0xC5, 0xE9, 0xF2, 0xFF},
{0xD5, 0xEE, 0xF5, 0xFF},
{0xE3, 0xF4, 0xF8, 0xFF},
{0xEE, 0xF8, 0xFB, 0xFF},
{0xF7, 0xFC, 0xFD, 0xFF},
{0x00, 0xA2, 0x9C, 0xFF},
{0x5B, 0xC4, 0xBA, 0xFF},
{0x77, 0xCB, 0xC5, 0xFF},
{0x94, 0xD5, 0xD1, 0xFF},
{0xAD, 0xDE, 0xDB, 0xFF},
{0xC4, 0xE7, 0xE4, 0xFF},
{0xD7, 0xEE, 0xED, 0xFF},
{0xE8, 0xF5, 0xF4, 0xFF},
{0xD8, 0xEE, 0xEB, 0xFF},
{0xCE, 0x32, 0x62, 0xFF},
{0xD7, 0x5C, 0x7E, 0xFF},
{0xDE, 0x7B, 0x96, 0xFF},
{0xE4, 0x97, 0xAD, 0xFF},
{0xEB, 0xB1, 0xC1, 0xFF},
{0xF2, 0xC9, 0xD4, 0xFF},
{0xF6, 0xDC, 0xE3, 0xFF},
{0xF9, 0xEA, 0xEE, 0xFF},
{0xF1, 0xD2, 0xD3, 0xFF},
{0x00, 0x00, 0x00, 0xFF},
{0x1B, 0x1A, 0x1A, 0xFF},
{0x2E, 0x2D, 0x2C, 0xFF},
{0x40, 0x3D, 0x3D, 0xFF},
{0x53, 0x50, 0x50, 0xFF},
{0x68, 0x64, 0x64, 0xFF},
{0x7F, 0x7C, 0x7B, 0xFF},
{0x9A, 0x97, 0x96, 0xFF},
{0xB5, 0xB2, 0xB3, 0xFF},
{0xFD, 0xDD, 0x00, 0xFF},
{0xFE, 0xE3, 0x3D, 0xFF},
{0xFF, 0xE9, 0x67, 0xFF},
{0xFF, 0xED, 0x88, 0xFF},
{0xFE, 0xF1, 0xA4, 0xFF},
{0xFE, 0xF5, 0xBE, 0xFF},
{0xFE, 0xF9, 0xD5, 0xFF},
{0xFF, 0xFB, 0xE6, 0xFF},
{0xFF, 0xFE, 0xF3, 0xFF},
{0x00, 0x75, 0x8D, 0xFF},
{0x55, 0x57, 0x59, 0xFF},
{0x40, 0x2B, 0x56, 0xFF},
{0xDB, 0xD9, 0xD6, 0xFF},
}
PaletteGo is the Go palette.
https://golang.org/s/brandbook
var PaletteInk = Palette{
{0x1F, 0x1F, 0x29, 0xFF},
{0x41, 0x3A, 0x42, 0xFF},
{0x59, 0x60, 0x70, 0xFF},
{0x96, 0xA2, 0xB3, 0xFF},
{0xEA, 0xF0, 0xD8, 0xFF},
}
PaletteInk is the Ink palette.
Created by AprilSundae.
https://lospec.com/palette-list/ink
var PaletteNYX8 = Palette{
{0x08, 0x14, 0x1E, 0xFF},
{0x0F, 0x2A, 0x3F, 0xFF},
{0x20, 0x39, 0x4F, 0xFF},
{0xF6, 0xD6, 0xBD, 0xFF},
{0xC3, 0xA3, 0x8A, 0xFF},
{0x99, 0x75, 0x77, 0xFF},
{0x81, 0x62, 0x71, 0xFF},
{0x4E, 0x49, 0x5F, 0xFF},
}
PaletteNYX8 is the NYX8 palette.
Palette created by Javier Guerrero.
https://lospec.com/palette-list/nyx8
var PaletteNight16 = Palette{
{0x0F, 0x0F, 0x1E, 0xFF},
{0xFF, 0xF8, 0xBC, 0xFF},
{0x0C, 0x21, 0x33, 0xFF},
{0x48, 0x58, 0x6D, 0xFF},
{0x79, 0xA0, 0xB0, 0xFF},
{0xB0, 0xCE, 0x9D, 0xFF},
{0x65, 0x7F, 0x49, 0xFF},
{0x3F, 0x45, 0x36, 0xFF},
{0xB9, 0x9D, 0x6A, 0xFF},
{0xFF, 0xDD, 0x91, 0xFF},
{0xDD, 0x94, 0x5B, 0xFF},
{0x9A, 0x51, 0x42, 0xFF},
{0x64, 0x4B, 0x48, 0xFF},
{0x33, 0x30, 0x33, 0xFF},
{0x76, 0x70, 0x88, 0xFF},
{0xC5, 0xA3, 0xB3, 0xFF},
}
PaletteNight16 is the Night 16 palette.
3rd place winner of the PixelJoint 16 color palette competition (2015). Created by Night.
https://lospec.com/palette-list/night-16
var PalettePICO8 = Palette{
{0x00, 0x00, 0x00, 0xFF},
{0x5F, 0x57, 0x4F, 0xFF},
{0xC2, 0xC3, 0xC7, 0xFF},
{0xFF, 0xF1, 0xE8, 0xFF},
{0xFF, 0xEC, 0x27, 0xFF},
{0xFF, 0xA3, 0x00, 0xFF},
{0xFF, 0xCC, 0xAA, 0xFF},
{0xAB, 0x52, 0x36, 0xFF},
{0xFF, 0x77, 0xA8, 0xFF},
{0xFF, 0x00, 0x4D, 0xFF},
{0x83, 0x76, 0x9C, 0xFF},
{0x7E, 0x25, 0x53, 0xFF},
{0x29, 0xAD, 0xFF, 0xFF},
{0x1D, 0x2B, 0x53, 0xFF},
{0x00, 0x87, 0x51, 0xFF},
{0x00, 0xE4, 0x36, 0xFF},
}
PalettePICO8 is the palette used by PICO-8.
The PICO-8 is a virtual video game console created by Lexaloffle Games.
https://lospec.com/palette-list/pico-8
var PaletteSplendor128 = Palette{}/* 128 elements not displayed */
PaletteSplendor128 is the Splendor 128 palette.
Created by Adigun Polack as a successor to his AAP-64 palette. #Splendor128
https://lospec.com/palette-list/aap-splendor128
var PaletteTango = Palette{
{0xFC, 0xE9, 0x4F, 0xFF},
{0xED, 0xD4, 0x00, 0xFF},
{0xC4, 0xA0, 0x00, 0xFF},
{0xFC, 0xAF, 0x3E, 0xFF},
{0xF5, 0x79, 0x00, 0xFF},
{0xCE, 0x5C, 0x00, 0xFF},
{0xE9, 0xB9, 0x6E, 0xFF},
{0xC1, 0x7D, 0x11, 0xFF},
{0x8F, 0x59, 0x02, 0xFF},
{0x8A, 0xE2, 0x34, 0xFF},
{0x73, 0xD2, 0x16, 0xFF},
{0x4E, 0x9A, 0x06, 0xFF},
{0x72, 0x9F, 0xCF, 0xFF},
{0x34, 0x65, 0xA4, 0xFF},
{0x20, 0x4A, 0x87, 0xFF},
{0xAD, 0x7F, 0xA8, 0xFF},
{0x75, 0x50, 0x7B, 0xFF},
{0x5C, 0x35, 0x66, 0xFF},
{0xEF, 0x29, 0x29, 0xFF},
{0xCC, 0x00, 0x00, 0xFF},
{0xA4, 0x00, 0x00, 0xFF},
{0xEE, 0xEE, 0xEC, 0xFF},
{0xD3, 0xD7, 0xCF, 0xFF},
{0xBA, 0xBD, 0xB6, 0xFF},
{0x88, 0x8A, 0x85, 0xFF},
{0x55, 0x57, 0x53, 0xFF},
{0x2E, 0x34, 0x36, 0xFF},
}
PaletteTango is the Tango palette.
http://en.wikipedia.org/wiki/Tango_Desktop_Project#Palette
var PalettesByNumberOfColors = func() map[int]PaletteLookup { pnc := map[int]PaletteLookup{} for n, p := range PaletteByName { c := len(p) if pnc[c] == nil { pnc[c] = PaletteLookup{} } pnc[c][n] = p } return pnc }()
PalettesByNumberOfColors is a map of int to Palettes.
var ZP = image.ZP
ZP is the zero image.Point.
var ZR = image.ZR
ZR is the zero image.Rectangle.
var ZV = Vec{0, 0}
ZV is a zero vector.
var ZV3 = Vec3{0, 0, 0}
ZV3 is the zero Vec3
Functions ¶
func Base64EncodedPNG ¶
Base64EncodedPNG encodes the given image into a string using base64.StdEncoding.
func Base64ImgTag ¶
Base64ImgTag returns a HTML tag for an img with its src set to a base64 encoded PNG.
func Clamp ¶
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 ColorNRGBA ¶
ColorNRGBA constructs a color.NRGBA.
func ColorWithAlpha ¶
ColorWithAlpha creates a new color.RGBA based on the provided color.Color and alpha arguments.
func CreateFile ¶
CreateFile creates or truncates the named file.
func DecodeImage ¶
DecodeImage decodes an image from the provided io.Reader.
func DecodeImageBytes ¶
DecodeImageBytes decodes an image from the provided []byte.
func DecodePNGBytes ¶
DecodePNGBytes decodes a PNG from the provided []byte.
func DrawCicleFast ¶
DrawCicleFast draws a (crude) filled circle.
func DrawCircle ¶
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 ¶
DrawCircleFilled draws a filled circle.
func DrawColorOver ¶
DrawColorOver draws an image.Rectangle of uniform color over dst.
func DrawIntCircle ¶
DrawIntCircle draws a circle given a point and radius
func DrawIntFilledCircle ¶
DrawIntFilledCircle draws a filled circle given a point and radius
func DrawIntFilledRectangle ¶
DrawIntFilledRectangle draws a filled rectangle given a point, width and height
func DrawIntFilledTriangle ¶
DrawIntFilledTriangle draws a filled triangle given three points
func DrawIntLine ¶
DrawIntLine draws a line between two points
func DrawIntRectangle ¶
DrawIntRectangle draws a rectangle given a point, width and height
func DrawIntTriangle ¶
DrawIntTriangle draws a triangle given three points
func DrawLine ¶
DrawLine draws a line of the given color. A thickness of <= 1 is drawn using DrawBresenhamLine.
func DrawLineBresenham ¶
DrawLineBresenham draws a line using Bresenham's line algorithm.
http://en.wikipedia.org/wiki/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 DrawPalettedImage ¶
func DrawPalettedImage(dst PalettedDrawImage, r image.Rectangle, src PalettedImage)
DrawPalettedImage draws a PalettedImage over a PalettedDrawImage.
func DrawPalettedLayer ¶
DrawPalettedLayer draws a *Layer over a *Paletted. (slightly faster than using the generic DrawPalettedImage)
func DrawPointCircle ¶
DrawPointCircle draws a circle at the given point.
func DrawPolygon ¶
DrawPolygon filled or as line polygons if the thickness is >= 1.
func DrawPolyline ¶
DrawPolyline draws a polyline with the given color and thickness.
func DrawTriangles ¶
DrawTriangles draws triangles on dst.
func DrawTrianglesOver ¶
DrawTrianglesOver draws triangles over dst.
func DrawTrianglesWireframe ¶
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 ¶
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 EncodeJSON ¶
EncodeJSON creates a new JSON encoder and encodes the provided value.
func Errorf ¶
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 IntAbs ¶
IntAbs returns the absolute value of x.
Example ¶
Dump( IntAbs(10), IntAbs(-5), )
Output: 10 5
func IntClamp ¶
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 ¶
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 ¶
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 ¶
JSONIndent configures the prefix and indent level of a JSON encoder.
func Lerp ¶
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 ¶
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 ¶
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 MathCeil ¶
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 ¶
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 MathFloor ¶
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 ¶
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 MathMax ¶
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 ¶
MathMin returns the smaller of x or y.
Example ¶
Dump( MathMin(-1, 1), MathMin(1, 2), MathMin(3, 2), )
Output: -1 1 2
func MathSin ¶
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 MathSqrt ¶
MathSqrt returns the square root of x.
Example ¶
Dump( MathSqrt(1), MathSqrt(2), MathSqrt(3), )
Output: 1 1.4142135623730951 1.7320508075688772
func MustOpenImage ¶
MustOpenImage decodes an image using the provided file name. Panics on error.
func NewGray16 ¶
NewGray16 returns a new Gray16 image with the given bounds. (For example useful for height maps)
func NewJSONEncoder ¶
NewJSONEncoder creates a new JSON encoder for the given io.Writer.
func NewResizedImage ¶
NewResizedImage returns a new image with the provided dimensions.
func NewResizedRGBA ¶
NewResizedRGBA returns a new RGBA image with the provided dimensions.
func NewScaledImage ¶
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 ¶
NewScaledRGBA returns a new RGBA image scaled by the provided scaling factor.
func NewUniform ¶
NewUniform creates a new uniform image of the given color.
func Playground ¶
Playground displays image on The Go Playground using the IMAGE: base64 encoded PNG “hack”
func Printf ¶
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 RandFloat64 ¶
func RandFloat64() float64
RandFloat64 returns, as a float64, a pseudo-random number in [0.0,1.0) from the default Source.
func RandIntn ¶
RandIntn returns, as an int, a non-negative pseudo-random number in [0,n) from the default Source. It panics if n <= 0.
func RandSeed ¶
func RandSeed(seed int64)
RandSeed uses the provided seed value to initialize the default Source to a deterministic state. If Seed is not called, the generator behaves as if seeded by Seed(1). Seed values that have the same remainder when divided by 2^31-1 generate the same pseudo-random sequence. RandSeed, unlike the Rand.Seed method, is safe for concurrent use.
func ResizeImage ¶
ResizeImage using nearest neighbor scaling on dst from src.
func Sign ¶
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
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 (*Animation) AddPalettedImage ¶
func (a *Animation) AddPalettedImage(frame PalettedImage)
AddPalettedImage adds a frame and palette to the animation.
type BasicTarget ¶
type BasicTarget interface { Target // SetMatrix sets a Matrix that every point will be projected by. SetMatrix(Matrix) }
BasicTarget is a Target with additional basic adjustment methods.
type Batch ¶
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 ¶
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) 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) 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.
type Block ¶
type Block struct { Pos Vec3 Size Vec3 Color BlockColor }
Block has a position, size and color.
func (Block) Corners ¶
func (b Block) Corners(origin Vec3) BlockCorners
Corners returns the screen coordinates for the Block corners.
func (Block) DrawBounds ¶
DrawBounds for block on dst at origin.
func (Block) DrawPolygons ¶
DrawPolygons for block on dst at origin.
func (Block) DrawRectangles ¶
DrawRectangles for block on dst at origin.
func (Block) DrawWireframe ¶
DrawWireframe block on dst at origin.
func (Block) Polygons ¶
Polygons returns the shape, top, left and right polygons with coordinates based on origin.
func (Block) TrianglesData ¶
func (b Block) TrianglesData(origin Vec3) *TrianglesData
TrianglesData creates triangles data for the Block.
type BlockColor ¶
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.
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) AddNewBlock ¶
func (blocks *Blocks) AddNewBlock(pos, size Vec3, ic BlockColor)
AddNewBlock creates a new Block and appends it to the slice.
func (Blocks) DrawBounds ¶
DrawBounds for all blocks.
func (Blocks) DrawPolygons ¶
DrawPolygons draws all of the blocks on the dst image. (using the shape, top and left polygons at the given origin)
func (Blocks) DrawRectangles ¶
DrawRectangles for all blocks.
func (Blocks) DrawWireframes ¶
DrawWireframes for all blocks.
type Box ¶
Box is a 3D cuboid with a min and max Vec3
type CIELab ¶
CIELab represents a color in CIE-L*ab.
func (CIELab) DeltaC ¶
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 ¶
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 ¶
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 ¶
Circle is a 2D circle. It is defined by two properties:
- Center vector
- Radius float64
func C ¶
C returns a new Circle with the given radius and center coordinates.
Note that a negative radius is valid.
func (Circle) Contains ¶
Contains checks whether a vector `u` is contained within this Circle (including it's perimeter).
func (Circle) Intersect ¶
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 ¶
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) Norm ¶
Norm returns the Circle in normalized form - this sets the radius to its absolute value.
func (Circle) Resized ¶
Resized returns the Circle resized by the given delta. The Circles center is use as the anchor.
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) 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.
type Float64Scaler ¶
Float64Scaler can scale a float64 to another float64.
type GeoPoint ¶
GeoPoint represents a geographic point with Lat/Lon.
func NewGeoPointFromTileNumbers ¶
NewGeoPointFromTileNumbers creates a new GeoPoint based on the given tile numbers. https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_numbers_to_lon..2Flat.
type GeoTile ¶
GeoTile consists of a Zoom level, X and Y values.
func (GeoTile) Bounds ¶
Bounds returns an image.Rectangle for the GeoTile based on the dst, gp and tileSize.
type GeoTileServer ¶
type GeoTileServer struct {
Format string
}
GeoTileServer represents a tile server.
func (GeoTileServer) DrawNeighbors ¶
DrawNeighbors on dst.
func (GeoTileServer) DrawTileAndNeighbors ¶
DrawTileAndNeighbors on dst.
type HSL ¶
HSL is the hue, saturation and lightness color representation. - Hue [0,360] - Saturation [0,1] - Lightness [0,1]
type HSV ¶
HSV is the hue, saturation and value color representation. - Hue [0,360] - Saturation [0,1] - Value [0,1]
type HunterLab ¶
HunterLab represents a color in Hunter-Lab.
func (HunterLab) 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 ¶
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 ¶
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 ¶
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 ¶
Draw draws all currently drawn shapes inside the IM onto another Target.
Note, that IMDraw's matrix have no effect here.
func (*IMDraw) Ellipse ¶
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 ¶
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) 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 ¶
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 ¶
Push adds some points to the IM queue. All Pushed points will have the same properties except for the position.
func (*IMDraw) Rectangle ¶
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.
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 (*Layer) ColorIndexAt ¶
ColorIndexAt returns the palette index of the pixel at (x, y).
func (*Layer) ColorModel ¶
ColorModel returns the color model for the paletted layer.
func (*Layer) ColorPalette ¶
ColorPalette retrieves the layer palette.
func (*Layer) GfxPalette ¶
GfxPalette retrieves the layer palette.
func (*Layer) SetTileIndex ¶
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 ¶
TileIndexAt returns the tile index at (x, y).
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 ¶
Chained adds another Matrix to this one. All tranformations by the next Matrix will be applied after the transformations of this Matrix.
func (Matrix) Project ¶
Project applies all transformations added to the Matrix to a vector u and returns the result.
Time complexity is O(1).
func (Matrix) Rotated ¶
Rotated rotates everything around a given point by the given angle in radians.
func (Matrix) RotatedDegrees ¶
RotatedDegrees rotates everything around a given point by the given number of degrees.
func (Matrix) ScaledXY ¶
ScaledXY scales everything around a given point by the scale factor in each axis respectively.
type Palette ¶
Palette is a slice of colors.
func (Palette) AsColorPalette ¶
AsColorPalette converts the Palette to a color.Palette.
func (Palette) CmplxPhaseAt ¶
func (p Palette) CmplxPhaseAt(z complex128) color.Color
CmplxPhaseAt returns the color at the phase of the given complex128 value.
type PaletteLookup ¶
type PaletteLookup map[PaletteName]Palette
PaletteLookup is a map of PaletteName to Palette.
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 ¶
NewPaletted returns a new paletted image with the given width, height and palette.
func NewPalettedImage ¶
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 (*Paletted) ColorIndexAt ¶
ColorIndexAt returns the color index at (x, y).
func (*Paletted) ColorModel ¶
ColorModel returns the color model of the paletted image.
func (*Paletted) ColorPalette ¶
ColorPalette returns the color palette of the paletted image.
func (*Paletted) GfxPalette ¶
GfxPalette returns the gfx palette of the paletted image.
func (*Paletted) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*Paletted) SetColorIndex ¶
SetColorIndex changes the color index at (x, y).
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 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 ¶
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 Polygon ¶
type Polygon []Vec
Polygon is represented by a list of vectors.
func (Polygon) EachPixel ¶
EachPixel calls the provided function for each pixel in the polygon rectangle bounds.
type Polyline ¶
type Polyline []Polygon
Polyline is a slice of polygons forming a line.
func NewPolyline ¶
NewPolyline constructs a slice of line polygons.
type ReadFunc ¶
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 ¶
BoundsToRect converts an image.Rectangle to a Rect.
func R ¶
R returns a new Rect given the Min and Max coordinates.
Note that the returned rectangle is not automatically normalized.
func (Rect) CenterOrigin ¶
CenterOrigin returns a Vec3 based on Rect.Center() scaled by v, and its Z component set to the provided z.
func (Rect) Contains ¶
Contains checks whether a vector u is contained within this Rect (including it's borders).
func (Rect) DrawColorOver ¶
DrawColorOver draws Rect with a uniform color over dst.
func (Rect) Intersect ¶
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 ¶
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) Norm ¶
Norm returns the Rect in normal form, such that Max is component-wise greater or equal than Min.
func (Rect) Resized ¶
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 ¶
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) 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)
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) 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) 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) 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 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 ¶
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.
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 ¶
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) DrawColorOver ¶
DrawColorOver draws the triangle over dst using the given color.
func (Triangle) DrawWireframe ¶
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.
type TriangleFunc ¶
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 ¶
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 ¶
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 ¶
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 ¶
BoundsCenter returns the vector in the center of an image.Rectangle
func Centroid ¶
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 ¶
CubicBezierCurve returns a slice of vectors representing a cubic bezier curve
func (Vec) Angle ¶
Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].
func (Vec) Bounds ¶
Bounds returns the bounds around the vector based on the provided Left, Top, Right, Bottom values.
func (Vec) Lerp ¶
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 ¶
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) Normal ¶
Normal returns a vector normal to u. Equivalent to u.Rotated(math.Pi / 2), but faster.
func (Vec) Project ¶
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) R ¶
R creates a new Rect for the vectors u and v.
Note that the returned rectangle is not automatically normalized.
func (Vec) Rect ¶
Rect constructs a Rect around the vector based on the provided Left, Top, Right, Bottom values.
func (Vec) 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)
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 ¶
BoundsCenterOrigin returns the center origin for the given image.Rectangle and z value.
func (Vec3) Lerp ¶
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 ¶
Map applies the function f to the x, y and z components of the vector u and returns the modified vector.
type Vertex ¶
Vertex holds Position, Color, Picture and Intensity.
type XYZ ¶
XYZ color space.
func ColorToXYZ ¶
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 ¶
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 ¶
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.
Source Files ¶
- animation.go
- base64.go
- batch.go
- bezier.go
- block.go
- blocks.go
- box.go
- bresenham.go
- cie_lab.go
- circle.go
- cmplx.go
- colors.go
- decode.go
- degrees.go
- doc.go
- draw.go
- draw_int.go
- draw_target.go
- drawer.go
- errors.go
- file.go
- geo.go
- hsl.go
- hsv.go
- http.go
- hunter_lab.go
- image.go
- imdraw.go
- int.go
- interfaces.go
- json.go
- layer.go
- linear_scaler.go
- log.go
- math.go
- matrix.go
- palette.go
- paletted_image.go
- palettes.go
- playground.go
- polygon.go
- polyline.go
- rand.go
- rect.go
- resize.go
- signed_distance.go
- simplex.go
- sort.go
- tiles.go
- triangle.go
- triangles_data.go
- vec2.go
- vec3.go
- vertex.go
- xyz.go