Skip to content

Instantly share code, notes, and snippets.

@melcor76
Created November 19, 2019 12:54
Show Gist options
  • Save melcor76/0b8476b0aa8cfd92af4cfec1c46ef639 to your computer and use it in GitHub Desktop.
Save melcor76/0b8476b0aa8cfd92af4cfec1c46ef639 to your computer and use it in GitHub Desktop.
js-tetris - rotate
// Transpose matrix, p is the Piece.
for (let y = 0; y < p.shape.length; ++y) {
for (let x = 0; x < y; ++x) {
[p.shape[x][y], p.shape[y][x]] =
[p.shape[y][x], p.shape[x][y]];
}
}
// Reverse the order of the columns.
p.shape.forEach(row => row.reverse());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment