Takes roughly 50 degrees to slow down, so this is now hardcoded lol
This commit is contained in:
parent
de8a561eda
commit
f3fa69f65f
|
@ -1,4 +1,4 @@
|
||||||
const display = [5, 6,7,8,9, 10]
|
const display = [5,6,7,8]
|
||||||
const not_pickable = [
|
const not_pickable = [
|
||||||
6,7,8
|
6,7,8
|
||||||
]
|
]
|
47
script.js
47
script.js
|
@ -77,21 +77,21 @@ console.log(spinChart.options.rotation);
|
||||||
|
|
||||||
|
|
||||||
/* --------------- Spinning Code --------------------- */
|
/* --------------- Spinning Code --------------------- */
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
spinBtn.addEventListener("click", () => {
|
spinBtn.addEventListener("click", () => {
|
||||||
let spinAmount = 61;
|
let spinAmount = 71;
|
||||||
|
|
||||||
spinBtn.disabled = true;
|
spinBtn.disabled = true;
|
||||||
text.innerHTML = `<p>Held og lykke!</p>`;
|
text.innerHTML = `<p>Held og lykke!</p>`;
|
||||||
|
|
||||||
let slowing_down = false;
|
let slowing_down = false;
|
||||||
|
let keep_speed = false;
|
||||||
let pickable = spinValues.filter(item => !not_pickable.includes(item.value))
|
let pickable = spinValues.filter(item => !not_pickable.includes(item.value))
|
||||||
let target = pickable[Math.floor(Math.random() * pickable.length)]
|
let target = pickable[Math.floor(Math.random() * pickable.length)]
|
||||||
let target_index = spinValues.findIndex(item => item.value === target.value);
|
let target_index = spinValues.findIndex(item => item.value === target.value);
|
||||||
target_degree = Math.floor(Math.random() * (target.maxDegree - target.minDegree - 5))
|
target_degree = Math.floor(Math.random() * (target.maxDegree - target.minDegree - 5))
|
||||||
//slowing_down_degree = Math.floor(0.5 * (spinValues[target_index + 1].maxDegree - spinValues[target_index + 1].minDegree))
|
|
||||||
console.log(spinValues[target_index]);
|
console.log(spinValues[target_index]);
|
||||||
//console.log(spinValues[target_index + 1]);
|
|
||||||
|
|
||||||
let slowing_down_target = spinValues[target_index + 1];
|
let slowing_down_target = spinValues[target_index + 1];
|
||||||
|
|
||||||
|
@ -101,37 +101,56 @@ spinBtn.addEventListener("click", () => {
|
||||||
|
|
||||||
let rotationInterval = window.setInterval(() => {
|
let rotationInterval = window.setInterval(() => {
|
||||||
spinAmount *= 0.99
|
spinAmount *= 0.99
|
||||||
if (slowing_down) {
|
if (slowing_down && !keep_speed) {
|
||||||
spinAmount = Math.max(0.1, spinAmount)
|
spinAmount = Math.max(0.1, spinAmount)
|
||||||
|
} else if (keep_speed) {
|
||||||
|
spinAmount = Math.max(4, spinAmount)
|
||||||
} else {
|
} else {
|
||||||
spinAmount = Math.max(4, spinAmount)
|
spinAmount = Math.max(4, spinAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
spinChart.options.rotation += spinAmount;
|
spinChart.options.rotation += spinAmount;
|
||||||
spinChart.update();
|
spinChart.update();
|
||||||
|
|
||||||
if (spinChart.options.rotation >= 360) {
|
if (spinChart.options.rotation >= 360) {
|
||||||
spinChart.options.rotation -= 360;
|
spinChart.options.rotation -= 360;
|
||||||
}
|
}
|
||||||
if (spinAmount <= 5 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree - target_degree + (degrees/2) ) {
|
// it takes like 40-ish ticks to slow it down, so we need to compute when we need to start slowing down for this to always work
|
||||||
//console.log(target_degree);
|
// Add a check, if it is too high when it passes halfway through or something like then continue at that speed for the next round
|
||||||
|
|
||||||
|
//if (spinAmount <= 8 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree + (degrees/display.length) - target_degree + 3 ) {
|
||||||
|
if (spinAmount <= 8 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < (target.maxDegree - target_degree) + 50 ) {
|
||||||
|
console.log((360 - spinChart.options.rotation) + " ---- " + (target.maxDegree - target_degree));
|
||||||
console.log(spinAmount + " Decreasing more")
|
console.log(spinAmount + " Decreasing more")
|
||||||
slowing_down = true;
|
slowing_down = true;
|
||||||
spinAmount *= 0.9
|
spinAmount *= 0.9
|
||||||
|
counter = counter + 1;
|
||||||
if (spinAmount <= 0.1 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) {
|
if (spinAmount <= 0.1 && target.minDegree-5 <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree) {
|
||||||
spinChart.update()
|
spinChart.update()
|
||||||
text.innerHTML = `<p>Gruppe nummer ${target.value} skal præsentere!</p>`;
|
text.innerHTML = `<p>Gruppe nummer ${target.value} skal præsentere!</p>`;
|
||||||
clearInterval(rotationInterval);
|
clearInterval(rotationInterval);
|
||||||
spinBtn.disabled = false;
|
spinBtn.disabled = false;
|
||||||
} else if (target.minDegree + 1 > 360-spinChart.options.rotation) {
|
console.log("counter " + counter);
|
||||||
spinAmount = 0;
|
} else if ( spinAmount <= 1 && target.minDegree + 3 > 360-spinChart.options.rotation) {
|
||||||
console.log("halting");
|
console.log("halting " + spinAmount );
|
||||||
|
spinChart.update()
|
||||||
|
text.innerHTML = `<p>Gruppe nummer ${target.value} skal præsentere!</p>`;
|
||||||
|
clearInterval(rotationInterval);
|
||||||
|
spinBtn.disabled = false;
|
||||||
|
console.log("counter " + counter);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if ( spinAmount >= 1 && target.minDegree + 3 > 360-spinChart.options.rotation) {
|
||||||
|
keep_speed = true;
|
||||||
|
/*console.log("halting");
|
||||||
|
spinChart.update()
|
||||||
|
text.innerHTML = `<p>Gruppe nummer ${target.value} skal præsentere!</p>`;
|
||||||
|
clearInterval(rotationInterval);
|
||||||
|
spinBtn.disabled = false;
|
||||||
|
console.log("counter " + counter);*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
/* --------------- End Spin Wheel --------------------- */
|
/* --------------- End Spin Wheel --------------------- */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user