pixel

package
v0.0.0-...-d322e89 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2018 License: BSD-2-Clause Imports: 17 Imported by: 9

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

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

View Source
const MouseCursor = PictureID(1)

MouseCursor is a small picture that can be used as mouse cursor.

View Source
const Transparent = color.Index(0)

Transparent is the only reserved color index. All palettes start with it.

Variables

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

func Box(fg, bg color.Index, layer int16, corner int16, p1, p2 XY)

Box queues a GPU command to draw a box on the canvas.

func Clear

func Clear(c color.Index)

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

func FindColor(v color.Color) color.Index

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 LRGBAof

func LRGBAof(c color.Index) color.LRGBA

LRGBAof returns the color corresponding to a color index in the current palette.

func Lines

func Lines(c color.Index, layer int16, strip ...XY)

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 Point

func Point(c color.Index, layer int16, pos XY)

Point queues a GPU command to draw a point on the canvas.

func SetColor

func SetColor(i color.Index, c color.Color) color.Index

SetColor changes the color associated with an index.

func SetPalette

func SetPalette(p color.Palette)

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.

func SetZoom

func SetZoom(z int16)

SetZoom sets the pixel size used to display the canvas.

func Triangles

func Triangles(c color.Index, layer int16, strip ...XY)

Triangles queues a GPU command to draw a triangle strip on the canvas. Triangle strip have the same meaning than in OpenGL. All triangles share the same color.

func Zoom

func Zoom() int16

Zoom returns the size of one canvas pixel, in *window* pixels.

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

func (a *Cursor) Locate(layer int16, p XY)

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

func (a *Cursor) Print(args ...interface{}) (n int, err error)

Print queues a command on the GPU to display text on the canvas (works like fmt.Print).

func (*Cursor) Printf

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

Printf queues a command on the GPU to display text on the canvas (works like fmt.Printf).

func (*Cursor) Println

func (a *Cursor) Println(args ...interface{}) (n int, err error)

Println queues a command on the GPU to display text on the canvas (works like fmt.Println).

func (*Cursor) Style

func (a *Cursor) Style(c color.Index, f FontID)

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.

func (*Cursor) Write

func (a *Cursor) Write(p []byte) (n int, err error)

Write asks the GPU to display p (interpreted as an UTF8 string) on the canvas. This method implements the io.Writer interface.

func (*Cursor) WriteRune

func (a *Cursor) WriteRune(r rune)

WriteRune asks the GPU to display a single rune on the canvas.

type FontID

type FontID uint8

FontID is the ID to handle font assets.

func Font

func Font(path string) FontID

Font declares a new font and returns its ID.

func (FontID) Height

func (f FontID) Height() int16

Height returns the height of the font, i.e. the height of the images used to store the glyphs.

type PictureID

type PictureID uint16

PictureID is the ID to handle static image assets.

func Picture

func Picture(path string) PictureID

Picture declares a new picture and returns its ID.

func (PictureID) Paint

func (p PictureID) Paint(layer int16, pos XY)

Paint queues a GPU command to put a picture on the canvas.

func (PictureID) Size

func (p PictureID) Size() XY

Size returns the width and height of the picture.

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

func (a XY) Cartesian() (x, y, z float32)

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

func (a XY) Coord() coord.XY

Coord returns the floating point coordinates of the vector.

func (XY) FlipX

func (a XY) FlipX() XY

FlipX returns the vector with the sign of X flipped.

func (XY) FlipY

func (a XY) FlipY() XY

FlipY returns the vector with the sign of Y flipped.

func (XY) Minus

func (a XY) Minus(b XY) XY

Minus returns the difference with another vector.

func (XY) MinusS

func (a XY) MinusS(s int16) XY

MinusS returns the difference with the vector (s, s).

func (XY) Mod

func (a XY) Mod(s int16) XY

Mod returns the remainder (modulus) of the division by a scalar (which must be non-zero).

func (XY) ModXY

func (a XY) ModXY(b XY) XY

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

func (a XY) Null() bool

Null returns true if both coordinates are null.

func (XY) Opposite

func (a XY) Opposite() XY

Opposite returns the opposite of the vector.

func (XY) Perp

func (a XY) Perp() XY

Perp returns the vector rotated by 90 in counter-clockwise direction.

func (XY) Plus

func (a XY) Plus(b XY) XY

Plus returns the sum with another vector.

func (XY) PlusS

func (a XY) PlusS(s int16) XY

PlusS returns the sum with the vector (s, s).

func (XY) ProjX

func (a XY) ProjX() XY

ProjX returns the vector projected on the X axis (i.e. with Y nulled).

func (XY) ProjY

func (a XY) ProjY() XY

ProjY returns the vector projected on the Y axis (i.e. with X nulled).

func (XY) Slash

func (a XY) Slash(s int16) XY

Slash returns the integer quotient of the division by a scalar (which must be non-zero).

func (XY) SlashXY

func (a XY) SlashXY(b XY) XY

SlashXY returns the integer quotients of the component-wise division by another vector (of which both X and Y must be non-zero).

func (XY) Times

func (a XY) Times(s int16) XY

Times returns the product with a scalar.

func (XY) TimesXY

func (a XY) TimesXY(b XY) XY

TimesXY returns the component-wise product with another vector.

func (XY) WindowXY

func (a XY) WindowXY() window.XY

WindowXY takes coordinates in canvas space and returns them in window space.

func (XY) YX

func (a XY) YX() XY

YX returns the vector with coordinates X and Y swapped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL