canvas

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package canvas defines the Canvas interface, the BufferBasedCanvas interface, and the ByteColorBuffer type which implements it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferBasedCanvas

type BufferBasedCanvas interface {
	// Canvas is a super-interface of BufferBasedCanvas.
	Canvas

	// At returns the color of the pixel at (x, y).
	//
	// Errors
	//
	// common.ErrPointOutsideCanvas:
	// Will be returned if (x, y) is outside the canvas.
	//
	At(x, y int) (color.Color, error)

	// Set sets the color of the pixel at (x, y).
	//
	// Errors
	//
	// common.ErrPointOutsideCanvas:
	// Will be returned if (x, y) is outside the canvas.
	//
	// common.ErrColorTypeNotSupported:
	// Will be returned if c is not supported by the canvas.
	//
	Set(x, y int, c color.Color) error
}

BufferBasedCanvas is a Canvas based on a buffer of color.Color.

type ByteColorBuffer

type ByteColorBuffer struct {
	// contains filtered or unexported fields
}

ByteColorBuffer is a canvas based on a buffer of color.ByteColor. It implements the Canvas interface and the BufferBasedCanvas interface.

func NewByteColorBuffer

func NewByteColorBuffer(width, height int, bgColor, fgColor color.ByteColor) (*ByteColorBuffer, error)

NewByteColorBuffer returns a new ByteColorBuffer.

Errors

common.ErrWidthOrHeightNotPositive: Will be returned if width <= 0, or height <= 0.

func (*ByteColorBuffer) At

func (cnv *ByteColorBuffer) At(x, y int) (color.Color, error)

At returns the color of the pixel at (x, y).

Errors

common.ErrPointOutsideCanvas: Will be returned if (x, y) is outside the canvas.

func (*ByteColorBuffer) BucketFill

func (cnv *ByteColorBuffer) BucketFill(x, y int, c color.Color) error

BucketFill fills the area enclosing (x, y). The pixels connecting to (x, y) having the same color as that at (x, y) are replaced by c.

Errors

common.ErrPointOutsideCanvas: Will be returned if (x, y) is outside the canvas.

common.ErrColorTypeNotSupported: Will be returned if c is not supported by the canvas.

func (*ByteColorBuffer) Dimensions

func (cnv *ByteColorBuffer) Dimensions() (width, height int)

Dimensions returns the width and height.

func (*ByteColorBuffer) DrawLine

func (cnv *ByteColorBuffer) DrawLine(x1, y1, x2, y2 int) error

DrawLine draws a horizontal or vertical line.

Errors

common.ErrPointOutsideCanvas: Will be returned if (x1, y1) or (x2, y2) is outside the canvas.

common.ErrLineNotHorizontalOrVertical: Will be returned if the line is not horizontal or vertical.

func (*ByteColorBuffer) DrawRect

func (cnv *ByteColorBuffer) DrawRect(x1, y1, x2, y2 int) error

DrawRect draws a rectangle.

Errors

common.ErrPointOutsideCanvas: Will be returned if (x1, y1) or (x2, y2) is outside the canvas.

func (*ByteColorBuffer) Pixels

func (cnv *ByteColorBuffer) Pixels() []color.ByteColor

Pixels returns the underlying pixel buffer.

func (*ByteColorBuffer) Set

func (cnv *ByteColorBuffer) Set(x, y int, c color.Color) error

Set sets the color of the pixel at (x, y).

Errors

common.ErrPointOutsideCanvas: Will be returned if (x, y) is outside the canvas.

common.ErrColorTypeNotSupported: Will be returned if c is not supported by the canvas.

type Canvas

type Canvas interface {
	// Dimensions returns the width and height.
	Dimensions() (int, int)

	// DrawLine draws a horizontal or vertical line.
	//
	// Errors
	//
	// common.ErrPointOutsideCanvas:
	// Will be returned if (x1, y1) or (x2, y2) is outside the canvas.
	//
	// common.ErrLineNotHorizontalOrVertical:
	// Will be returned if the line is not horizontal or vertical.
	//
	DrawLine(x1, y1, x2, y2 int) error

	// DrawRect draws a rectangle.
	//
	// Errors
	//
	// common.ErrPointOutsideCanvas:
	// Will be returned if (x1, y1) or (x2, y2) is outside the canvas.
	//
	DrawRect(x1, y1, x2, y2 int) error

	// BucketFill fills the area enclosing (x, y). The pixels connecting to
	// (x, y) having the same color as that at (x, y) are replaced by c.
	//
	// Errors
	//
	// common.ErrPointOutsideCanvas:
	// Will be returned if (x, y) is outside the canvas.
	//
	// common.ErrColorTypeNotSupported:
	// Will be returned if c is not supported by the canvas.
	//
	BucketFill(x, y int, c color.Color) error
}

Canvas is a finite rectangular grid which allows several drawing operations. The coordinate system is zero-based.

Jump to

Keyboard shortcuts

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