diff --git a/src/circle.rs b/src/circle.rs index 2f9b0f4..4d7502a 100644 --- a/src/circle.rs +++ b/src/circle.rs @@ -1,11 +1,21 @@ -use crate::shapes::Shape; +use crate::shapes::*; /// An iterator containing the shapes to display -pub struct CircleShapes; +pub struct CircleShapes { + modulo: u32, + factor: u32, + position: u32, + circle: Circle, +} impl CircleShapes { - pub fn new() -> CircleShapes { - CircleShapes {} + pub fn new(modulo: u32, factor: u32, circle: Circle) -> CircleShapes { + CircleShapes { + modulo, + factor, + position: 0, + circle, + } } } @@ -13,6 +23,11 @@ impl Iterator for CircleShapes { type Item = Shape; fn next(&mut self) -> Option { - None + if self.position == 0 { + self.position += 1; + Some(Shape::Circle(self.circle)) + } else { + None + } } } diff --git a/src/lib.rs b/src/lib.rs index 699bf03..bed46d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,17 +26,19 @@ pub fn start() { context.begin_path(); - let iter = CircleShapes::new(); + let iter = CircleShapes::new(10, 2, Circle {center: Point {x: 75.0, y: 75.0}, radius: 70.0}); for shape in iter { drawing::draw_shape(shape, &context); } - + +/* drawing::draw_circle(Circle {center: Point {x: 75.0, y: 75.0}, radius: 70.0}, &context); drawing::draw_circle(Circle {center: Point {x: 75.0, y: 75.0}, radius: 35.0}, &context); drawing::draw_circle(Circle {center: Point {x: 60.0, y: 65.0}, radius: 5.0}, &context); drawing::draw_line(Line {p1: Point {x: 0.0, y: 0.0}, p2: Point {x: 150.0, y: 150.0}}, &context); drawing::draw_line(Line {p1: Point {x: 0.0, y: 150.0}, p2: Point {x: 150.0, y: 0.0}}, &context); - +*/ + context.stroke(); } diff --git a/src/shapes.rs b/src/shapes.rs index b62de6a..bc461f1 100644 --- a/src/shapes.rs +++ b/src/shapes.rs @@ -1,13 +1,16 @@ +#[derive(Copy, Clone)] pub struct Point { pub x: f64, pub y: f64, } +#[derive(Copy, Clone)] pub struct Circle { pub center: Point, pub radius: f64, } +#[derive(Copy, Clone)] pub struct Line { pub p1: Point, pub p2: Point,