define the struct Point
This commit is contained in:
parent
cc6a0c4bce
commit
45ad11a0db
2 changed files with 17 additions and 10 deletions
|
@ -1,9 +1,15 @@
|
||||||
use std::f64;
|
use std::f64;
|
||||||
|
|
||||||
pub fn draw_circle(center: (f64, f64), radius: f64, context: &web_sys::CanvasRenderingContext2d) {
|
pub struct Point(pub f64, pub f64);
|
||||||
let (x, y) = center;
|
|
||||||
context.move_to(x+radius, y);
|
pub fn draw_circle(center: Point, radius: f64, context: &web_sys::CanvasRenderingContext2d) {
|
||||||
context
|
context.move_to(center.0+radius, center.1);
|
||||||
.arc(x, y, radius, 0.0, f64::consts::PI * 2.0)
|
context
|
||||||
.unwrap();
|
.arc(center.0, center.1, radius, 0.0, f64::consts::PI * 2.0)
|
||||||
}
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn draw_line(p1: Point, p2: Point, context: &web_sys::CanvasRenderingContext2d) {
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
pub mod drawing;
|
pub mod drawing;
|
||||||
|
use drawing::Point;
|
||||||
|
|
||||||
#[wasm_bindgen(start)]
|
#[wasm_bindgen(start)]
|
||||||
pub fn start() {
|
pub fn start() {
|
||||||
|
@ -20,9 +21,9 @@ pub fn start() {
|
||||||
|
|
||||||
context.begin_path();
|
context.begin_path();
|
||||||
|
|
||||||
drawing::draw_circle((75.0, 75.0), 70.0, &context);
|
drawing::draw_circle(Point(75.0, 75.0), 70.0, &context);
|
||||||
drawing::draw_circle((75.0, 75.0), 35.0, &context);
|
drawing::draw_circle(Point(75.0, 75.0), 35.0, &context);
|
||||||
drawing::draw_circle((60.0, 65.0), 5.0, &context);
|
drawing::draw_circle(Point(60.0, 65.0), 5.0, &context);
|
||||||
|
|
||||||
context.stroke();
|
context.stroke();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue