Browse Source

3.141592653589793238462643383279502884

master
BuildTools 2 years ago
parent
commit
76d59c2ff1
  1. 3
      index.php
  2. 48
      script.js

3
index.php

@ -20,7 +20,8 @@ var_dump($res);
<g stroke="black" stroke-width=2></g>
</svg>
<script type="text/javascript">
draw_roulette(3, 200, 200, 200, ["arthur", "jimmy", "Jamel"]);
let names = new Array("arthur", "jimmy", "Jamel");
draw_roulette(200, 200, 200, names);
</script>
<button onclick="rotate(3)">Tourner</button>
</body>

48
script.js

@ -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));
};

Loading…
Cancel
Save