2018-09-10 17:51:44 -07:00
|
|
|
# 2D Canvas
|
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[View full source code][code] or [view the compiled example online][online]
|
2018-09-20 16:20:42 -07:00
|
|
|
|
2018-09-20 17:54:06 -07:00
|
|
|
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/canvas/
|
2018-09-20 16:20:42 -07:00
|
|
|
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/canvas
|
|
|
|
|
2018-09-10 17:51:44 -07:00
|
|
|
Drawing a smiley face with the 2D canvas API. This is a port of part of [this
|
|
|
|
MDN
|
|
|
|
tutorial](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes#Moving_the_pen)
|
|
|
|
to `web-sys`.
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
## `Cargo.toml`
|
|
|
|
|
|
|
|
The `Cargo.toml` enables features necessary to query the DOM and work with 2D
|
|
|
|
canvas.
|
|
|
|
|
|
|
|
```toml
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/canvas/Cargo.toml}}
|
2018-09-10 17:51:44 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
## `src/lib.rs`
|
|
|
|
|
|
|
|
Gets the `<canvas>` element, creates a 2D rendering context, and draws the
|
|
|
|
smiley face.
|
|
|
|
|
|
|
|
```rust
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/canvas/src/lib.rs}}
|
2018-09-10 17:51:44 -07:00
|
|
|
```
|