Made the spinning slightly prettier
This commit is contained in:
parent
4c3c07f01a
commit
ea44ba4440
|
@ -1,4 +1,4 @@
|
||||||
const display = [6,7,8,9]
|
const display = [5, 6,7,8,9, 10]
|
||||||
const not_pickable = [
|
const not_pickable = [
|
||||||
6,
|
6,7,8
|
||||||
]
|
]
|
32
script.js
32
script.js
|
@ -79,20 +79,31 @@ console.log(spinChart.options.rotation);
|
||||||
/* --------------- Spinning Code --------------------- */
|
/* --------------- Spinning Code --------------------- */
|
||||||
|
|
||||||
spinBtn.addEventListener("click", () => {
|
spinBtn.addEventListener("click", () => {
|
||||||
let spinAmount = 101;
|
let spinAmount = 61;
|
||||||
|
|
||||||
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 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)]
|
||||||
target_degree = Math.floor(Math.random() * (target.maxDegree - target.minDegree - 10))
|
let target_index = spinValues.findIndex(item => item.value === target.value);
|
||||||
|
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 + 1]);
|
||||||
|
|
||||||
|
let slowing_down_target = spinValues[target_index + 1];
|
||||||
|
|
||||||
console.log(target)
|
console.log(target)
|
||||||
|
|
||||||
let rotationInterval = window.setInterval(() => {
|
let rotationInterval = window.setInterval(() => {
|
||||||
spinAmount *= 0.98
|
spinAmount *= 0.99
|
||||||
spinAmount = Math.max(1, spinAmount)
|
if (slowing_down) {
|
||||||
|
spinAmount = Math.max(0.1, spinAmount)
|
||||||
|
} else {
|
||||||
|
spinAmount = Math.max(2.5, spinAmount)
|
||||||
|
}
|
||||||
|
|
||||||
spinChart.options.rotation += spinAmount;
|
spinChart.options.rotation += spinAmount;
|
||||||
spinChart.update();
|
spinChart.update();
|
||||||
|
@ -100,14 +111,23 @@ spinBtn.addEventListener("click", () => {
|
||||||
if (spinChart.options.rotation >= 360) {
|
if (spinChart.options.rotation >= 360) {
|
||||||
spinChart.options.rotation -= 360;
|
spinChart.options.rotation -= 360;
|
||||||
}
|
}
|
||||||
|
if (spinAmount <= 4 && target.minDegree - 20 <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) {
|
||||||
|
console.log(spinAmount + " Decreasing more")
|
||||||
|
slowing_down = true;
|
||||||
|
spinAmount *= 0.8
|
||||||
|
|
||||||
if (spinAmount <= 1 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) {
|
|
||||||
|
if (spinAmount <= 0.1 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) {
|
||||||
// spinChart.options.rotation = target_degree
|
// spinChart.options.rotation = target_degree
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
/* --------------- End Spin Wheel --------------------- */
|
/* --------------- End Spin Wheel --------------------- */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user