diff --git a/src/lib/turtle/Structure.hx b/src/lib/turtle/Structure.hx index d0d8c8f..b47f7a6 100644 --- a/src/lib/turtle/Structure.hx +++ b/src/lib/turtle/Structure.hx @@ -39,4 +39,26 @@ abstract Layer(Array>) from Array> { } return str; } + + public function rotate():Layer { + // Transpose the matrix (swap rows and columns) + var transposedMatrix:Array> = []; + for (columnIndex in 0...width()) { + var newRow:Array = []; + for (rowIndex in 0...height()) { + newRow.push(get(columnIndex, rowIndex)); + } + transposedMatrix.push(newRow); + } + + // Reverse the order of the columns + var rotatedMatrix:Array> = []; + for (row in transposedMatrix) { + var rev = row.copy(); + rev.reverse(); + rotatedMatrix.push(rev); + } + + return rotatedMatrix; + } }