diff --git a/imgs/polygons/3.png b/imgs/polygons/3.png index fb3c119..2c71d03 100644 Binary files a/imgs/polygons/3.png and b/imgs/polygons/3.png differ diff --git a/imgs/polygons/4.png b/imgs/polygons/4.png index ac6f763..c570e99 100644 Binary files a/imgs/polygons/4.png and b/imgs/polygons/4.png differ diff --git a/imgs/polygons/5.png b/imgs/polygons/5.png index 7e49a90..e55a9ac 100644 Binary files a/imgs/polygons/5.png and b/imgs/polygons/5.png differ diff --git a/imgs/polygons/6.png b/imgs/polygons/6.png index 62203f2..1a78410 100644 Binary files a/imgs/polygons/6.png and b/imgs/polygons/6.png differ diff --git a/imgs/polygons/7.png b/imgs/polygons/7.png index 03e19e4..52a910a 100644 Binary files a/imgs/polygons/7.png and b/imgs/polygons/7.png differ diff --git a/src/main.rs b/src/main.rs index 45742cb..1b392a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,11 +24,11 @@ fn polygon(corners_number: u32, steps_count: u32, output_path: &'static str) { } fn main() { - polygon(3, 10, "imgs/polygons/3.png"); - polygon(4, 8, "imgs/polygons/4.png"); - polygon(5, 6, "imgs/polygons/5.png"); - polygon(6, 5, "imgs/polygons/6.png"); - polygon(7, 4, "imgs/polygons/7.png"); + polygon(3, 11, "imgs/polygons/3.png"); + polygon(4, 9, "imgs/polygons/4.png"); + polygon(5, 7, "imgs/polygons/5.png"); + polygon(6, 6, "imgs/polygons/6.png"); + polygon(7, 5, "imgs/polygons/7.png"); polygon(8, 4, "imgs/polygons/8.png"); polygon(9, 4, "imgs/polygons/9.png"); polygon(36, 1, "imgs/polygons/36.png"); diff --git a/src/turtle.rs b/src/turtle.rs index 772826d..10ccf24 100644 --- a/src/turtle.rs +++ b/src/turtle.rs @@ -99,15 +99,13 @@ impl Turtle { pub fn forward(&mut self, steps_count: u32) { let start_pos = self.pos; - - let dy = self.angle.sin() * steps_count as f64 * self.step_length as f64; - let dx = self.angle.cos() * steps_count as f64 * self.step_length as f64; + let (sin, cos) = self.angle.sin_cos(); + let step = steps_count * self.step_length; - self.set_pos(( - self.pos.0 + dx.round() as i32, - self.pos.1 + dy.round() as i32 - )); - + self.pos = ( + self.pos.0 + (cos * step as f64).round() as i32, + self.pos.1 + (sin * step as f64).round() as i32, + ); self.draw_line(start_pos, self.pos); }