Make circle more circular
This commit is contained in:
parent
648bf44864
commit
79064f4b3a
@ -153,14 +153,15 @@ function design3(input) {
|
||||
|
||||
function design4(input) {
|
||||
let outputString = "";
|
||||
let radius = input.length +1;
|
||||
let outputLine = "";
|
||||
let radius = (input.length + 1);
|
||||
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 = ""
|
||||
@ -168,33 +169,42 @@ function design4(input) {
|
||||
space += " ";
|
||||
}
|
||||
// for horizontal movement
|
||||
for (let i = 0; i <= 2 * radius; i++) {
|
||||
if (i != mid) {
|
||||
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 (let j = 0; j <= 2 * radius; j++) {
|
||||
|
||||
for (j = 0; j <= 2 * radius; j++) {
|
||||
dist = Math.sqrt(
|
||||
(i - radius) * (i - radius) +
|
||||
(j - (radius / 2)) * (j - (radius / 2))
|
||||
((i - radius) * (i - radius) * 4) +
|
||||
(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 - 0.5 && dist < radius + 0.5) {
|
||||
outputString += "*";
|
||||
|
||||
if (dist > radius - 1 && dist < radius + 1) { //&& dist > radius - 1
|
||||
lineHasInput = true;
|
||||
outputLine += "·";
|
||||
} else {
|
||||
outputString += " ";
|
||||
outputLine += " ";
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
outputString += "*" + space + input + space + spaceOffset + "*";
|
||||
lineHasInput = true;
|
||||
outputLine += "·" + space + input + space + spaceOffset + "·";
|
||||
}
|
||||
|
||||
|
||||
outputString += "\n";
|
||||
//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"
|
Loading…
Reference in New Issue
Block a user