добавил макросы для генерации функций типа прямо_поворот, поворот_прямо
parent
cd7249e272
commit
ee3b0f36b0
|
@ -8,7 +8,7 @@ type ImgBufU8 = ImageBuffer<Rgb<u8>, Vec<u8>>;
|
|||
type Colour = Rgb<u8>;
|
||||
type Coord = (i32, i32);
|
||||
|
||||
macro_rules! rotation_move_combo {
|
||||
macro_rules! rotation_move {
|
||||
($name:ident $rot:ident) => {
|
||||
pub fn $name(&mut self, degrees: f64, steps: u32) {
|
||||
self.$rot(degrees);
|
||||
|
@ -17,7 +17,7 @@ macro_rules! rotation_move_combo {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! move_rotation_combo {
|
||||
macro_rules! move_rotation {
|
||||
($name:ident $rot:ident) => {
|
||||
pub fn $name(&mut self, steps: u32, degrees: f64) {
|
||||
self.forward(steps);
|
||||
|
@ -92,10 +92,10 @@ impl Turtle {
|
|||
self.angle = self.angle.rem_euclid(2.0 * std::f64::consts::PI);
|
||||
}
|
||||
|
||||
rotation_move_combo!(right_forward right);
|
||||
rotation_move_combo!(left_forward left);
|
||||
move_rotation_combo!(forward_right right);
|
||||
move_rotation_combo!(forward_left left);
|
||||
rotation_move!(right_forward right);
|
||||
rotation_move!(left_forward left);
|
||||
move_rotation!(forward_right right);
|
||||
move_rotation!(forward_left left);
|
||||
|
||||
pub fn forward(&mut self, steps_count: u32) {
|
||||
let start_pos = self.pos;
|
||||
|
|
Loading…
Reference in New Issue