Created
July 22, 2014 02:02
-
-
Save sanx/922a5b314ae7368d936d to your computer and use it in GitHub Desktop.
rotate 2 dimensional bitmap in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rotate90 = function (orig) { | |
var rotated = []; | |
for (var colIdx = 0; colIdx < orig[0].length; colIdx++) { | |
var reverseCol = [], | |
col; | |
for (var rowIdx = 0; rowIdx < orig.length; rowIdx++) { | |
reverseCol.push(orig[rowIdx][colIdx]); | |
} | |
col = reverseCol.reverse(); | |
rotated.push(col); | |
} | |
return rotated; | |
}; | |
var bitmap = [[8,7,4,3],[6,5,8,9],[7,6,5,2],[9,8,6,7]]; | |
// rotate90(bitmap) yields: [[9,7,6,8],[8,6,5,7],[6,5,8,4],[7,2,9,3]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment