improved turtle Printer

This commit is contained in:
Niklas Kapelle 2023-11-15 20:39:08 +01:00
parent be89ca12bd
commit f9c10cfc0b
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -37,29 +37,32 @@ class Printer {
// Turn left or right // Turn left or right
if (x % 2 == (inverse ? 1 : 0)) { if (x % 2 == (inverse ? 1 : 0)) {
Turtle.turnRight(); Turtle.turnLeft();
Turtle.forward(); Turtle.forward();
Turtle.turnRight(); Turtle.turnLeft();
} else { } else {
Turtle.turnLeft(); Turtle.turnRight();
Turtle.forward(); Turtle.forward();
Turtle.turnLeft(); Turtle.turnRight();
} }
} }
} }
public function execute() { public function execute() {
Turtle.up(); // We place the block below us so move up.
for (i in 0...structure.height()) { for (i in 0...structure.height()) {
var layer = structure.getLayer(i); var layer = structure.getLayer(i);
var inverse = i % 2 == 0; var inverse = i % 2 == 0;
printLayer(layer, inverse); printLayer(layer, inverse);
// Don't go up on the last layer // Don't go up or turn around on the last layer
if (i != structure.height() - 1) { if (i == structure.height() - 1) {
Turtle.up(); continue;
} }
Turtle.up();
Turtle.turnLeft(); Turtle.turnLeft();
Turtle.turnLeft(); Turtle.turnLeft();
} }