add module 'shapes'
parent
59cd9727a8
commit
12f8f86a37
@ -1,16 +1,15 @@
|
|||||||
use std::f64;
|
use std::f64;
|
||||||
|
use crate::shapes::Point;
|
||||||
pub struct Point(pub f64, pub f64);
|
|
||||||
|
|
||||||
pub fn draw_circle(center: Point, radius: f64, context: &web_sys::CanvasRenderingContext2d) {
|
pub fn draw_circle(center: Point, radius: f64, context: &web_sys::CanvasRenderingContext2d) {
|
||||||
context.move_to(center.0+radius, center.1);
|
context.move_to(center.x+radius, center.y);
|
||||||
context
|
context
|
||||||
.arc(center.0, center.1, radius, 0.0, f64::consts::PI * 2.0)
|
.arc(center.x, center.y, radius, 0.0, f64::consts::PI * 2.0)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_line(p1: Point, p2: Point, context: &web_sys::CanvasRenderingContext2d) {
|
pub fn draw_line(p1: Point, p2: Point, context: &web_sys::CanvasRenderingContext2d) {
|
||||||
context.move_to(p1.0, p1.1);
|
context.move_to(p1.x, p1.y);
|
||||||
context
|
context
|
||||||
.line_to(p2.0, p2.1);
|
.line_to(p2.x, p2.y);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
pub struct Point {
|
||||||
|
pub x: f64,
|
||||||
|
pub y: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Circle {
|
||||||
|
pub center: Point,
|
||||||
|
pub radius: f64,
|
||||||
|
}
|
Loading…
Reference in New Issue