periph: Index | Examples | Files | Directories

package display

import ""

Package display implements interfaces for visual output devices. These can be pixel or text based.



Package Files


type Drawer Uses

type Drawer interface {

    // ColorModel returns the device native color model.
    ColorModel() color.Model
    // Bounds returns the size of the output device.
    // Generally displays should have Min at {0, 0} but this is not guaranteed in
    // multiple displays setup or when an instance of this interface represents a
    // section of a larger logical display.
    Bounds() image.Rectangle
    // Draw updates the display with this image.
    // Only the pixels within the display boundary are updated. Partial update is
    // supported.
    // Coordinates are top-left 0,0.
    // dstRect aligns the the drawing operation in the display, enabling partial
    // update.
    // srcPts aligns the image at this offset, enabling using a subset of the
    // source image. use image.ZP/image.Point{} to take the image at its origin.
    Draw(dstRect image.Rectangle, src image.Image, srcPts image.Point) error

Drawer represents a context to display pixels on an output device. It is a write-only interface.

What Drawer represents can be as varied as a 1 bit OLED display or a strip of LED lights. The implementation keeps a single frame buffer, so that partial updates can be done.


// Make sure periph is initialized.
if _, err := host.Init(); err != nil {

// Get a display output device, like an apa102 or ssd1306. For example:
//   s, _ := spireg.Open("")
//   d, _ := apa102.New(s, &apa102.DefaultOpts)
var d display.Drawer

// Get an image. You could load a PNG. Resize it to the device display size.
img := image.NewNRGBA(d.Bounds())

// Render the image. The normal use case is:
// - Use d.Bounds() as the dstRect, to cover the whole screen.
// - Use image.ZP/image.Point{} as 'srcPts' unless you want to offset inside
//   the image.
if err := d.Draw(d.Bounds(), img, image.ZP); err != nil {


displaytestPackage displaytest contains non-hardware devices implementations for testing or emulation purpose.

Package display imports 3 packages (graph) and is imported by 16 packages. Updated 2018-06-26. Refresh now. Tools for package owners.