var instructionLengthLimit = 176; function setupDanceInstructions(parentdiv) { // style parentdiv.style.padding = "8px"; parentdiv.style.width = "354px"; var string = "\ndance instructions to be followed alone on the salt flats at 4:04 AM"; var breakLimit = 2; var breakCount = 0; for (var i = 0x0000; i < 0x000a; i += 0x0001) { var line = ""; line = printNumber(line, i); var count = dRandomInt(16); for (var i2 = 0; i2 < count; i2 ++) { if ((breakCount < breakLimit) && (dRandomFloat() < 0.1)) { // insert a block of spaces breakCount ++; var spaceCount = 8 + 8 * Math.floor(2 * dRandomFloat()); for (var i3 = 0; i3 < spaceCount; i3 ++) { line = line.concat(" "); } } if (line.length < instructionLengthLimit) line = addDanceStep(line, dRandomInt(12)); } line += "
"; // make sure we don't run over // this actually checks the height of the text as rendered by the browser var safeVersion = parentdiv.innerHTML; // store previous version (which fit) string += line; parentdiv.innerHTML = string; if (parentdiv.scrollHeight > parentdiv.clientHeight) { // revert parentdiv.innerHTML = safeVersion; } } console.log("done"); } function function4(targetDiv) { targetDiv.innerHTML = "middle of the / night last glance outside it was daylight the / new cup of coffee on the table ice cold and the milk / partially sour"; } function printNumber(string, n) { var base = 0x2776; if (n > 10) base = 0x24ff var number = base + n; string = string.concat("" + number + " "); return string; } function addDanceStep(input, n) { var base = 0x2599; var number = base + n; if (n == 9) number = 0x25c9 if (n > 9) number = 0x25d0 + (n - 0x0007); input = input.concat("" + number); return input; }