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.

24 lines
740 B
Rust

use std::f64;
use crate::shapes::*;
pub fn draw_circle(circle: Circle, context: &web_sys::CanvasRenderingContext2d) {
context.move_to(circle.center.x+circle.radius, circle.center.y);
context
.arc(circle.center.x, circle.center.y, circle.radius, 0.0, f64::consts::PI * 2.0)
.unwrap();
}
pub fn draw_line(line: Line, context: &web_sys::CanvasRenderingContext2d) {
context.move_to(line.p1.x, line.p1.y);
context
.line_to(line.p2.x, line.p2.y);
}
pub fn draw_shape(shape: Shape, context: &web_sys::CanvasRenderingContext2d) {
match shape {
Shape::Circle(circle) => draw_circle(circle, context),
Shape::Line(line) => draw_line(line, context),
Shape::Point(_) => (),
}
}