Documentation
¶
Index ¶
- func Run(ctx context.Context, setup, draw func(c *Canvas), opts ...callbackOption)
- func Start(ctx context.Context, done chan struct{}, setup, draw func(c *Canvas), ...) *sync.WaitGroup
- func WithOnKey(onKey func(c *Canvas, e KeyEvent)) callbackOption
- func WithOnMouseClick(onMouseClick func(c *Canvas, e MouseEvent)) callbackOption
- func WithOnMouseMove(onMouseMove func(c *Canvas, e MouseEvent)) callbackOption
- func WithOnMouseRelease(onMouseRelease func(c *Canvas, e MouseEvent)) callbackOption
- func WithOnMouseWheel(onMouseWheel func(c *Canvas, e MouseEvent)) callbackOption
- type Canvas
- func (c *Canvas) Background(text, fg, bg string)
- func (c *Canvas) BackgroundBg(bg string)
- func (c *Canvas) BackgroundFg(fg string)
- func (c *Canvas) BackgroundText(text string)
- func (c *Canvas) Bezier(x1, y1, x2, y2, x3, y3, x4, y4 int)
- func (c *Canvas) CellModeCustom(char string)
- func (c *Canvas) CellModeDefault()
- func (c *Canvas) CellModeDouble()
- func (c *Canvas) CellPadding(char string)
- func (c *Canvas) CellPaddingDouble(char string)
- func (c *Canvas) Circle(xCenter, yCenter, r int)
- func (c *Canvas) Clear()
- func (c *Canvas) ColorHSL(h, s, l int) string
- func (c *Canvas) ColorHSV(h, s, v int) string
- func (c *Canvas) ColorRGB(r, g, b int) string
- func (c *Canvas) Debug(messages ...any)
- func (c *Canvas) DisableRendering()
- func (c *Canvas) Dist(x1, y1, x2, y2 int) float64
- func (c *Canvas) Ellipse(xCenter, yCenter, rx, ry int)
- func (c *Canvas) Exit()
- func (c *Canvas) Fill(text, fg, bg string)
- func (c *Canvas) FillBg(bg string)
- func (c *Canvas) FillFg(fg string)
- func (c *Canvas) FillText(text string)
- func (c *Canvas) Fps(fps int)
- func (c *Canvas) Get(x, y, w, h int) Image
- func (c *Canvas) Image(img Image, x, y, w, h int)
- func (c *Canvas) Line(x1, y1, x2, y2 int)
- func (c *Canvas) LoadImage(path string) Image
- func (c *Canvas) Loop()
- func (c *Canvas) LoopAngle(duration int) float64
- func (c *Canvas) Map(value, inputStart, inputEnd, outputStart, outputEnd float64) float64
- func (c *Canvas) NoCellPadding()
- func (c *Canvas) NoFill()
- func (c *Canvas) NoLoop()
- func (c *Canvas) NoStroke()
- func (c *Canvas) Noise1D(x float64) float64
- func (c *Canvas) Noise2D(x, y float64) float64
- func (c *Canvas) NoiseLoop(angle, radius float64) float64
- func (c *Canvas) NoiseLoop1D(angle, radius float64, x int) float64
- func (c *Canvas) NoiseLoop2D(angle, radius float64, x, y int) float64
- func (c *Canvas) NoiseSeed(seed int64)
- func (c *Canvas) Point(x, y int)
- func (c *Canvas) Pop()
- func (c *Canvas) Push()
- func (c *Canvas) Quad(x1, y1, x2, y2, x3, y3, x4, y4 int)
- func (c *Canvas) Random(minimum, maximum int) float64
- func (c *Canvas) RandomSeed(seed int64)
- func (c *Canvas) Rect(x, y, w, h int)
- func (c *Canvas) Redraw()
- func (c *Canvas) Rotate(angle float64)
- func (c *Canvas) SaveCanvasToGIF(filename string, duration int)
- func (c *Canvas) SaveCanvasToMP4(filename string, duration int)
- func (c *Canvas) SaveCanvasToPNG(filename string)
- func (c *Canvas) SavedCanvasFont(filename string)
- func (c *Canvas) SavedCanvasFontSize(size int)
- func (c *Canvas) Scale(scale float64)
- func (c *Canvas) Set(x, y int, cells writable)
- func (c *Canvas) Size(w, h int)
- func (c *Canvas) Square(x, y, size int)
- func (c *Canvas) Stroke(text, fg, bg string)
- func (c *Canvas) StrokeBg(bg string)
- func (c *Canvas) StrokeFg(fg string)
- func (c *Canvas) StrokeText(text string)
- func (c *Canvas) Text(text string, x, y int)
- func (c *Canvas) Translate(x, y int)
- func (c *Canvas) Triangle(x1, y1, x2, y2, x3, y3 int)
- type Cell
- type Image
- type KeyEvent
- type MouseEvent
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithOnMouseClick ¶ added in v0.8.0
func WithOnMouseClick(onMouseClick func(c *Canvas, e MouseEvent)) callbackOption
func WithOnMouseMove ¶ added in v0.8.0
func WithOnMouseMove(onMouseMove func(c *Canvas, e MouseEvent)) callbackOption
func WithOnMouseRelease ¶ added in v0.8.0
func WithOnMouseRelease(onMouseRelease func(c *Canvas, e MouseEvent)) callbackOption
func WithOnMouseWheel ¶ added in v0.8.0
func WithOnMouseWheel(onMouseWheel func(c *Canvas, e MouseEvent)) callbackOption
Types ¶
type Canvas ¶
type Canvas struct {
Width, Height int
MouseX, MouseY int
Framecount int
IsLooping bool
// contains filtered or unexported fields
}
Canvas represents a drawable area where shapes, text, and effects can be rendered.
func (*Canvas) Background ¶
Background sets the background character and colors for the entire canvas.
func (*Canvas) BackgroundBg ¶
BackgroundBg sets the background color used by the background fill.
func (*Canvas) BackgroundFg ¶
BackgroundFg sets the foreground (text) color used by the background fill.
func (*Canvas) BackgroundText ¶
BackgroundText sets the character used for the background fill.
func (*Canvas) CellModeCustom ¶ added in v0.9.0
CellModeCustom sets a specific character used for cell spacing between elements.
func (*Canvas) CellModeDefault ¶ added in v0.9.0
func (c *Canvas) CellModeDefault()
CellModeDefault disables cell mode.
func (*Canvas) CellModeDouble ¶ added in v0.9.0
func (c *Canvas) CellModeDouble()
CellModeDouble makes every cell duplicated.
func (*Canvas) CellPadding ¶
DEPRECATED: Use CellModeCustom() instead.
func (*Canvas) CellPaddingDouble ¶
DEPRECATED: Use CellModeDouble() instead.
func (*Canvas) DisableRendering ¶
func (c *Canvas) DisableRendering()
DisableRendering disables all rendering updates. Used when an error is rendered.
func (*Canvas) LoopAngle ¶ added in v0.2.0
LoopAngle returns the angular progress (in radians, range [0, 2π]) through a looping cycle of given duration in seconds.
func (*Canvas) NoCellPadding ¶ added in v0.7.0
func (c *Canvas) NoCellPadding()
DEPRECATED: Use CellModeDefault() instead.
func (*Canvas) NoStroke ¶ added in v0.6.0
func (c *Canvas) NoStroke()
NoStroke disables stroke for subsequent shapes.
func (*Canvas) Noise2D ¶
Noise2D generates 2D Perlin noise (range [0, 1]) for a given (x, y) coordinate.
func (*Canvas) NoiseLoop ¶ added in v0.2.0
NoiseLoop returns a noise value by sampling the noise on a circular path of the given radius. This is useful for creating cyclic animations or evolving patterns that repeat perfectly after one full loop.
Parameters:
- angle: the loop angle in radians, from 0 to 2π.
- radius: the radius of the circular path in noise space. the higher the radius, the more instable it gets.
Returns:
- A float64 noise value in the range [0, 1].
func (*Canvas) NoiseLoop1D ¶ added in v0.2.0
NoiseLoop1D returns a 1D noise value that loops as the angle progresses. It samples a 2D noise space using the given radius and combines it with a horizontal offset.
Parameters:
- angle: the loop angle in radians, typically from 0 to 2π.
- radius: the radius of the circular path in noise space.
- x: horizontal position to offset the noise sampling.
Returns:
- A float64 noise value in the range [0, 1].
func (*Canvas) NoiseLoop2D ¶ added in v0.2.0
NoiseLoop2D returns a 2D noise value that loops as the angle progresses. It samples a circular path in 2D noise space, offset by the (x, y) coordinates.
Parameters:
- angle: the loop angle in radians, typically from 0 to 2π.
- radius: the radius of the circular path in noise space.
- x, y: coordinates used to offset the sampled position in the noise field.
Returns:
- A float64 noise value in the range [0, 1].
func (*Canvas) RandomSeed ¶
RandomSeed sets the random number generator seed.
func (*Canvas) SaveCanvasToGIF ¶ added in v0.2.0
SaveCanvasToGIF exports the canvas to an animated gif for a given duration (in seconds).
func (*Canvas) SaveCanvasToMP4 ¶ added in v0.4.0
SaveCanvasToMP4 exports the canvas to a mp4 (h264) video for a given duration (in seconds). Depends on ffmpeg.
func (*Canvas) SaveCanvasToPNG ¶ added in v0.2.0
SaveCanvasToPNG exports the canvas to a png image file.
func (*Canvas) SavedCanvasFont ¶
SavedCanvasFont sets a custom font (tff) file used for rendering text characters in exported images generated via SaveCanvasTo...().
func (*Canvas) SavedCanvasFontSize ¶ added in v0.2.0
SavedCanvasFontSize sets the font size used for rendering text characters in exported images generated via SaveCanvas().
func (*Canvas) StrokeText ¶
StrokeText sets the character used for strokes.
type MouseEvent ¶ added in v0.5.0
type Number ¶ added in v0.10.0
type Number interface {
constraints.Integer | constraints.Float
}
