Documentation
¶
Overview ¶
Package canvas provides a 2D pixel buffer and drawing operations for HTML5 canvas.
Index ¶
- type Canvas
- func (c *Canvas) BorderCircle(midX, midY, radius, borderWidth int32)
- func (c *Canvas) CanvasHandle() dom.Handle
- func (c *Canvas) Circle(midX, midY, radius int32)
- func (c *Canvas) ClearScreen(col colour.Colour)
- func (c *Canvas) ColourBorderCircle(midX, midY, radius, borderWidth int32, col colour.Colour)
- func (c *Canvas) ColourCircle(midX, midY, radius int32, col colour.Colour)
- func (c *Canvas) ColourFilledCircle(midX, midY, radius int32, col colour.Colour)
- func (c *Canvas) ColourFilledRectangle(xStart, yStart, width, height int32, col colour.Colour)
- func (c *Canvas) ColourLine(x1, y1, x2, y2 int32, col colour.Colour)
- func (c *Canvas) ColourLinePoint(p1, p2 Point, col colour.Colour)
- func (c *Canvas) ColourPutPixel(x, y int32, col colour.Colour)
- func (c *Canvas) ColourRectangle(xStart, yStart, width, height, thickness int32, col colour.Colour)
- func (c *Canvas) FilledCircle(midX, midY, radius int32)
- func (c *Canvas) FilledRectangle(xStart, yStart, width, height int32)
- func (c *Canvas) GetColour() colour.Colour
- func (c *Canvas) GetContext2D() dom.Context2D
- func (c *Canvas) GetPixel(x, y int32) (colour.Colour, bool)
- func (c *Canvas) Height() int
- func (c *Canvas) Line(x1, y1, x2, y2 int32)
- func (c *Canvas) LinePoint(p1, p2 Point)
- func (c *Canvas) Pixels() []byte
- func (c *Canvas) PutPixel(x, y int32)
- func (c *Canvas) Rectangle(xStart, yStart, width, height, thickness int32)
- func (c *Canvas) Render()
- func (c *Canvas) SetColour(col colour.Colour)
- func (c *Canvas) Triangle(p1, p2, p3 Point)
- func (c *Canvas) Width() int
- type Point
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
------------------------------------------------------------------------------------------------ Canvas represents the in-memory pixel buffer and its associated HTML canvas.
func NewCanvas ¶
------------------------------------------------------------------------------------------------ NewCanvas creates a canvas in-memory and associates it with a new canvas element appended to the DOM element identified by parentID.
func NewOffscreenCanvas ¶ added in v1.0.2
------------------------------------------------------------------------------------------------ NewOffscreenCanvas creates a Canvas backed only by a Go pixel buffer, with no DOM or JS objects attached. Useful for benchmarking and unit testing. Calling Render() on an offscreen canvas is a no-op.
func (*Canvas) BorderCircle ¶
------------------------------------------------------------------------------------------------ BorderCircle draws a ring (annulus) at (midX, midY) with the specified radius and border width using the active color.
func (*Canvas) CanvasHandle ¶
------------------------------------------------------------------------------------------------ CanvasHandle returns the DOM handle for the underlying HTML canvas element.
func (*Canvas) Circle ¶
------------------------------------------------------------------------------------------------ Circle draws an outline circle at (midX, midY) with the specified radius using the active color. Uses the Bresenham midpoint circle algorithm — integer arithmetic only, no trigonometry.
func (*Canvas) ClearScreen ¶
------------------------------------------------------------------------------------------------ ClearScreen fills the entire canvas with the specified color.
func (*Canvas) ColourBorderCircle ¶
------------------------------------------------------------------------------------------------ ColourBorderCircle draws a ring (annulus) at (midX, midY) with the specified radius, border width, and color.
func (*Canvas) ColourCircle ¶
------------------------------------------------------------------------------------------------ ColourCircle draws an outline circle at (midX, midY) with the specified radius and color.
func (*Canvas) ColourFilledCircle ¶
------------------------------------------------------------------------------------------------ ColourFilledCircle draws a filled circle at (midX, midY) with the specified radius and color.
func (*Canvas) ColourFilledRectangle ¶
------------------------------------------------------------------------------------------------ ColourFilledRectangle draws a filled rectangle starting at (xStart, yStart) with the specified width, height, and color.
func (*Canvas) ColourLine ¶
------------------------------------------------------------------------------------------------ ColourLine draws a line from (x1, y1) to (x2, y2) with the specified color.
func (*Canvas) ColourLinePoint ¶
------------------------------------------------------------------------------------------------ ColourLinePoint draws a line between two Points with the specified color.
func (*Canvas) ColourPutPixel ¶
------------------------------------------------------------------------------------------------ ColourPutPixel draws a pixel at (x, y) with the specified color.
func (*Canvas) ColourRectangle ¶
------------------------------------------------------------------------------------------------ ColourRectangle draws an outline rectangle starting at (xStart, yStart) with the specified width, height, thickness, and color.
func (*Canvas) FilledCircle ¶
------------------------------------------------------------------------------------------------ FilledCircle draws a filled circle at (midX, midY) with the specified radius using the active color.
func (*Canvas) FilledRectangle ¶
------------------------------------------------------------------------------------------------ FilledRectangle draws a filled rectangle starting at (xStart, yStart) with the specified width and height using the active color.
func (*Canvas) GetColour ¶
------------------------------------------------------------------------------------------------ GetColour retrieves the active drawing color.
func (*Canvas) GetContext2D ¶
------------------------------------------------------------------------------------------------ GetContext2D returns a Context2D wrapper for the HTML canvas context. Panics if called on a canvas created with NewOffscreenCanvas.
func (*Canvas) GetPixel ¶
------------------------------------------------------------------------------------------------ GetPixel retrieves the color of the pixel at (x, y). It returns false if the coordinates are out of bounds.
func (*Canvas) Height ¶
------------------------------------------------------------------------------------------------ Height returns the canvas height in pixels.
func (*Canvas) Line ¶
------------------------------------------------------------------------------------------------ Line draws a 1-pixel line from (x1, y1) to (x2, y2) using Bresenham's algorithm and the active color.
func (*Canvas) LinePoint ¶
------------------------------------------------------------------------------------------------ LinePoint draws a line between two Point structures using the active color.
func (*Canvas) Pixels ¶
------------------------------------------------------------------------------------------------ Pixels returns the underlying pixel buffer slice. The slice is shared with the Canvas — writes to it are reflected immediately.
func (*Canvas) PutPixel ¶
------------------------------------------------------------------------------------------------ PutPixel draws a pixel at (x, y) using the active drawing color.
func (*Canvas) Rectangle ¶
------------------------------------------------------------------------------------------------ Rectangle draws an outline rectangle starting at (xStart, yStart) with the specified width, height, and border thickness using the active color.
func (*Canvas) Render ¶
func (c *Canvas) Render()
------------------------------------------------------------------------------------------------ Render blits the Go-side pixel buffer into JavaScript and updates the canvas. It is a no-op if the canvas was created with NewOffscreenCanvas.
func (*Canvas) SetColour ¶
------------------------------------------------------------------------------------------------ SetColour sets the active drawing color.