Created
April 5, 2019 07:40
-
-
Save mizchi/bef7e325540005fb9f3d3b87dbbecdc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use wasm_bindgen::prelude::*; | |
use wasm_bindgen::JsCast; | |
fn run() -> Result<(), JsValue> { | |
let document = web_sys::window().unwrap().document().unwrap(); | |
let canvas = document | |
.create_element("canvas") | |
.unwrap() | |
.unchecked_into::<web_sys::HtmlCanvasElement>(); | |
canvas.set_attribute("width", "400px")?; | |
canvas.set_attribute("height", "320px")?; | |
canvas.set_attribute("style", "background: #eee")?; | |
let context = canvas | |
.get_context("2d")? | |
.unwrap() | |
.unchecked_into::<web_sys::CanvasRenderingContext2d>(); | |
document.body().unwrap().append_child(&canvas)?; | |
context.translate(0.5, 0.5)?; | |
context.begin_path(); | |
context.arc(10.0, 10.0, 5.0, 0.0, std::f64::consts::PI * 2.0)?; | |
context.stroke(); | |
Ok(()) | |
} | |
#[wasm_bindgen(start)] | |
pub fn start() { | |
run().unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment