| 1 |
# 2D Canvas |
| 2 |
|
| 3 |
[View full source code][code] or [view the compiled example online][online] |
| 4 |
|
| 5 |
[online]: https://rustwasm.github.io/wasm-bindgen/exbuild/canvas/ |
| 6 |
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/canvas |
| 7 |
|
| 8 |
Drawing a smiley face with the 2D canvas API. This is a port of part of [this |
| 9 |
MDN |
| 10 |
tutorial](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes#Moving_the_pen) |
| 11 |
to `web-sys`. |
| 12 |
|
| 13 |
 |
| 14 |
|
| 15 |
## `Cargo.toml` |
| 16 |
|
| 17 |
The `Cargo.toml` enables features necessary to query the DOM and work with 2D |
| 18 |
canvas. |
| 19 |
|
| 20 |
```toml |
| 21 |
{{#include ../../../examples/canvas/Cargo.toml}} |
| 22 |
``` |
| 23 |
|
| 24 |
## `src/lib.rs` |
| 25 |
|
| 26 |
Gets the `<canvas>` element, creates a 2D rendering context, and draws the |
| 27 |
smiley face. |
| 28 |
|
| 29 |
```rust |
| 30 |
{{#include ../../../examples/canvas/src/lib.rs}} |
| 31 |
``` |