Browse Source

3.141592653589793238462643383279502884

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

3
index.php

@ -20,7 +20,8 @@ var_dump($res);
<g stroke="black" stroke-width=2></g> <g stroke="black" stroke-width=2></g>
</svg> </svg>
<script type="text/javascript"> <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> </script>
<button onclick="rotate(3)">Tourner</button> <button onclick="rotate(3)">Tourner</button>
</body> </body>

28
script.js

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

Loading…
Cancel
Save