From 8c9e9db9539def0e8c54dc5b161e1954e27902e5 Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 19:35:19 +0800 Subject: [PATCH 01/10] fix 2 answers issue --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 2195c8d..82d8f80 100644 --- a/index.js +++ b/index.js @@ -296,18 +296,19 @@ function answerEntered(val) { // temp scaling: - let distance = Math.sqrt(dx ** 2 + dy ** 2)/scaleFactor; + let ; let trueDistance = Math.sqrt(dx ** 2 + dy ** 2 + dy ** 2 * 10)/scaleFactor; - let win = distance == 0; + let win = dx == 0 && dy == 0 && dz == 0; let exactDist = document.getElementById(`dist${activeGuess}`); let floor = document.getElementById(`floor${activeGuess}`); - - exactDist.innerText = `${distance.toFixed(1)}m`; + + innertext_distance = Math.sqrt(dx ** 2 + dy ** 2)/scaleFactor + exactDist.innerText = `${innertext_distance.toFixed(1)}m`; floor.innerText = `${Math.abs(dz.toFixed(0))}`; // add plus sign if positive - if (win && dz == 0) { + if (win) { console.log('win'); floor.innerText = '🎉'; exactDist.classList.toggle('invisible'); @@ -332,7 +333,7 @@ function answerEntered(val) { ans.innerText = `The answer was ${correct.name}`; ans.classList.toggle('hidden'); return; - } else{ + } else { activeGuess++; }; @@ -400,4 +401,4 @@ function getCookieValue(str) { function deleteCookies() { document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); }); -} \ No newline at end of file +} From 58cf9cf8e87950c834c07fe87d5bb57cd5d114b3 Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 19:38:12 +0800 Subject: [PATCH 02/10] oops github is not really a good editor --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 82d8f80..6947f16 100644 --- a/index.js +++ b/index.js @@ -296,15 +296,14 @@ function answerEntered(val) { // temp scaling: - let ; - let trueDistance = Math.sqrt(dx ** 2 + dy ** 2 + dy ** 2 * 10)/scaleFactor; + let trueDistance = Math.sqrt(dx ** 2 + dy ** 2 + dy ** 2 * 10) / scaleFactor; let win = dx == 0 && dy == 0 && dz == 0; let exactDist = document.getElementById(`dist${activeGuess}`); let floor = document.getElementById(`floor${activeGuess}`); - innertext_distance = Math.sqrt(dx ** 2 + dy ** 2)/scaleFactor + innerTextDistance = Math.sqrt(dx ** 2 + dy ** 2) / scaleFactor exactDist.innerText = `${innertext_distance.toFixed(1)}m`; floor.innerText = `${Math.abs(dz.toFixed(0))}`; // add plus sign if positive From 31d1d5ee06b068f494739821cece5e31bf3eba9b Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:04:52 +0800 Subject: [PATCH 03/10] sorry this is my first js code --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6947f16..e569a99 100644 --- a/index.js +++ b/index.js @@ -303,7 +303,7 @@ function answerEntered(val) { let exactDist = document.getElementById(`dist${activeGuess}`); let floor = document.getElementById(`floor${activeGuess}`); - innerTextDistance = Math.sqrt(dx ** 2 + dy ** 2) / scaleFactor + let innerTextDistance = Math.sqrt(dx ** 2 + dy ** 2) / scaleFactor exactDist.innerText = `${innertext_distance.toFixed(1)}m`; floor.innerText = `${Math.abs(dz.toFixed(0))}`; // add plus sign if positive From ac57390defdafcec9e0724561d9c8145caa80db0 Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:05:35 +0800 Subject: [PATCH 04/10] oops again --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e569a99..d6a81f3 100644 --- a/index.js +++ b/index.js @@ -304,7 +304,7 @@ function answerEntered(val) { let floor = document.getElementById(`floor${activeGuess}`); let innerTextDistance = Math.sqrt(dx ** 2 + dy ** 2) / scaleFactor - exactDist.innerText = `${innertext_distance.toFixed(1)}m`; + exactDist.innerText = `${innerTextDistance.toFixed(1)}m`; floor.innerText = `${Math.abs(dz.toFixed(0))}`; // add plus sign if positive if (win) { From 12c184ff495fcf791662d5e5f4e684947f3b2b6d Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:18:34 +0800 Subject: [PATCH 05/10] make maxDistance scale to actual maximum distance finds the largest possible maximum distance to scale against --- index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d6a81f3..3f5970f 100644 --- a/index.js +++ b/index.js @@ -193,8 +193,8 @@ let places = [ } ]; +var maxDistance = 0 let scaleFactor = 1.7353; -let maxDistance = 414; let activeGuess = 1; let win = false; let date = getDate(); @@ -314,7 +314,17 @@ function answerEntered(val) { } // set green bar: - // scale the distance up, and make lower values of distance better. MUST BE CHANGED TO FIT DATA RANGE + // scale the distance up, and make lower values of distance better + var distance; + // if maxdistance not set, set it + if (maxDistance == 0) { + for (const place of places) { + distance = (place.x - correct.x) ** 2 + (place.y - correct.y) ** 2 + 10 * (place.z - correct.z) ** 2; + if (maxDistance < distance) { + maxDistance = distance; + } + } + } distance = (maxDistance - trueDistance)/maxDistance * 100; currentElement.style = `background: linear-gradient(to right, #19a7a7 ${distance}%, #374151 ${distance}% 100%)`; @@ -324,6 +334,9 @@ function answerEntered(val) { const ans = document.getElementById('ans'); ans.innerText = `🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉`; ans.classList.toggle('hidden'); + + // clear maxDistance for next time + maxDistance = 0; return; } else if (activeGuess >= 6) { // game over @@ -331,6 +344,9 @@ function answerEntered(val) { const ans = document.getElementById('ans'); ans.innerText = `The answer was ${correct.name}`; ans.classList.toggle('hidden'); + + // clear maxDistance for next time + maxDistance = 0; return; } else { activeGuess++; From 4d43855da926acab826bac05cac6f55f2220873f Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:20:51 +0800 Subject: [PATCH 06/10] actually correct doesnt change since correct doesnt change maxDistance doesnt have to either also i forgot some semicolons --- index.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 3f5970f..4ebbdc5 100644 --- a/index.js +++ b/index.js @@ -193,7 +193,14 @@ let places = [ } ]; -var maxDistance = 0 +var maxDistance = 0; +var distance; +for (const place of places) { + distance = (place.x - correct.x) ** 2 + (place.y - correct.y) ** 2 + 10 * (place.z - correct.z) ** 2; + if (maxDistance < distance) { + maxDistance = distance; + } +} let scaleFactor = 1.7353; let activeGuess = 1; let win = false; @@ -317,14 +324,6 @@ function answerEntered(val) { // scale the distance up, and make lower values of distance better var distance; // if maxdistance not set, set it - if (maxDistance == 0) { - for (const place of places) { - distance = (place.x - correct.x) ** 2 + (place.y - correct.y) ** 2 + 10 * (place.z - correct.z) ** 2; - if (maxDistance < distance) { - maxDistance = distance; - } - } - } distance = (maxDistance - trueDistance)/maxDistance * 100; currentElement.style = `background: linear-gradient(to right, #19a7a7 ${distance}%, #374151 ${distance}% 100%)`; @@ -334,9 +333,6 @@ function answerEntered(val) { const ans = document.getElementById('ans'); ans.innerText = `🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉`; ans.classList.toggle('hidden'); - - // clear maxDistance for next time - maxDistance = 0; return; } else if (activeGuess >= 6) { // game over @@ -344,9 +340,6 @@ function answerEntered(val) { const ans = document.getElementById('ans'); ans.innerText = `The answer was ${correct.name}`; ans.classList.toggle('hidden'); - - // clear maxDistance for next time - maxDistance = 0; return; } else { activeGuess++; From 7980f59a09a0843e84b58443cb0ccc517437ba31 Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:22:16 +0800 Subject: [PATCH 07/10] move maxDistance calc below correct init --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 4ebbdc5..f6c35f4 100644 --- a/index.js +++ b/index.js @@ -193,6 +193,12 @@ let places = [ } ]; +let scaleFactor = 1.7353; +let activeGuess = 1; +let win = false; +let date = getDate(); +let correct = places[Math.floor((mulberry32(cyrb32(date))()*100000))%32]; + var maxDistance = 0; var distance; for (const place of places) { @@ -201,11 +207,6 @@ for (const place of places) { maxDistance = distance; } } -let scaleFactor = 1.7353; -let activeGuess = 1; -let win = false; -let date = getDate(); -let correct = places[Math.floor((mulberry32(cyrb32(date))()*100000))%32]; for (let i = 1; i <= 6; i++) { let element = document.getElementById(`guess${i}`); From 697a7093caf8125592336491b115750309862c43 Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:27:23 +0800 Subject: [PATCH 08/10] remove some redundant lines forgot to delete eariler --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index f6c35f4..2bd21ff 100644 --- a/index.js +++ b/index.js @@ -323,10 +323,8 @@ function answerEntered(val) { // set green bar: // scale the distance up, and make lower values of distance better - var distance; - // if maxdistance not set, set it - distance = (maxDistance - trueDistance)/maxDistance * 100; - currentElement.style = `background: linear-gradient(to right, #19a7a7 ${distance}%, #374151 ${distance}% 100%)`; + let distance_bar = (maxDistance - trueDistance)/maxDistance * 100; + currentElement.style = `background: linear-gradient(to right, #19a7a7 ${distance_bar}%, #374151 ${distance_bar}% 100%)`; document.cookie = "guess" + activeGuess.toString() + "=" + val + ";"; From eb03910b849beb1a4aa0101eb221e433998f18f3 Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:30:48 +0800 Subject: [PATCH 09/10] i forgot to sqrt and apply scaleFactor --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 2bd21ff..2979433 100644 --- a/index.js +++ b/index.js @@ -207,6 +207,7 @@ for (const place of places) { maxDistance = distance; } } +maxDistance = Math.sqrt(maxDistance) / scaleFactor; for (let i = 1; i <= 6; i++) { let element = document.getElementById(`guess${i}`); From 2bbeab6c5ff828aae02e93247f1d8b2e7894f77b Mon Sep 17 00:00:00 2001 From: notmeegoreng Date: Sun, 4 Dec 2022 20:40:15 +0800 Subject: [PATCH 10/10] sorry for so many commits github pages requires a new commit to test --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2979433..6b02c8a 100644 --- a/index.js +++ b/index.js @@ -324,7 +324,7 @@ function answerEntered(val) { // set green bar: // scale the distance up, and make lower values of distance better - let distance_bar = (maxDistance - trueDistance)/maxDistance * 100; + let distance_bar = (1 - trueDistance / maxDistance) * 100; currentElement.style = `background: linear-gradient(to right, #19a7a7 ${distance_bar}%, #374151 ${distance_bar}% 100%)`; document.cookie = "guess" + activeGuess.toString() + "=" + val + ";";