добавил макросы для генерации функций типа прямо_поворот, поворот_прямо

main
serr 2025-06-25 21:08:36 +03:00
parent ee3b0f36b0
commit 29e3990ffd
7 changed files with 11 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -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");

View File

@ -99,15 +99,13 @@ impl Turtle {
pub fn forward(&mut self, steps_count: u32) {
let start_pos = self.pos;
let (sin, cos) = self.angle.sin_cos();
let step = steps_count * self.step_length;
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;
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);
}