A Go+WebAssembly library for drawing on HTML5 Canvas entirely from Go code without JavaScript calls.
go-canvas is a pure Go+WebAssembly library that enables efficient drawing on HTML5 Canvas elements directly from Go code, eliminating the need for JavaScript interop. It provides an alternative to traditional WebAssembly canvas usage by handling all drawing operations natively in Go using a shadow image buffer and adaptive rendering.
Go developers building browser-based applications or games that require canvas rendering, particularly those who want to avoid JavaScript interop and maintain compile-time safety. It's also suitable for developers exploring WebAssembly with Go who need efficient canvas manipulation.
Developers choose go-canvas because it allows canvas manipulation through pure Go code rather than error-prone JavaScript syscalls, providing compile-time safety and better developer experience. It offers performance optimizations like adaptive rendering, frame rate control, and automatic DOM setup that traditional WebAssembly canvas approaches lack.
Library to use HTML5 Canvas from Go-WASM, with all drawing within go code
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Eliminates error-prone JavaScript interop by allowing all canvas drawing operations in pure Go code, as demonstrated in the README's comparison of messy JS calls vs. clean Go drawing with draw2d.
The render callback can return false to skip unnecessary buffer copies when nothing changes, saving CPU cycles and improving efficiency for static or slowly updating scenes.
Includes a maxFPS parameter to throttle redraws, preventing over-rendering and optimizing performance based on application needs, as specified in the library's start function options.
Handles canvas setup, font caching, and requestAnimationFrame callbacks automatically, reducing boilerplate code for developers, as outlined in the features list.
Relies on the draw2d library, which may not support all HTML5 Canvas API features or be as performant as native JavaScript implementations, potentially restricting advanced graphics needs.
Due to WebAssembly's current threading limitations, all drawing occurs in one thread, which can lead to performance issues for complex or long-duration render operations, as noted in the README's known issues and future considerations.
The use of an off-screen image buffer adds copying overhead each frame, which might introduce latency compared to direct canvas manipulation, especially for high-frame-rate applications.
As a niche project last updated in 2020 with unimplemented future plans (like layered canvas support), it may lack ongoing updates, community support, or comprehensive documentation, posing risks for long-term use.