|
|
@ -1,6 +1,6 @@ |
|
|
|
|
|
|
|
function draw_roulette(nb_person, x, y, r, names){ |
|
|
|
console.log(names); |
|
|
|
function draw_roulette(x, y, r, names){ |
|
|
|
let nb_person = names.length; |
|
|
|
let chart = document.getElementById("roulette").querySelector('g'); |
|
|
|
let starting_coo = new Array(x, y + r); |
|
|
|
let text_coo = new Array(starting_coo[0] + (r/2), starting_coo[1]); |
|
|
@ -26,28 +26,36 @@ function draw_roulette(nb_person, x, y, r, names){ |
|
|
|
chart.appendChild(text); |
|
|
|
chart.innerHTML += ' '; |
|
|
|
|
|
|
|
console.log(new_path.getAttribute('d')); |
|
|
|
|
|
|
|
starting_coo = coo_arr |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function rotate(nb_person){ |
|
|
|
let angle = Math.floor(Math.random()*15)*360 + (Math.random()*nb_person)*360/nb_person; |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
let i = 0; |
|
|
|
let interval = setInterval(() => { |
|
|
|
if (i >= angle){ |
|
|
|
document.getElementById('roulette').style.transform = 'rotate('+angle+'deg)'; |
|
|
|
clearInterval(interval); |
|
|
|
resolve() |
|
|
|
} |
|
|
|
else { |
|
|
|
i += 9; |
|
|
|
console.log(i); |
|
|
|
document.getElementById('roulette').style.transform = 'rotate('+i+'deg)'; |
|
|
|
} |
|
|
|
}, 5); |
|
|
|
}) |
|
|
|
let winner = Math.random() * nb_person; |
|
|
|
let angle = Math.floor(Math.random()*15)*360 - winner * 360/nb_person; |
|
|
|
let result = new Promise((resolve, reject) => { |
|
|
|
let i = 0; |
|
|
|
let add = 0; |
|
|
|
let interval = setInterval(() => { |
|
|
|
if (i >= angle){ |
|
|
|
document.getElementById('roulette').style.transform = 'rotate('+angle+'deg)'; |
|
|
|
clearInterval(interval); |
|
|
|
resolve(names[Math.floor(winner)]); |
|
|
|
} |
|
|
|
else { |
|
|
|
if (i > angle/2){ |
|
|
|
add -= 1; |
|
|
|
} |
|
|
|
else{ |
|
|
|
add += 1; |
|
|
|
} |
|
|
|
add = Math.abs(add); |
|
|
|
i += add; |
|
|
|
document.getElementById('roulette').style.transform = 'rotate('+i+'deg)'; |
|
|
|
} |
|
|
|
}, 5); |
|
|
|
}); |
|
|
|
console.log(result); |
|
|
|
result.then((val) => console.log(val)); |
|
|
|
}; |
|
|
|