добавил макросы для генерации функций типа прямо_поворот, поворот_прямо
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.0 KiB |
10
src/main.rs
|
@ -24,11 +24,11 @@ fn polygon(corners_number: u32, steps_count: u32, output_path: &'static str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
polygon(3, 10, "imgs/polygons/3.png");
|
polygon(3, 11, "imgs/polygons/3.png");
|
||||||
polygon(4, 8, "imgs/polygons/4.png");
|
polygon(4, 9, "imgs/polygons/4.png");
|
||||||
polygon(5, 6, "imgs/polygons/5.png");
|
polygon(5, 7, "imgs/polygons/5.png");
|
||||||
polygon(6, 5, "imgs/polygons/6.png");
|
polygon(6, 6, "imgs/polygons/6.png");
|
||||||
polygon(7, 4, "imgs/polygons/7.png");
|
polygon(7, 5, "imgs/polygons/7.png");
|
||||||
polygon(8, 4, "imgs/polygons/8.png");
|
polygon(8, 4, "imgs/polygons/8.png");
|
||||||
polygon(9, 4, "imgs/polygons/9.png");
|
polygon(9, 4, "imgs/polygons/9.png");
|
||||||
polygon(36, 1, "imgs/polygons/36.png");
|
polygon(36, 1, "imgs/polygons/36.png");
|
||||||
|
|
|
@ -99,15 +99,13 @@ impl Turtle {
|
||||||
|
|
||||||
pub fn forward(&mut self, steps_count: u32) {
|
pub fn forward(&mut self, steps_count: u32) {
|
||||||
let start_pos = self.pos;
|
let start_pos = self.pos;
|
||||||
|
let (sin, cos) = self.angle.sin_cos();
|
||||||
let dy = self.angle.sin() * steps_count as f64 * self.step_length as f64;
|
let step = steps_count * self.step_length;
|
||||||
let dx = self.angle.cos() * steps_count as f64 * self.step_length as f64;
|
|
||||||
|
|
||||||
self.set_pos((
|
self.pos = (
|
||||||
self.pos.0 + dx.round() as i32,
|
self.pos.0 + (cos * step as f64).round() as i32,
|
||||||
self.pos.1 + dy.round() as i32
|
self.pos.1 + (sin * step as f64).round() as i32,
|
||||||
));
|
);
|
||||||
|
|
||||||
self.draw_line(start_pos, self.pos);
|
self.draw_line(start_pos, self.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|