diff --git a/src/drawing.rs b/src/drawing.rs new file mode 100644 index 0000000..cf37dad --- /dev/null +++ b/src/drawing.rs @@ -0,0 +1,9 @@ +use std::f64; + + pub fn draw_circle(center: (f64, f64), radius: f64, context: &web_sys::CanvasRenderingContext2d) { + let (x, y) = center; + context.move_to(x+radius, y); + context + .arc(x, y, radius, 0.0, f64::consts::PI * 2.0) + .unwrap(); + } diff --git a/src/lib.rs b/src/lib.rs index c898e6a..ef20f14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ -use std::f64; use wasm_bindgen::prelude::*; use wasm_bindgen::JsCast; +pub mod drawing; #[wasm_bindgen(start)] pub fn start() { @@ -20,21 +20,9 @@ pub fn start() { 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(); + drawing::draw_circle((75.0, 75.0), 70.0, &context); + drawing::draw_circle((75.0, 75.0), 35.0, &context); + drawing::draw_circle((60.0, 65.0), 5.0, &context); context.stroke(); }