add internal state field
This commit is contained in:
parent
58e5efa58d
commit
8ebc270fe7
3 changed files with 28 additions and 8 deletions
|
@ -1,11 +1,21 @@
|
||||||
use crate::shapes::Shape;
|
use crate::shapes::*;
|
||||||
|
|
||||||
/// An iterator containing the shapes to display
|
/// An iterator containing the shapes to display
|
||||||
pub struct CircleShapes;
|
pub struct CircleShapes {
|
||||||
|
modulo: u32,
|
||||||
|
factor: u32,
|
||||||
|
position: u32,
|
||||||
|
circle: Circle,
|
||||||
|
}
|
||||||
|
|
||||||
impl CircleShapes {
|
impl CircleShapes {
|
||||||
pub fn new() -> CircleShapes {
|
pub fn new(modulo: u32, factor: u32, circle: Circle) -> CircleShapes {
|
||||||
CircleShapes {}
|
CircleShapes {
|
||||||
|
modulo,
|
||||||
|
factor,
|
||||||
|
position: 0,
|
||||||
|
circle,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +23,11 @@ impl Iterator for CircleShapes {
|
||||||
type Item = Shape;
|
type Item = Shape;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
if self.position == 0 {
|
||||||
|
self.position += 1;
|
||||||
|
Some(Shape::Circle(self.circle))
|
||||||
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,17 +26,19 @@ pub fn start() {
|
||||||
|
|
||||||
context.begin_path();
|
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 {
|
for shape in iter {
|
||||||
drawing::draw_shape(shape, &context);
|
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: 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: 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_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: 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);
|
drawing::draw_line(Line {p1: Point {x: 0.0, y: 150.0}, p2: Point {x: 150.0, y: 0.0}}, &context);
|
||||||
|
*/
|
||||||
|
|
||||||
context.stroke();
|
context.stroke();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub struct Point {
|
pub struct Point {
|
||||||
pub x: f64,
|
pub x: f64,
|
||||||
pub y: f64,
|
pub y: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub struct Circle {
|
pub struct Circle {
|
||||||
pub center: Point,
|
pub center: Point,
|
||||||
pub radius: f64,
|
pub radius: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub struct Line {
|
pub struct Line {
|
||||||
pub p1: Point,
|
pub p1: Point,
|
||||||
pub p2: Point,
|
pub p2: Point,
|
||||||
|
|
Loading…
Reference in a new issue