Created
April 24, 2013 02:06
-
-
Save AlphaGit/5449057 to your computer and use it in GitHub Desktop.
GridCalculator -- taken from https://github.com/AlphaGit/random-javascript/blob/2bb71a1af77909d564023d66623e6f54b5c2bf80/arkanoid-canvas/arkanoid.js
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
// helper: grid calculator for coordinate system | |
function GridCalculator(realHeight, realWidth, numColumns, numRows) { | |
var self = this; | |
self.numColumns = numColumns; | |
self.numRows = numRows; | |
var getNumRows = function() { | |
return self.numRows; | |
} | |
var getNumColumns = function() { | |
return self.numColumns; | |
} | |
var getBlockWidth = function() { | |
return realWidth / numColumns; | |
}; | |
var getBlockHeight = function() { | |
return realHeight / numRows; | |
}; | |
var getBlockPosX = function(columnIndex) { | |
return columnIndex * getBlockWidth(); | |
}; | |
var getBlockPosY = function(rowIndex) { | |
return rowIndex * getBlockHeight(); | |
}; | |
var getBlockCenterPosX = function(columnIndex) { | |
return (columnIndex + 0.5) * getBlockWidth(); | |
}; | |
var getBlockCenterPosY = function(rowIndex) { | |
return (rowIndex + 0.5) * getBlockHeight(); | |
}; | |
return { | |
getBlockWidth: getBlockWidth, | |
getBlockHeight: getBlockHeight, | |
getBlockPosX: getBlockPosX, | |
getBlockPosY: getBlockPosY, | |
getBlockCenterPosX: getBlockCenterPosX, | |
getBlockCenterPosY: getBlockCenterPosY, | |
getNumRows: getNumRows, | |
getNumColumns: getNumColumns | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment