From c9fc5b0842fe88b15073ac00228d20e0fbdcf5db Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Sat, 8 Apr 2023 23:12:49 -0500 Subject: [PATCH] Get rid of redundant console.log() --- commands/drawDesign.cjs | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/commands/drawDesign.cjs b/commands/drawDesign.cjs index be478bc..495aa1b 100644 --- a/commands/drawDesign.cjs +++ b/commands/drawDesign.cjs @@ -206,5 +206,71 @@ function design4(input) { } return outputString; } +var charIterateState; +function charIterate(input) { + if (charIterateState < input.length) { + charIterateState++; + } else { + charIterateState = 0; + } + return charIterateState; +} + +function design5(input) { + let outputString = ""; + let outputLine = ""; + input += " "; + 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); + } else { + outputLine += " "; + } + } + } else { + lineHasInput = true; + outputLine += input.charAt(charIterate) + space + input + space + spaceOffset + input.charAt(charIterate); + } + + //console.log(i, j, outputLine); + if (lineHasInput) { + outputString += outputLine + "\n"; + } + outputLine = ""; + } + return outputString; +} //console.log(design4("super long test string super long test string")); //"super long test string super long test string" \ No newline at end of file