Documentation ¶
Overview ¶
Package pixel provides a drawing canvas specialized for pixel art.
It implements a GPU pipeline that works entirely in indexed colors at a chosen, fixed, resolution (usually lower than the screen resolution).
It does not provide any anti-aliasing, nor alpha-transparency, since the goal is to offer an easy way to work within the stricter definition of pixel art (i.e. limited color palette, no mixed-resolution or "mixels", and so on).
Index ¶
- Constants
- Variables
- func Box(fg, bg color.Index, layer int16, corner int16, p1, p2 XY)
- func Clear(c color.Index)
- func Err() error
- func FindColor(v color.Color) color.Index
- func LRGBAof(c color.Index) color.LRGBA
- func Lines(c color.Index, layer int16, strip ...XY)
- func Point(c color.Index, layer int16, pos XY)
- func SetColor(i color.Index, c color.Color) color.Index
- func SetPalette(p color.Palette)
- func SetResolution(r XY)
- func SetZoom(z int16)
- func Triangles(c color.Index, layer int16, strip ...XY)
- func Zoom() int16
- type Cursor
- func (a *Cursor) Locate(layer int16, p XY)
- func (a *Cursor) Print(args ...interface{}) (n int, err error)
- func (a *Cursor) Printf(format string, args ...interface{}) (n int, err error)
- func (a *Cursor) Println(args ...interface{}) (n int, err error)
- func (a *Cursor) Style(c color.Index, f FontID)
- func (a *Cursor) Write(p []byte) (n int, err error)
- func (a *Cursor) WriteRune(r rune)
- type FontID
- type PictureID
- type XY
- func (a XY) Cartesian() (x, y, z float32)
- func (a XY) Coord() coord.XY
- func (a XY) FlipX() XY
- func (a XY) FlipY() XY
- func (a XY) Minus(b XY) XY
- func (a XY) MinusS(s int16) XY
- func (a XY) Mod(s int16) XY
- func (a XY) ModXY(b XY) XY
- func (a XY) Null() bool
- func (a XY) Opposite() XY
- func (a XY) Perp() XY
- func (a XY) Plus(b XY) XY
- func (a XY) PlusS(s int16) XY
- func (a XY) ProjX() XY
- func (a XY) ProjY() XY
- func (a XY) Slash(s int16) XY
- func (a XY) SlashXY(b XY) XY
- func (a XY) Times(s int16) XY
- func (a XY) TimesXY(b XY) XY
- func (a XY) WindowXY() window.XY
- func (a XY) YX() XY
Constants ¶
const Monozela10 = FontID(0)
Monozela10 is the default font (10 pixel high, monospace). This is the only font that is always loaded and doesn't need declaration.
const MouseCursor = PictureID(1)
MouseCursor is a small picture that can be used as mouse cursor.
const Transparent = color.Index(0)
Transparent is the only reserved color index. All palettes start with it.
Variables ¶
var DefaultPalette = color.Palette{ ByName: map[string]color.Index{ "Dark Blue": 1, "Dark Purple": 2, "Dark Green": 3, "Brown": 4, "Dark Gray": 5, "Light Gray": 6, "White": 7, "Red": 8, "Orange": 9, "Yellow": 10, "Green": 11, "Blue": 12, "Indigo": 13, "Pink": 14, "Peach": 15, "Black": 16, }, Colors: []color.LRGBA{ color.LRGBAof(color.SRGB8{0x28, 0x22, 0x53}), color.LRGBAof(color.SRGB8{0x7E, 0x25, 0x53}), color.LRGBAof(color.SRGB8{0x00, 0x87, 0x51}), color.LRGBAof(color.SRGB8{0xAB, 0x52, 0x36}), color.LRGBAof(color.SRGB8{0x5F, 0x57, 0x4F}), color.LRGBAof(color.SRGB8{0xC2, 0xC3, 0xC7}), color.LRGBAof(color.SRGB8{0xFF, 0xF1, 0xE8}), color.LRGBAof(color.SRGB8{0xFF, 0x00, 0x4D}), color.LRGBAof(color.SRGB8{0xFF, 0xA3, 0x00}), color.LRGBAof(color.SRGB8{0xFF, 0xEC, 0x27}), color.LRGBAof(color.SRGB8{0x00, 0xE4, 0x36}), color.LRGBAof(color.SRGB8{0x29, 0xAD, 0xFF}), color.LRGBAof(color.SRGB8{0x83, 0x76, 0x9C}), color.LRGBAof(color.SRGB8{0xFF, 0x77, 0xA8}), color.LRGBAof(color.SRGB8{0xFF, 0xCC, 0xAA}), color.LRGBAof(color.SRGB8{0x00, 0x00, 0x00}), }, }
DefaultPalette is the palette initially loaded when the framework starts.
Functions ¶
func Clear ¶
Clear sets the color of all pixels on the canvas; it also resets the filter of all pixels.
func Err ¶
func Err() error
Err returns the first unchecked error of the package since last call to the function. The error is then considered checked, and further calls to Err will return nil until the next error occurs.
Note: errors occuring while there already is an unchecked error will not be recorded. However, if the debug mode is active, all errors will be logged.
func FindColor ¶
FindColor returns the first color index associated with specific LRGBA values. If there isn't any color with these values in the palette, index 0 is returned.
func Lines ¶
Lines queues a GPU command to draw a line strip on the canvas. A line strip is a succession of connected lines; all lines share the same color.
func SetPalette ¶
SetPalette asks the GPU to change the color palette.
Note that the palette will be used for every drawing command of the current frame, even those issued before the call to Use. In other words, you cannot change the palette in the middle of a frame.
func SetResolution ¶
func SetResolution(r XY)
SetResolution defines a target resolution for the automatic resizing of the canvas.
It guarantees that: - the canvas will never be smaller than the target resolution, - the target resolution will occupy as much screen as possible.
Types ¶
type Cursor ¶
type Cursor struct { Color color.Index Font FontID Margin int16 LetterSpacing int16 Interline int16 Position XY Layer int16 }
A Cursor is used to write text on the canvas.
func (*Cursor) Locate ¶
Locate moves the text cursor to a specific position. It also defines column p.X as the cursor margin, i.e. the column to which the cursor returns to start a new line.
func (*Cursor) Print ¶
Print queues a command on the GPU to display text on the canvas (works like fmt.Print).
func (*Cursor) Printf ¶
Printf queues a command on the GPU to display text on the canvas (works like fmt.Printf).
func (*Cursor) Println ¶
Println queues a command on the GPU to display text on the canvas (works like fmt.Println).
func (*Cursor) Style ¶
Style configures the color and font used to display text on the canvas. It also sets the cursor Interline to a sensible default for the selected font.
type PictureID ¶
type PictureID uint16
PictureID is the ID to handle static image assets.
type XY ¶
type XY struct {
X, Y int16
}
XY represents the coordinates of a pixel on the canvas.
func Resolution ¶
func Resolution() XY
Resolution returns the current dimension of the canvas (in *canvas* pixels).
func RoundXYof ¶
func RoundXYof(v coord.Coordinates) XY
RoundXYof returns an integer vector corresponding to the first two coordinates of v.
func XYof ¶
func XYof(v coord.Coordinates) XY
XYof returns an integer vector corresponding to the first two coordinates of v. If v is a window.XY, the coordinates are converted from window space to canvas space.
func (XY) Cartesian ¶
Cartesian returns the coordinates of the vector in 3D space. X and Y are casted to float32, and the third coordinate is always 0.
func (XY) Mod ¶
Mod returns the remainder (modulus) of the division by a scalar (which must be non-zero).
func (XY) ModXY ¶
ModXY returns the remainder (modulus) of the component-wise division by another vector (of which both X and Y must be non-zero).
func (XY) Slash ¶
Slash returns the integer quotient of the division by a scalar (which must be non-zero).
func (XY) SlashXY ¶
SlashXY returns the integer quotients of the component-wise division by another vector (of which both X and Y must be non-zero).