canvas

package
v0.0.0-...-b7a9cc5 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColoredString

func ColoredString(c Color) string

ColoredString ...

Types

type Canvas

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

Canvas represents a 2D surface of a particular size. Coordinates on this surface are zero-based. Point (x:0, y:0) is in the top left corner. Horizontal axis corresponds to X coordinate (grows to the right). Vertical axis corresponds to Y coordinate (grows to the bottom).

Example of a 2x3 canvas: |---------------| | (0,0) | (1,0) | |---------------| | (0,1) | (1,1) | |---------------| | (0,2) | (1,2) | |---------------|

func Import

func Import(s string) (*Canvas, error)

Import creates Canvas given an output of some canvas.Export() function.

func NewCanvas

func NewCanvas(w, h int) (*Canvas, bool)

NewCanvas allocates a new canvas with the given hight and width. hight and width must be bigger than zero

func (*Canvas) Circle

func (c *Canvas) Circle(center Point, r int, cl Color)

Circle draws a circle with the given center and radius.

func (*Canvas) Dot

func (c *Canvas) Dot(p Point, cl Color)

Dot paints the given point with the given color.

func (*Canvas) Export

func (c *Canvas) Export(f Format) string

Export returns a string represantation of the canvas with given format

func (*Canvas) Fill

func (c *Canvas) Fill(p Point, cl Color)

Fill fills the area with the given Point and color.

func (*Canvas) Rect

func (c *Canvas) Rect(left, right Point, cl Color)

Rect draws a rectangle given its top-left and bottom-right corners.

type Color

type Color int8

Color of a pixel in the Canvas.

const (
	White Color = iota
	Black
	Red
	Green
	Blue
	Yellow
	Magenta
	Cyan

	MaxColor
)

All possible colors.

func (Color) String

func (c Color) String() string

String ...

type Format

type Format func(c Color) string

Format ...

type Point

type Point struct {
	X int
	Y int
}

Point describes coordinates of one pixel in the Canvas.

func (*Point) String

func (p *Point) String() string

Jump to

Keyboard shortcuts

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