use crate::{
position::{Pos, Distance},
color::Color, angle::Angle
};
pub type PenPos = Pos<f64>;
#[derive(PartialEq, Clone, Copy)]
pub enum PenState {
Up,
Down
}
#[derive(Clone, Copy)]
pub struct Pen {
pub thickness: f64,
pub position: PenPos,
pub color: Color,
state: PenState,
pub angle: Angle
}
impl Default for Pen {
fn default() -> Self {
Self {
thickness: 1.,
position: PenPos::default(),
color: Color::default(),
state: PenState::Down,
angle: Angle(0.)
}
}
}
impl Pen {
pub fn new<P, C>(thickness: f64, position: P, color: C) -> Self
where
P: Into<PenPos>,
C: Into<Color>
{
Self {
thickness,
position: position.into(),
color: color.into(),
state: PenState::Down,
angle: Angle(0.)
}
}
pub fn forward(&mut self, distance: Distance) {
let next_pos = self.position.next_pos_turn(
self.angle,
(0.).into(),
distance
);
self.position = next_pos;
}
pub fn backward(&mut self, distance: Distance) {
let next_pos = self.position.next_pos_turn(
self.angle,
(180.).into(),
distance
);
self.position = next_pos;
}
pub fn up(&mut self) {
self.state = PenState::Up;
}
pub fn down(&mut self) {
self.state = PenState::Down;
}
pub fn is_down(&self) -> bool {
self.state == PenState::Down
}
}