Port enhancements from NMA
This commit is contained in:
parent
0a6e2acea5
commit
3257562ff6
164
index.html
164
index.html
@ -223,77 +223,125 @@
|
||||
}
|
||||
return outputString;
|
||||
}
|
||||
|
||||
var charIterateState;
|
||||
const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
function charIterate(input) {
|
||||
if (charIterateState == undefined) {
|
||||
charIterateState = 0;
|
||||
} else {
|
||||
if (charIterateState < (input.length - 1)) {
|
||||
charIterateState++;
|
||||
} else {
|
||||
charIterateState = 0;
|
||||
let stringLength = (input.length - 1);
|
||||
let temp = input.split('');
|
||||
for (let i = 0; i < stringLength; ++i) {
|
||||
let compareString = temp.join("");
|
||||
let stringEval = undefined, stringEvalIndex = undefined;
|
||||
while ((stringEval = surrogatePairs.exec(compareString)) !== null) {
|
||||
stringEvalIndex = stringEval.index;
|
||||
console.log("emoji is at index", stringEvalIndex);
|
||||
}
|
||||
}
|
||||
console.log(charIterateState, input.charAt(charIterateState));
|
||||
return charIterateState;
|
||||
if (stringEvalIndex == i) {
|
||||
stringLength--;
|
||||
temp.splice(i, 1);
|
||||
console.log("Decreasing stringLength variable to", stringLength);
|
||||
}
|
||||
}
|
||||
if (charIterateState == undefined) {
|
||||
//console.log("undefined! setting to zero");
|
||||
charIterateState = 0;
|
||||
} else {
|
||||
if (charIterateState < stringLength) {
|
||||
charIterateState++;
|
||||
} else {
|
||||
charIterateState = 0;
|
||||
}
|
||||
}
|
||||
//console.log(charIterateState, fixedCharAt(input, charIterateState));
|
||||
return charIterateState;
|
||||
}
|
||||
|
||||
function design5(input) {
|
||||
charIterateState = undefined;
|
||||
let outputString = "";
|
||||
let outputLine = "";
|
||||
let radius = (input.length);
|
||||
let mid = radius;
|
||||
if (mid % 2 == 1) {
|
||||
var spaceOffset = " ";
|
||||
} else {
|
||||
var spaceOffset = "";
|
||||
}
|
||||
console.log(radius, mid);
|
||||
// dist represents distance to the center
|
||||
let dist = parseFloat(0);
|
||||
let space = ""
|
||||
for (let i = 0; i < (input.length / 2); ++i) {
|
||||
space += " ";
|
||||
}
|
||||
// for horizontal movement
|
||||
var i;
|
||||
var j;
|
||||
let lineHasInput = false;
|
||||
for (i = 0; i <= 2 * radius; i++) {
|
||||
lineHasInput = false;
|
||||
if (Math.trunc(i) != mid) {
|
||||
// for vertical movement
|
||||
for (j = 0; j <= 2 * radius; j++) {
|
||||
dist = Math.sqrt(
|
||||
((i - radius) * (i - radius) * 4) + // (* 4) accounts for the offset between lines
|
||||
(j - radius) * (j - radius)
|
||||
);
|
||||
//console.log(i, j, radius, dist);
|
||||
// dist should be in the range (radius - 0.5)
|
||||
// and (radius + 0.5) to print stars(*)
|
||||
|
||||
|
||||
if (dist > radius - 1 && dist < radius + 1) { //&& dist > radius - 1
|
||||
lineHasInput = true;
|
||||
outputLine += input.charAt(charIterate(input));
|
||||
} else {
|
||||
outputLine += " ";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lineHasInput = true;
|
||||
outputLine += input.charAt(charIterate(input)) + space + input + space + spaceOffset + input.charAt(charIterate(input));
|
||||
}
|
||||
|
||||
//console.log(i, j, outputLine);
|
||||
if (lineHasInput) {
|
||||
console.log("outputLine", outputLine);
|
||||
outputString += outputLine + "<br>";
|
||||
}
|
||||
outputLine = "";
|
||||
}
|
||||
return outputString;
|
||||
} else {
|
||||
var spaceOffset = "";
|
||||
}
|
||||
console.log(radius, mid);
|
||||
// dist represents distance to the center
|
||||
let dist = parseFloat(0);
|
||||
let space = ""
|
||||
for (let i = 0; i < (input.length / 2); ++i) {
|
||||
space += " ";
|
||||
}
|
||||
// for horizontal movement
|
||||
var i;
|
||||
var j;
|
||||
let lineHasInput = false;
|
||||
for (i = 0; i <= 2 * radius; i++) {
|
||||
lineHasInput = false;
|
||||
if (Math.trunc(i) != mid) {
|
||||
// for vertical movement
|
||||
for (j = 0; j <= 2 * radius; j++) {
|
||||
dist = Math.sqrt(
|
||||
((i - radius) * (i - radius) * 4) + // (* 4) accounts for the offset between lines
|
||||
(j - radius) * (j - radius)
|
||||
);
|
||||
//console.log(i, j, radius, dist);
|
||||
// dist should be in the range (radius - 0.5)
|
||||
// and (radius + 0.5) to print stars(*)
|
||||
|
||||
|
||||
if (dist > radius - 1 && dist < radius + 1) { //&& dist > radius - 1
|
||||
lineHasInput = true;
|
||||
outputLine += "" + fixedCharAt(input, charIterate(input)); //zero-width space
|
||||
} else {
|
||||
outputLine += " ";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lineHasInput = true;
|
||||
outputLine += fixedCharAt(input, charIterate(input)) + space + input + space + spaceOffset + fixedCharAt(input, charIterate(input));
|
||||
}
|
||||
|
||||
//console.log(i, j, outputLine);
|
||||
if (lineHasInput) {
|
||||
outputString += outputLine + "<br>";
|
||||
}
|
||||
outputLine = "";
|
||||
}
|
||||
return outputString;
|
||||
}
|
||||
|
||||
// Code from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
|
||||
|
||||
function fixedCharAt(str, idx) {
|
||||
str = String(str);
|
||||
|
||||
//const surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
while (surrogatePairs.exec(str) !== null) {
|
||||
const lastIdx = surrogatePairs.lastIndex;
|
||||
if (lastIdx - 2 < idx) {
|
||||
idx++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx >= str.length || idx < 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let ret = str.charAt(idx);
|
||||
if (
|
||||
/[\uD800-\uDBFF]/.test(ret) &&
|
||||
/[\uDC00-\uDFFF]/.test(str.charAt(idx + 1))
|
||||
) {
|
||||
// Go one further, since one of the "characters" is part of a surrogate pair
|
||||
ret += str.charAt(idx + 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
</script>
|
||||
<p id="jsOutput"></p>
|
||||
<img id=riitag src="https://tag.rc24.xyz/294976590658666497/tag.max.png" alt="My RiiTag" width=1024>
|
||||
|
Loading…
Reference in New Issue
Block a user