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