SocketCanvas

command module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 11 Imported by: 0

README

SocketCanvas

Draw to an HTMLCanvas with WebSockets. SocketCanvas is a Go application that allows other applications speak WebSockets to draw to an HTMLCanvas.

Usage

You will need to Go installed to use SocketCanvas.

# using go install
go install codeberg.org/some/SocketCanvas@latest
~/go/bin/SocketCanvas

# cloning and building
git clone https://codeberg/some/SocketCanvas
cd SocketCanvas
go run main.go

Once running it will print

2025/08/21 20:56:30 Serving on port 8888

You can then open http://localhost:8888 in the browser.

Flags
-p int
      Port number (default 8888)
-stdin
      Enables listening for commands from stdin
Drawing

To draw to the canvas that is being served, you will need a WebSocket client to send draw commands. You can try it out with wscat if you have npm. Run npx wscat --connect ws://localhost:8888/draw. Note that the route is now /draw and using the ws protocol. Alternatively, you can run the application with the -stdin flag. Then you can send the following commands:

fill 0 0 0
rect 0 0 500 500
fill 250 250 250
circle 250 250 250

The resulting image:

image

Draw Commands

The draw commands follow this grammar

<DRAW COMMAND> = <COMMAND><ARGS>
<COMMAND> = fill | clear | rect |
            circle | line | shape |
            width | height | rotate |
            translate | push | pop | 
            stroke
<ARGS> = <ARG><ARGS>
<ARG> = int | float

An overview of implemented commands.

command args description
fill RED GREEN BLUE sets the current fill color
stroke RED GREEN BLUE sets the current stroke color
clear clears the canvas
rect X Y WEIGHT HEIGHT draws a filled rectangle
circle X Y RADIUS draws a filled circle
line X1 Y1 X2 Y2 ... draws a series of lines
shape X1 Y1 X2 Y2 X3 Y3 ... draws a filled shape
width WIDTH sets the canvas width
height HEIGHT sets the canvas height
rotate DEGREES rotates canvas by DEGREES
translate X Y translates canvas by X, Y
push pushes canvas state to internal stack
pop restores last pushed canvas state

2025 © Somē Cho

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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