You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
use std::f64;
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen::JsCast;
|
|
|
|
#[wasm_bindgen(start)]
|
|
pub fn start() {
|
|
let document = web_sys::window().unwrap().document().unwrap();
|
|
let canvas = document.get_element_by_id("canvas").unwrap();
|
|
let canvas: web_sys::HtmlCanvasElement = canvas
|
|
.dyn_into::<web_sys::HtmlCanvasElement>()
|
|
.map_err(|_| ())
|
|
.unwrap();
|
|
|
|
let context = canvas
|
|
.get_context("2d")
|
|
.unwrap()
|
|
.unwrap()
|
|
.dyn_into::<web_sys::CanvasRenderingContext2d>()
|
|
.unwrap();
|
|
|
|
context.begin_path();
|
|
|
|
// arc(x, y, radius, startAngle, endAngle, counterclockwise)
|
|
// Draws an arc which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle going in the given direction indicated by counterclockwise (defaulting to clockwise).
|
|
context
|
|
.arc(75.0, 75.0, 50.0, 0.0, f64::consts::PI * 2.0)
|
|
.unwrap();
|
|
|
|
context.move_to(110.0, 75.0);
|
|
context
|
|
.arc(75.0, 75.0, 35.0, 0.0, f64::consts::PI)
|
|
.unwrap();
|
|
|
|
context.move_to(65.0, 65.0);
|
|
context
|
|
.arc(60.0, 65.0, 5.0, 0.0, f64::consts::PI * 2.0)
|
|
.unwrap();
|
|
|
|
context.stroke();
|
|
}
|