Compare commits
5 Commits
12eb9d05de
...
7f8c0d154c
| Author | SHA1 | Date | |
|---|---|---|---|
|
7f8c0d154c
|
|||
|
f9c10cfc0b
|
|||
|
be89ca12bd
|
|||
|
ca79714e8d
|
|||
|
e0d4844890
|
@@ -1,5 +1,6 @@
|
||||
package bin;
|
||||
|
||||
import lua.NativeStringTools;
|
||||
import kernel.binstore.BinStore;
|
||||
import kernel.ps.ProcessHandle;
|
||||
import kernel.ps.Process;
|
||||
@@ -139,7 +140,6 @@ class Terminal implements Process {
|
||||
}
|
||||
|
||||
var commandArgs:Array<String> = args.slice(1);
|
||||
var hadInput = false;
|
||||
|
||||
var ps = getProgByName(commandName);
|
||||
if (ps == null) {
|
||||
@@ -155,17 +155,19 @@ class Terminal implements Process {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hadInput) {
|
||||
// Add a new line, so that the input is not on the same line as the command
|
||||
this.backlog.push("");
|
||||
hadInput = true;
|
||||
}
|
||||
var mfunc = NativeStringTools.gmatch(s, "(.-)(\n)");
|
||||
|
||||
for (line in s.split("\n")) {
|
||||
if (line == "") {
|
||||
while (true) {
|
||||
var found = mfunc();
|
||||
|
||||
if (found == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (found == "\n") {
|
||||
this.backlog.push("");
|
||||
} else {
|
||||
this.backlog[this.backlog.length - 1] += s;
|
||||
this.backlog.push(found);
|
||||
}
|
||||
|
||||
// Trim the backlog if it's too long
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package lib.turtle;
|
||||
|
||||
typedef Block = Bool;
|
||||
|
||||
abstract Structure(Array<Layer>) from Array<Layer> {
|
||||
public inline function getLayer(i:Int):Layer {
|
||||
return this[i];
|
||||
@@ -8,10 +10,14 @@ abstract Structure(Array<Layer>) from Array<Layer> {
|
||||
public inline function height():Int {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public function rotate():Structure {
|
||||
return [for (i in 0...height()) this[i].rotate()];
|
||||
}
|
||||
}
|
||||
|
||||
abstract Layer(Array<Array<Bool>>) from Array<Array<Bool>> {
|
||||
public inline function get(x:Int, y:Int):Bool {
|
||||
abstract Layer(Array<Array<Block>>) from Array<Array<Block>> {
|
||||
public inline function get(x:Int, y:Int):Block {
|
||||
return this[y][x];
|
||||
}
|
||||
|
||||
@@ -22,4 +28,41 @@ abstract Layer(Array<Array<Bool>>) from Array<Array<Bool>> {
|
||||
public inline function height():Int {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public function getTextRepresentation():String {
|
||||
var str = "";
|
||||
for (y in 0...height()) {
|
||||
for (x in 0...width()) {
|
||||
if (get(x, y)) {
|
||||
str += "X";
|
||||
} else {
|
||||
str += " ";
|
||||
}
|
||||
}
|
||||
str += "\n";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public function rotate():Layer {
|
||||
// Transpose the matrix (swap rows and columns)
|
||||
var transposedMatrix:Array<Array<Block>> = [];
|
||||
for (columnIndex in 0...width()) {
|
||||
var newRow:Array<Block> = [];
|
||||
for (rowIndex in 0...height()) {
|
||||
newRow.push(get(columnIndex, rowIndex));
|
||||
}
|
||||
transposedMatrix.push(newRow);
|
||||
}
|
||||
|
||||
// Reverse the order of the columns
|
||||
var rotatedMatrix:Array<Array<Block>> = [];
|
||||
for (row in transposedMatrix) {
|
||||
var rev = row.copy();
|
||||
rev.reverse();
|
||||
rotatedMatrix.push(rev);
|
||||
}
|
||||
|
||||
return rotatedMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user