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
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();
}