Created
October 7, 2015 08:01
-
-
Save netcell/d62ae281416f42e6ee25 to your computer and use it in GitHub Desktop.
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
function getRandomShapes(width, height) { | |
var shapeArray = new Array(); | |
for (var y = 0; y < height; y++) { | |
for (var x = 0; x < width; x++) { | |
var topTab = undefined; | |
var rightTab = undefined; | |
var bottomTab = undefined; | |
var leftTab = undefined; | |
if (y == 0) | |
topTab = 0; | |
if (y == height - 1) | |
bottomTab = 0; | |
if (x == 0) | |
leftTab = 0; | |
if (x == width - 1) | |
rightTab = 0; | |
shapeArray.push( | |
({ | |
topTab: topTab, | |
rightTab: rightTab, | |
bottomTab: bottomTab, | |
leftTab: leftTab | |
}) | |
); | |
} | |
} | |
for (var y = 0; y < height; y++) { | |
for (var x = 0; x < width; x++) { | |
var shape = shapeArray[y * width + x]; | |
var shapeRight = (x < width - 1) ? | |
shapeArray[y * width + (x + 1)] : | |
undefined; | |
var shapeBottom = (y < height - 1) ? | |
shapeArray[(y + 1) * width + x] : | |
undefined; | |
shape.rightTab = (x < width - 1) ? | |
getRandomTabValue() : | |
shape.rightTab; | |
if (shapeRight) | |
shapeRight.leftTab = - shape.rightTab; | |
shape.bottomTab = (y < height - 1) ? | |
getRandomTabValue() : | |
shape.bottomTab; | |
if (shapeBottom) | |
shapeBottom.topTab = - shape.bottomTab; | |
} | |
} | |
return shapeArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment