From f9c10cfc0becf51dfa71e4a9f4eefeaf3ddd46d4 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Wed, 15 Nov 2023 20:39:08 +0100 Subject: [PATCH] improved turtle Printer --- src/lib/turtle/Printer.hx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/lib/turtle/Printer.hx b/src/lib/turtle/Printer.hx index 67f9289..fe47f8d 100644 --- a/src/lib/turtle/Printer.hx +++ b/src/lib/turtle/Printer.hx @@ -37,29 +37,32 @@ class Printer { // Turn left or right if (x % 2 == (inverse ? 1 : 0)) { - Turtle.turnRight(); + Turtle.turnLeft(); Turtle.forward(); - Turtle.turnRight(); + Turtle.turnLeft(); } else { - Turtle.turnLeft(); + Turtle.turnRight(); Turtle.forward(); - Turtle.turnLeft(); + Turtle.turnRight(); } } } public function execute() { + Turtle.up(); // We place the block below us so move up. + for (i in 0...structure.height()) { var layer = structure.getLayer(i); var inverse = i % 2 == 0; printLayer(layer, inverse); - // Don't go up on the last layer - if (i != structure.height() - 1) { - Turtle.up(); + // Don't go up or turn around on the last layer + if (i == structure.height() - 1) { + continue; } + Turtle.up(); Turtle.turnLeft(); Turtle.turnLeft(); }