v0.0.0-...-1b60a0e Latest Latest

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 7 Imported by: 0



Package canvas represents a rectangular grid of Pixels.



View Source
const PixelMapTemplate = `{{ .PPMIdentifier }}
{{ .Width }} {{ .Height }}
{{ .MaxColorValue }}
{{ pixels .Pixels }}`

PixelMapTemplate is a template used for rendering a Canvas to a portable pixmap (PPM) file.


This section is empty.


This section is empty.


type Canvas

type Canvas struct {
	Width         int
	Height        int
	Pixels        [][]color.Color
	PPMIdentifier string
	MaxColorValue uint8
	MinColorValue uint8

Canvas represents a rectangular grid of Pixels.

func NewCanvas

func NewCanvas(width, height int) *Canvas

NewCanvas returns a new Canvas with the passed Width and Height.

func (*Canvas) PixelAt

func (c *Canvas) PixelAt(x, y int) (color.Color, error)

PixelAt returns the Color at the pixel located at the passed x and y values.

func (*Canvas) ToPPM

func (c *Canvas) ToPPM(writer io.Writer, goTemplate string) error

ToPPM writes the current canvas to a file in the portable pixmap (PPM) format.

func (*Canvas) ValidateInCanvasBounds

func (c *Canvas) ValidateInCanvasBounds(x, y int) error

ValidateInCanvasBounds validates that the passed x and y values fit into the pixel bounds of the canvas.

func (*Canvas) WritePixel

func (c *Canvas) WritePixel(x, y int, color color.Color) error

WritePixel writes the passed Color to the Canvas at the pixel located at the passed x and y values.

Jump to

Keyboard shortcuts

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