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 = [
|
||||
6,
|
||||
6,7,8
|
||||
]
|
42
script.js
42
script.js
|
@ -79,20 +79,31 @@ console.log(spinChart.options.rotation);
|
|||
/* --------------- Spinning Code --------------------- */
|
||||
|
||||
spinBtn.addEventListener("click", () => {
|
||||
let spinAmount = 101;
|
||||
let spinAmount = 61;
|
||||
|
||||
spinBtn.disabled = true;
|
||||
text.innerHTML = `<p>Held og lykke!</p>`;
|
||||
|
||||
|
||||
let slowing_down = false;
|
||||
let pickable = spinValues.filter(item => !not_pickable.includes(item.value))
|
||||
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)
|
||||
|
||||
let rotationInterval = window.setInterval(() => {
|
||||
spinAmount *= 0.98
|
||||
spinAmount = Math.max(1, spinAmount)
|
||||
spinAmount *= 0.99
|
||||
if (slowing_down) {
|
||||
spinAmount = Math.max(0.1, spinAmount)
|
||||
} else {
|
||||
spinAmount = Math.max(2.5, spinAmount)
|
||||
}
|
||||
|
||||
spinChart.options.rotation += spinAmount;
|
||||
spinChart.update();
|
||||
|
@ -100,14 +111,23 @@ spinBtn.addEventListener("click", () => {
|
|||
if (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 <= 0.1 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) {
|
||||
// spinChart.options.rotation = target_degree
|
||||
spinChart.update()
|
||||
text.innerHTML = `<p>Gruppe nummer ${target.value} skal præsentere!</p>`;
|
||||
clearInterval(rotationInterval);
|
||||
spinBtn.disabled = false;
|
||||
}
|
||||
|
||||
if (spinAmount <= 1 && target.minDegree <= 360-spinChart.options.rotation && 360-spinChart.options.rotation < target.maxDegree-target_degree) {
|
||||
// spinChart.options.rotation = target_degree
|
||||
spinChart.update()
|
||||
text.innerHTML = `<p>Gruppe nummer ${target.value} skal præsentere!</p>`;
|
||||
clearInterval(rotationInterval);
|
||||
spinBtn.disabled = false;
|
||||
}
|
||||
|
||||
|
||||
}, 10);
|
||||
});
|
||||
/* --------------- End Spin Wheel --------------------- */
|
||||
|
|
Loading…
Reference in New Issue
Block a user