JSFiddle - React, Tailwind, and code Playground
JavaScript
var html ="";
var str = "1";
var matrixSide = 31;
var rowCount = 0;
var appendPrependStr = "";
var back = false;
for ( i = 0; i < ((matrixSide - str.length) / 2); i++) {
appendPrependStr += "0";
}
while (true) {
rowCount++;
html+= appendPrependStr + str + appendPrependStr + "<br>";
if (rowCount == matrixSide) {
break;
}
if (back) {
str = str.substring(2);
appendPrependStr += 0;
} else {
str += "11";
appendPrependStr = appendPrependStr.substring(1);
}
if (str.length >= matrixSide) {
back = !back;
}
}
document.body.innerHTML = html;