Skip to content

Instantly share code, notes, and snippets.

@wowiwo1
Last active August 26, 2016 08:43
Show Gist options
  • Save wowiwo1/b07caf19e410ee83cbabe4b1424eafbf to your computer and use it in GitHub Desktop.
Save wowiwo1/b07caf19e410ee83cbabe4b1424eafbf to your computer and use it in GitHub Desktop.
function mat_make(width, height, peak, way)
{
var arr = []
var ret = []
for (var i = 0; i < height; i++)
ret[i] = []
// init
for (var i = 0; i < width * height; i++)
arr.push('A'.charCodeAt(0))
// calc
for (var i = 0; i < width * height; i++)
{
if (i <= peak)
arr[i] += i
else if (i - 2 * peak < 0)
arr[i] += 2 * peak - i
}
// assemble
for (var j = 0; j < height; j++)
for (var i = 0; i < width; i++)
ret[j][i] = String.fromCharCode((way) ? arr[j + i * height] : arr[i + j * width])
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment