Last active
December 17, 2015 11:19
-
-
Save eloone/5601671 to your computer and use it in GitHub Desktop.
Recursive function to calculate a grid
This file contains 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
function calculate(cols, nb){ | |
_this_.cols = cols; | |
_this_.rows = Math.ceil(nb/cols); | |
_this_.rest = nb % cols; | |
_this_.boxDim = _this_.width/cols - 2*_this_.border; | |
if(_this_.boxDim <= 1){ | |
debug.exec('warn', 'Dimensions of the boxes are too small to be seen'); | |
} | |
//Recurses if the height of the resulting grid is greater than the settings height | |
if((_this_.boxDim+2*_this_.border)*_this_.rows > _this_.height){ | |
calculate(cols + 1, nb); | |
} | |
} |
This file contains 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
//We start by computing the rendered grid recursively, we want at minimum 2 columns, since it's a grid | |
//We call the recursive function to calculate the grid at the beginning of the script | |
//Once it's done, the grid is calculated | |
calculate(2, _this_.nb_items); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment