TwoRS
Easily render 2D graphics in a canvas - entirely powered by Rust!!! 🦀
😎 Why Rust/WASM?
It's use case is either the reuse of code written in another language or to offload heavy computations to the near-native execution speeds of WASM.
However this is not free - traversing the WASM boundary means going trough some glue code and copying data from JS to the WASM module memory and back. In the case of strings it's even more expensive - because JS strings are UTF-16 and Rust strings use UTF-8 any string passtrough needs to go trough a copy AND a re-encode.
twors doesn't have any complicated physics to offload to WASM at this point in time - neither
is it making use of some advanced pre-existing Rust library. So why Rust then?
Simply because Rust is the best!!!
⚡ Quick start
The examples/playground crate in this repo contains basic code for a moving rectangle and some input
handling - there are two ways to run it:
-
Experiment by modifying
examples/playgroundand running the code:# compile, build the WASM module, run a HTTP server - rinse and repeat automatically on code changes -
Set up your own crate similarly to
examples/playgroundexample by visiting the quick start guide
📚 Docs
- Refer to the docs after you have a working setup to experiment with
📝 Roadmap
- Adaptive canvas resolution on resize
- Delta time
- Keyboard and mouse input handling
- Component system (with
init()andupdate()lifecycle methods) - Transform (with inheritance) - translate, scale
- Collision detection
- Bezier curves
- FPS benchmark
💻 Development
Experiments and manual testing are to be done in the examples/playground crate.
# convenience scripts - see "Makefile.toml" for full list of commands
# run local pre-commit checks - will be run on "build" automatically
# other commands
Notes
- Make sure to use
wasm_assert!instead ofassert!in non-test code to see error messages in the browser console.