p5go

package module
v0.0.43 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 4 Imported by: 0

README

p5go

Go Reference Go Version

Go wrapper for p5.js - Create interactive graphics and animations in Go that run in the browser via WebAssembly.

Inspired by p5rb.

Installation

go get github.com/ryomak/p5go

Requirements: Go 1.22+

Quick Start

package main

import "github.com/ryomak/p5go"

func main() {
	p5go.Run("#container",
		p5go.Setup(func(c *p5go.Canvas) {
			c.CreateCanvas(400, 400)
		}),
		p5go.Draw(func(c *p5go.Canvas) {
			c.Background(220)
			c.Fill(255, 0, 0)
			c.Circle(200, 200, 50)
		}),
	)
	select {}
}

Build and run:

GOOS=js GOARCH=wasm go build -o main.wasm
# Serve with any HTTP server

Examples

See the examples directory for more:

  • Simple - Basic shapes and drawing
  • Playground - Interactive animation with mouse events

Features

  • Drawing: shapes, text, images, custom paths
  • Styling: colors, strokes, fills, transformations
  • Events: mouse and keyboard input
  • Export: save as image or animated GIF
  • Graphics buffers for layered compositions

API

For the complete API reference, see pkg.go.dev.

Common methods:

// Canvas
c.CreateCanvas(width, height)
c.Background(r, g, b)

// Shapes
c.Circle(x, y, diameter)
c.Rect(x, y, w, h)
c.Line(x1, y1, x2, y2)

// Styling
c.Fill(r, g, b)
c.Stroke(r, g, b)
c.StrokeWeight(weight)

// Transform
c.Translate(x, y)
c.Rotate(angle)
c.Push() / c.Pop()

// Events
p5go.MousePressed(handler)
p5go.KeyPressed(handler)

// Export
c.SaveCanvas(filename, ext)
c.SaveGif(filename, seconds)

Contributing

Pull requests are welcome! Many p5.js features are still being added.

Resources

Documentation

Overview

Package p5go provides a bridge between Go and p5.js.

This package allows you to create interactive graphics and animations using p5.js from Go code that compiles to WebAssembly. The package is organized into the following components:

- Constants and type definitions (constants.go) - Canvas management (canvas.go) - Lifecycle functions like Setup and Draw (lifecycle.go) - Event handlers for mouse and keyboard (events.go) - Drawing primitives and shapes (drawing.go) - Color manipulation (color.go) - Transformations (transform.go) - Mathematical functions (math.go) - Text rendering (text.go) - Pixel and image operations (pixels.go) - Input handling (input.go) - Environment and frame control (environment.go) - Helper types and structures (types.go)

Example usage:

err := p5go.Run("#app",
	p5go.Setup(func(c *p5go.Canvas) {
		c.CreateCanvas(400, 400)
	}),
	p5go.Draw(func(c *p5go.Canvas) {
		c.Background(220)
		c.Ellipse(200, 200, 50, 50)
	}),
)

Index

Constants

View Source
const (
	// Trigonometry
	PI                   = math.Pi
	HALF_PI              = math.Pi / 2
	QUARTER_PI           = math.Pi / 4
	TWO_PI               = math.Pi * 2
	TAU                  = TWO_PI
	DEGREES    AngleMode = "degrees"
	RADIANS    AngleMode = "radians"
)

Variables

This section is empty.

Functions

func Run

func Run(query string, fs ...Func) error

Run initializes the p5 p5Instance

Types

type AngleMode

type AngleMode string

AngleMode represents the angle mode

type BlendMode

type BlendMode string

BlendMode represents the blending mode

const (
	// Blend modes
	BLEND      BlendMode = "source-over"
	REMOVE     BlendMode = "destination-out"
	ADD        BlendMode = "lighter"
	DARKEST    BlendMode = "darken"
	LIGHTEST   BlendMode = "lighten"
	DIFFERENCE BlendMode = "difference"
	SUBTRACT   BlendMode = "subtract"
	EXCLUSION  BlendMode = "exclusion"
	MULTIPLY   BlendMode = "multiply"
	SCREEN     BlendMode = "screen"
	REPLACE    BlendMode = "copy"
	OVERLAY    BlendMode = "overlay"
	HARD_LIGHT BlendMode = "hard-light"
	SOFT_LIGHT BlendMode = "soft-light"
	DODGE      BlendMode = "color-dodge"
	BURN       BlendMode = "color-burn"
)

type Canvas

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

Canvas represents a p5.js canvas.

func (*Canvas) Abs

func (c *Canvas) Abs(n float64) float64

Abs returns the absolute value of the given number.

func (*Canvas) Acos

func (c *Canvas) Acos(value float64) float64

Acos returns the arccosine of a value.

func (*Canvas) Alpha

func (c *Canvas) Alpha(color js.Value) float64

Alpha returns the alpha value of a color.

func (*Canvas) AngleMode

func (c *Canvas) AngleMode(mode AngleMode)

AngleMode sets the angle mode for the canvas.

func (*Canvas) ApplyMatrix

func (c *Canvas) ApplyMatrix(a, b, c1, d, e, f float64)

ApplyMatrix applies a transformation matrix to the canvas.

func (*Canvas) Arc

func (c *Canvas) Arc(x, y, w, h, start, stop float64)

Arc draws an arc on the canvas.

func (*Canvas) Asin

func (c *Canvas) Asin(value float64) float64

Asin returns the arcsine of a value.

func (*Canvas) Atan

func (c *Canvas) Atan(value float64) float64

Atan returns the arctangent of a value.

func (*Canvas) Atan2

func (c *Canvas) Atan2(y, x float64) float64

Atan2 returns the arctangent of y/x.

func (*Canvas) Background

func (c *Canvas) Background(args ...any)

Background sets the background color of the canvas.

func (*Canvas) BeginContour

func (c *Canvas) BeginContour()

BeginContour begins recording vertices for a contour.

func (*Canvas) BeginShape

func (c *Canvas) BeginShape(kind ...ShapeType)

BeginShape begins recording vertices for a shape.

func (*Canvas) Bezier

func (c *Canvas) Bezier(x1, y1, x2, y2, x3, y3, x4, y4 float64)

Bezier draws a bezier curve on the canvas.

func (*Canvas) BezierVertex

func (c *Canvas) BezierVertex(cx1, cy1, cx2, cy2, x, y float64)

BezierVertex adds a bezier vertex to the current shape.

func (*Canvas) Blend

func (c *Canvas) Blend(sx, sy, sw, sh, dx, dy, dw, dh float64, blendMode BlendMode)

Blend blends a region of pixels using a specified blend mode.

func (*Canvas) BlendMode

func (c *Canvas) BlendMode(mode BlendMode)

BlendMode sets the blending mode for the canvas.

func (*Canvas) Blue

func (c *Canvas) Blue(color js.Value) float64

Blue returns the blue value of a color.

func (*Canvas) Box

func (c *Canvas) Box(opts ...any)

Box represents a 3D box with position and size

func (*Canvas) Brightness

func (c *Canvas) Brightness(color js.Value) float64

Brightness returns the brightness value of a color.

func (*Canvas) Ceil

func (c *Canvas) Ceil(n float64) float64

Ceil returns the smallest integer greater than or equal to the given number.

func (*Canvas) Circle

func (c *Canvas) Circle(x, y, d float64)

Circle draws a circle on the canvas.

func (*Canvas) Clear

func (c *Canvas) Clear()

Clear clears the canvas.

func (*Canvas) Close

func (c *Canvas) Close()

Close closes the current shape.

func (*Canvas) Color

func (c *Canvas) Color(args ...any) js.Value

Color creates a color object.

func (*Canvas) ColorMode

func (c *Canvas) ColorMode(mode ColorMode, max ...float64)

ColorMode sets the color mode for the canvas.

func (*Canvas) Constrain

func (c *Canvas) Constrain(n, low, high float64) float64

Constrain limits a number to be within a specified range.

func (*Canvas) Copy

func (c *Canvas) Copy(srcImage js.Value, sx, sy, sw, sh, dx, dy, dw, dh float64)

Copy copies a region of pixels from one image to another.

func (*Canvas) Cos

func (c *Canvas) Cos(value float64) float64

Cos returns the cosine of a value.

func (*Canvas) CreateCanvas

func (c *Canvas) CreateCanvas(w, h int, opts ...RendererMode)

CreateCanvas creates a new canvas with the specified width and height.

func (*Canvas) CreateCapture

func (c *Canvas) CreateCapture(kind CaptureKind) js.Value

CreateCapture creates a capture object.

func (*Canvas) CreateGraphics

func (c *Canvas) CreateGraphics(w, h float64, renderer ...any) *Canvas

CreateGraphics creates and returns a new graphics buffer.

func (*Canvas) Cursor

func (c *Canvas) Cursor(style CursorStyle)

Cursor sets the cursor style.

func (*Canvas) Curve

func (c *Canvas) Curve(x1, y1, x2, y2, x3, y3, x4, y4 float64)

Curve draws a curve on the canvas.

func (*Canvas) CurveVertex

func (c *Canvas) CurveVertex(x, y float64)

CurveVertex adds a curve vertex to the current shape.

func (*Canvas) Degrees

func (c *Canvas) Degrees(value float64) float64

Degrees converts a value from radians to degrees.

func (*Canvas) Dist

func (c *Canvas) Dist(x1, y1, x2, y2 float64) float64

Dist calculates the distance between two points.

func (*Canvas) DrawCircle

func (c *Canvas) DrawCircle(circle Circle)

DrawCircle draws a circle using a Circle struct

func (*Canvas) DrawLine

func (c *Canvas) DrawLine(line Line)

DrawLine draws a line using a Line struct

func (*Canvas) DrawRect

func (c *Canvas) DrawRect(r Rectangle)

DrawRect draws a rectangle using a Rectangle struct

func (*Canvas) DrawTriangle

func (c *Canvas) DrawTriangle(t Triangle)

DrawTriangle draws a triangle using a Triangle struct

func (*Canvas) Ellipse

func (c *Canvas) Ellipse(x, y, w, h float64)

Ellipse draws an ellipse on the canvas.

func (*Canvas) EllipseMode

func (c *Canvas) EllipseMode(mode DrawingMode)

EllipseMode sets the location from which ellipses are drawn.

func (*Canvas) EndContour

func (c *Canvas) EndContour()

EndContour ends recording vertices for a contour.

func (*Canvas) EndShape

func (c *Canvas) EndShape(mode ...ShapeType)

EndShape ends recording vertices for a shape.

func (*Canvas) Erase

func (c *Canvas) Erase(opt ...any)

Erase enables the eraser tool.

func (*Canvas) Exp

func (c *Canvas) Exp(n float64) float64

Exp returns Euler's number e raised to the power of the given number.

func (*Canvas) Fill

func (c *Canvas) Fill(args ...any)

Fill sets the fill color for shapes.

func (*Canvas) FillColor

func (c *Canvas) FillColor(color Color)

FillColor sets the fill color using a Color struct

func (*Canvas) FillRGB

func (c *Canvas) FillRGB(r, g, b float64)

FillRGB sets the fill color using RGB values

func (*Canvas) FillRGBA

func (c *Canvas) FillRGBA(r, g, b, a float64)

FillRGBA sets the fill color using RGBA values

func (*Canvas) Filter

func (c *Canvas) Filter(filterType FilterType, value ...float64)

Filter applies a filter to the canvas.

func (*Canvas) Floor

func (c *Canvas) Floor(n float64) float64

Floor returns the largest integer less than or equal to the given number.

func (*Canvas) FrameCount

func (c *Canvas) FrameCount() int

FrameCount returns the number of frames that have been displayed.

func (*Canvas) FrameRate

func (c *Canvas) FrameRate(fps float64)

FrameRate sets the frame rate for the canvas.

func (*Canvas) Get

func (c *Canvas) Get(x, y float64) js.Value

Get retrieves the color of any pixel or grabs a section of an image.

func (*Canvas) GetFrameRate

func (c *Canvas) GetFrameRate() float64

GetFrameRate returns the current frame rate.

func (*Canvas) Green

func (c *Canvas) Green(color js.Value) float64

Green returns the green value of a color.

func (*Canvas) Height

func (c *Canvas) Height() float64

Height returns the height of the canvas.

func (*Canvas) Hide

func (c *Canvas) Hide()

Hide hides the canvas.

func (*Canvas) Hue

func (c *Canvas) Hue(color js.Value) float64

Hue returns the hue value of a color.

func (*Canvas) Image

func (c *Canvas) Image(img any, opts ...any)

Image draws an image on the canvas.

func (*Canvas) IsLooping

func (c *Canvas) IsLooping() bool

IsLooping returns true if the draw loop is currently running.

func (*Canvas) Key

func (c *Canvas) Key() string

Key returns the current key being pressed.

func (*Canvas) KeyCode

func (c *Canvas) KeyCode() int

KeyCode returns the key code of the current key being pressed.

func (*Canvas) KeyIsPressed

func (c *Canvas) KeyIsPressed() bool

KeyIsPressed returns true if a key is currently pressed.

func (*Canvas) Lerp

func (c *Canvas) Lerp(start, stop, amt float64) float64

Lerp performs a linear interpolation between two values.

func (*Canvas) LerpColor

func (c *Canvas) LerpColor(c1 js.Value, c2 js.Value, amt float64) js.Value

LerpColor interpolates between two colors.

func (*Canvas) Line

func (c *Canvas) Line(x1, y1, x2, y2 float64)

Line draws a line on the canvas.

func (*Canvas) LoadImage

func (c *Canvas) LoadImage(path string) js.Value

LoadImage loads an image from the specified path.

func (*Canvas) LoadPixels

func (c *Canvas) LoadPixels()

LoadPixels loads the pixel data for the canvas into the pixels[] array.

func (*Canvas) Log

func (c *Canvas) Log(n float64) float64

Log returns the natural logarithm (base e) of the given number.

func (*Canvas) Loop

func (c *Canvas) Loop()

Loop starts the draw loop.

func (*Canvas) Mag

func (c *Canvas) Mag(x, y float64) float64

Mag calculates the magnitude of a vector.

func (*Canvas) Map

func (c *Canvas) Map(value, start1, stop1, start2, stop2 float64) float64

Map maps a value from one range to another.

func (*Canvas) Mask

func (c *Canvas) Mask(img js.Value)

Mask applies an image as a mask to the canvas.

func (*Canvas) Max

func (c *Canvas) Max(args ...float64) float64

Max returns the largest value from a list of numbers.

func (*Canvas) Min

func (c *Canvas) Min(args ...float64) float64

Min returns the smallest value from a list of numbers.

func (*Canvas) MouseButton

func (c *Canvas) MouseButton() string

MouseButton returns the current mouse button being pressed.

func (*Canvas) MouseIsPressed

func (c *Canvas) MouseIsPressed() bool

MouseIsPressed returns true if the mouse is currently pressed.

func (*Canvas) MouseX

func (c *Canvas) MouseX() float64

MouseX returns the current x-coordinate of the mouse.

func (*Canvas) MouseY

func (c *Canvas) MouseY() float64

MouseY returns the current y-coordinate of the mouse.

func (*Canvas) MovedX

func (c *Canvas) MovedX() float64

MovedX returns the amount the mouse has moved along the x-axis.

func (*Canvas) MovedY

func (c *Canvas) MovedY() float64

MovedY returns the amount the mouse has moved along the y-axis.

func (*Canvas) NoCursor

func (c *Canvas) NoCursor()

NoCursor hides the cursor.

func (*Canvas) NoErase

func (c *Canvas) NoErase()

NoErase disables the eraser tool.

func (*Canvas) NoFill

func (c *Canvas) NoFill()

NoFill disables filling shapes.

func (*Canvas) NoLoop

func (c *Canvas) NoLoop()

NoLoop stops the draw loop.

func (*Canvas) NoSmooth

func (c *Canvas) NoSmooth()

NoSmooth draws all geometry with jagged (aliased) edges.

func (*Canvas) NoStroke

func (c *Canvas) NoStroke()

NoStroke disables drawing the stroke for shapes.

func (*Canvas) Norm

func (c *Canvas) Norm(value, start, stop float64) float64

Norm normalizes a number from another range into a value between 0 and 1.

func (*Canvas) OrbitControl

func (c *Canvas) OrbitControl(opts ...any)

OrbitControl represents a control for orbiting around an object

func (*Canvas) PMouseX

func (c *Canvas) PMouseX() float64

PMouseX returns the previous x-coordinate of the mouse.

func (*Canvas) PMouseY

func (c *Canvas) PMouseY() float64

PMouseY returns the previous y-coordinate of the mouse.

func (*Canvas) Point

func (c *Canvas) Point(x, y float64, z ...float64)

Point draws a point on the canvas.

func (*Canvas) Pop

func (c *Canvas) Pop()

Pop restores the previous drawing style settings and transformations.

func (*Canvas) Pow

func (c *Canvas) Pow(n, e float64) float64

Pow returns the result of raising a number to a power.

func (*Canvas) Push

func (c *Canvas) Push()

Push saves the current drawing style settings and transformations.

func (*Canvas) QuadraticVertex

func (c *Canvas) QuadraticVertex(cx, cy, x, y float64)

QuadraticVertex draws a quadratic vertex on the canvas.

func (*Canvas) Radians

func (c *Canvas) Radians(value float64) float64

Radians converts a value from degrees to radians.

func (*Canvas) Random

func (c *Canvas) Random(min, max float64) float64

Random returns a random number between the specified min and max values.

func (*Canvas) Rect

func (c *Canvas) Rect(x, y, w, h float64)

Rect draws a rectangle on the canvas.

func (*Canvas) RectMode

func (c *Canvas) RectMode(mode DrawingMode)

RectMode sets the location from which rectangles are drawn.

func (*Canvas) Red

func (c *Canvas) Red(color js.Value) float64

Red returns the red value of a color.

func (*Canvas) Redraw

func (c *Canvas) Redraw()

Redraw redraws the canvas.

func (*Canvas) ResetMatrix

func (c *Canvas) ResetMatrix()

ResetMatrix resets the transformation matrix.

func (*Canvas) Rotate

func (c *Canvas) Rotate(angle float64)

Rotate rotates the canvas by the specified angle.

func (*Canvas) RotateX

func (c *Canvas) RotateX(angle float64)

RotateX rotates the canvas around the x-axis by the specified angle.

func (*Canvas) RotateY

func (c *Canvas) RotateY(angle float64)

RotateY rotates the canvas around the y-axis by the specified angle.

func (*Canvas) RotateZ

func (c *Canvas) RotateZ(angle float64)

RotateZ rotates the canvas around the z-axis by the specified angle.

func (*Canvas) Round

func (c *Canvas) Round(n float64) float64

Round returns the nearest integer to the given number.

func (*Canvas) Saturation

func (c *Canvas) Saturation(color js.Value) float64

Saturation returns the saturation value of a color.

func (*Canvas) Save

func (c *Canvas) Save(filename string)

Save saves the canvas as an image file.

func (*Canvas) SaveCanvas

func (c *Canvas) SaveCanvas(filename, extension string)

SaveCanvas saves the canvas as an image file.

func (*Canvas) SaveFrames

func (c *Canvas) SaveFrames(filename string, extension string, duration float64, fps float64)

SaveFrames saves a sequence of frames as image files.

func (*Canvas) SaveGif

func (c *Canvas) SaveGif(name string, second float64)

SaveGif saves the canvas as a GIF file.

func (*Canvas) Scale

func (c *Canvas) Scale(s float64)

Scale scales the canvas by the specified factor.

func (*Canvas) Set

func (c *Canvas) Set(x, y float64, color js.Value)

Set changes the color of any pixel or writes an image into the canvas.

func (*Canvas) ShearX

func (c *Canvas) ShearX(angle float64)

ShearX shears the canvas along the x-axis by the specified angle.

func (*Canvas) ShearY

func (c *Canvas) ShearY(angle float64)

ShearY shears the canvas along the y-axis by the specified angle.

func (*Canvas) Sin

func (c *Canvas) Sin(value float64) float64

Sin returns the sine of a value.

func (*Canvas) Size

func (c *Canvas) Size(width, height float64)

Size sets the size of the canvas.

func (*Canvas) Smooth

func (c *Canvas) Smooth()

Smooth draws all geometry with smooth (anti-aliased) edges.

func (*Canvas) Sq

func (c *Canvas) Sq(n float64) float64

Sq returns the square of the given number.

func (*Canvas) Sqrt

func (c *Canvas) Sqrt(n float64) float64

Sqrt returns the square root of the given number.

func (*Canvas) Square

func (c *Canvas) Square(x, y, s float64)

Square draws a square on the canvas.

func (*Canvas) Stroke

func (c *Canvas) Stroke(args ...any)

Stroke sets the stroke color for shapes.

func (*Canvas) StrokeCap

func (c *Canvas) StrokeCap(cap ShapeType)

StrokeCap sets the style of the stroke cap.

func (*Canvas) StrokeColor

func (c *Canvas) StrokeColor(color Color)

StrokeColor sets the stroke color using a Color struct

func (*Canvas) StrokeJoin

func (c *Canvas) StrokeJoin(join ShapeType)

StrokeJoin sets the style of the joints which connect line segments.

func (*Canvas) StrokeRGB

func (c *Canvas) StrokeRGB(r, g, b float64)

StrokeRGB sets the stroke color using RGB values

func (*Canvas) StrokeRGBA

func (c *Canvas) StrokeRGBA(r, g, b, a float64)

StrokeRGBA sets the stroke color using RGBA values

func (*Canvas) StrokeWeight

func (c *Canvas) StrokeWeight(weight float64)

StrokeWeight sets the weight of the stroke.

func (*Canvas) Tan

func (c *Canvas) Tan(value float64) float64

Tan returns the tangent of a value.

func (*Canvas) Text

func (c *Canvas) Text(str string, x, y float64)

Text draws text on the canvas.

func (*Canvas) TextAlign

func (c *Canvas) TextAlign(align DrawingMode)

TextAlign sets the alignment for text.

func (*Canvas) TextAscent

func (c *Canvas) TextAscent() float64

TextAscent returns the ascent of the current font.

func (*Canvas) TextDescent

func (c *Canvas) TextDescent() float64

TextDescent returns the descent of the current font.

func (*Canvas) TextFont

func (c *Canvas) TextFont(font string, size float64)

TextFont sets the font and size for text.

func (*Canvas) TextLeading

func (c *Canvas) TextLeading(leading float64)

TextLeading sets the leading for text.

func (*Canvas) TextSize

func (c *Canvas) TextSize(size float64)

TextSize sets the size for text.

func (*Canvas) TextStyle

func (c *Canvas) TextStyle(style TextStyle)

TextStyle sets the style for text.

func (*Canvas) TextWidth

func (c *Canvas) TextWidth(text string) float64

TextWidth returns the width of the specified text.

func (*Canvas) TextWrap

func (c *Canvas) TextWrap(w DrawingMode)

TextWrap sets the wrap mode for text.

func (*Canvas) Translate

func (c *Canvas) Translate(x, y float64, z ...float64)

Translate translates the canvas by the specified x and y values.

func (*Canvas) Triangle

func (c *Canvas) Triangle(x1, y1, x2, y2, x3, y3 float64)

Triangle draws a triangle on the canvas.

func (*Canvas) UpdatePixels

func (c *Canvas) UpdatePixels()

UpdatePixels updates the canvas with the data in the pixels[] array.

func (*Canvas) Validate

func (c *Canvas) Validate() error

Validate checks if the p5.js instance and required handlers are set.

func (*Canvas) Vertex

func (c *Canvas) Vertex(x, y float64, z ...float64)

Vertex adds a vertex to the current shape.

func (*Canvas) Width

func (c *Canvas) Width() float64

Width returns the width of the canvas.

func (*Canvas) WindowHeight

func (c *Canvas) WindowHeight() float64

WindowHeight returns the height of the window.

func (*Canvas) WindowWidth

func (c *Canvas) WindowWidth() float64

WindowWidth returns the width of the window.

type CaptureKind

type CaptureKind string

CaptureKind is a type that represents the kind of capture.

const (
	CaptureKindVIDEO CaptureKind = "VIDEO"
	CaptureKindIMAGE CaptureKind = "IMAGE"
)

type Circle

type Circle struct {
	Position Vector
	Diameter float64
}

Circle represents a circle with center position and diameter

type Color

type Color struct {
	R, G, B, A float64
}

Color represents a color with RGBA components

type ColorMode

type ColorMode string

ColorMode represents the color mode

const (
	// Color modes
	RGB ColorMode = "rgb"
	HSB ColorMode = "hsb"
	HSL ColorMode = "hsl"
)

type CursorStyle

type CursorStyle string

CursorStyle represents the cursor style

const (
	// Environment
	ARROW CursorStyle = "default"
	CROSS CursorStyle = "crosshair"
	HAND  CursorStyle = "pointer"
	MOVE  CursorStyle = "move"
	TEXT  CursorStyle = "text"
	WAIT  CursorStyle = "wait"
)

type DoubleClickedEvent

type DoubleClickedEvent struct {
	X, Y    float64
	Button  string
	Pressed bool
}

DoubleClickedEvent represents a double clicked event

type DoubleClickedHandler

type DoubleClickedHandler func(c *Canvas, e DoubleClickedEvent)

DoubleClickedHandler is a type for double clicked event handlers

type DrawingMode

type DrawingMode string

DrawingMode represents the drawing mode

const (
	// Drawing modes
	CORNER   DrawingMode = "corner"
	CORNERS  DrawingMode = "corners"
	RADIUS   DrawingMode = "radius"
	RIGHT    DrawingMode = "right"
	LEFT     DrawingMode = "left"
	CENTER   DrawingMode = "center"
	TOP      DrawingMode = "top"
	BOTTOM   DrawingMode = "bottom"
	BASELINE DrawingMode = "alphabetic"
)

type FilterType

type FilterType string

FilterType represents the type of filter

const (
	// Image filters
	THRESHOLD FilterType = "threshold"
	GRAY      FilterType = "gray"
	OPAQUE    FilterType = "opaque"
	INVERT    FilterType = "invert"
	POSTERIZE FilterType = "posterize"
	DILATE    FilterType = "dilate"
	ERODE     FilterType = "erode"
	BLUR      FilterType = "blur"
)

type Func

type Func func(c *Canvas)

Func is a type that represents a function that takes a Canvas pointer as an argument.

func DoubleClicked

func DoubleClicked(handler DoubleClickedHandler) Func

DoubleClicked sets the doubleClicked handler with a DoubleClickedEvent

func Draw

func Draw(handler func(c *Canvas)) Func

Draw sets the draw handler for the canvas.

func KeyPressed

func KeyPressed(handler func(c *Canvas)) Func

KeyPressed sets the keyPressed handler for the canvas.

func KeyReleased

func KeyReleased(handler func(c *Canvas)) Func

KeyReleased sets the keyReleased handler for the canvas.

func KeyTyped

func KeyTyped(handler func(c *Canvas)) Func

KeyTyped sets the keyTyped handler for the canvas.

func MouseClicked

func MouseClicked(handler MouseClickedHandler) Func

MouseClicked sets the mouseClicked handler with a MouseClickedEvent

func MouseDragged

func MouseDragged(handler MouseDraggedHandler) Func

MouseDragged sets the mouseDragged handler with a MouseDraggedEvent

func MouseMoved

func MouseMoved(handler func(c *Canvas)) Func

MouseMoved sets the mouseMoved handler for the canvas.

func MousePressed

func MousePressed(handler MousePressedHandler) Func

MousePressed sets the mousePressed handler with a MouseEvent

func MouseReleased

func MouseReleased(handler MouseReleasedHandler) Func

MouseReleased sets the mouseReleased handler with a MouseReleasedEvent

func MouseWheel

func MouseWheel(handler func(c *Canvas)) Func

MouseWheel sets the mouseWheel handler for the canvas.

func Preload

func Preload(handler func(c *Canvas)) Func

Preload sets the preload handler for the canvas.

func Setup

func Setup(handler func(c *Canvas)) Func

Setup sets the setup handler for the canvas.

type Line

type Line struct {
	Start, End Vector
}

Line represents a line with start and end points

type MouseClickedEvent

type MouseClickedEvent struct {
	X, Y    float64
	Button  string
	Pressed bool
}

MouseClickedEvent represents a mouse clicked event

type MouseClickedHandler

type MouseClickedHandler func(c *Canvas, e MouseClickedEvent)

MouseClickedHandler is a type for mouse clicked event handlers

type MouseDraggedEvent

type MouseDraggedEvent struct {
	X, Y    float64
	Button  string
	Pressed bool
}

MouseDraggedEvent represents a mouse dragged event

type MouseDraggedHandler

type MouseDraggedHandler func(c *Canvas, e MouseDraggedEvent)

MouseDraggedHandler is a type for mouse dragged event handlers

type MouseEvent

type MouseEvent struct {
	X, Y    float64
	Button  string
	Pressed bool
}

MouseEvent represents a mouse event

type MousePressedHandler

type MousePressedHandler func(c *Canvas, e MouseEvent)

MousePressedHandler is a type for mouse pressed event handlers

type MouseReleasedEvent

type MouseReleasedEvent struct {
	X, Y    float64
	Button  string
	Pressed bool
}

MouseReleasedEvent represents a mouse released event

type MouseReleasedHandler

type MouseReleasedHandler func(c *Canvas, e MouseReleasedEvent)

MouseReleasedHandler is a type for mouse released event handlers

type Orientation

type Orientation string

Orientation represents the device orientation

const (
	// Device orientation
	LANDSCAPE Orientation = "landscape"
	PORTRAIT  Orientation = "portrait"
)

type Rectangle

type Rectangle struct {
	Position Vector
	Size     Vector
}

Rectangle represents a rectangle with position and size

type RendererMode

type RendererMode string

RendererMode represents the rendering mode for the canvas

const (
	// Renderer modes
	P2D   RendererMode = "p2d"
	WEBGL RendererMode = "webgl"
)

type ShapeType

type ShapeType string

ShapeType represents the type of shape P5.jsの beginShape で使う型 https://p5js.org/reference/#/p5/beginShape "POINTS", "LINES", "TRIANGLES", "TRIANGLE_FAN", "TRIANGLE_STRIP", "QUADS", "QUAD_STRIP", "TESS"

const (
	POINTS         ShapeType = "POINTS"
	LINES          ShapeType = "LINES"
	LINE_STRIP     ShapeType = "LINE_STRIP"
	LINE_LOOP      ShapeType = "LINE_LOOP"
	TRIANGLES      ShapeType = "TRIANGLES"
	TRIANGLE_FAN   ShapeType = "TRIANGLE_FAN"
	TRIANGLE_STRIP ShapeType = "TRIANGLE_STRIP"
	QUADS          ShapeType = "QUADS"
	QUAD_STRIP     ShapeType = "QUAD_STRIP"
	TESS           ShapeType = "TESS"
	CLOSE          ShapeType = "CLOSE"
	OPEN           ShapeType = "OPEN"
	CHORD          ShapeType = "CHORD"
	PIE            ShapeType = "PIE"
	PROJECT        ShapeType = "PROJECT"
	SQUARE         ShapeType = "SQUARE"
	ROUND          ShapeType = "ROUND"
	BEVEL          ShapeType = "BEVEL"
	MITER          ShapeType = "MITER"
)

type TextStyle

type TextStyle string

TextStyle represents the style of text

const (
	// Typography
	NORMAL     TextStyle = "normal"
	ITALIC     TextStyle = "italic"
	BOLD       TextStyle = "bold"
	BOLDITALIC TextStyle = "bold italic"
)

type Triangle

type Triangle struct {
	V1, V2, V3 Vector
}

Triangle represents a triangle with three vertices

type Vector

type Vector struct {
	X, Y float64
}

Vector represents a 2D vector

type WebGLMode

type WebGLMode string

WebGLMode represents the WebGL mode

const (
	// Web GL specific
	IMMEDIATE WebGLMode = "immediate"
	IMAGE     WebGLMode = "image"
	NEAREST   WebGLMode = "nearest"
	REPEAT    WebGLMode = "repeat"
	CLAMP     WebGLMode = "clamp"
	MIRROR    WebGLMode = "mirror"
)

Directories

Path Synopsis
example
playground command
server command
simple command

Jump to

Keyboard shortcuts

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