Browse Source

3.14159265358979323846264338327950288419716939

master
quegzacov 2 years ago
parent
commit
d0544e1e05
  1. 12
      index.html
  2. 8
      script.js

12
index.html

@ -18,7 +18,7 @@
<h1 id="winner"></h1> <h1 id="winner"></h1>
Ajouter quelqu'un: <input id="entry" type="text" name="fname"> Ajouter quelqu'un: <input id="entry" type="text" name="fname">
<input id="submit" type="submit" value="Submit"> <input id="submit" type="submit" value="Submit">
<ul id="list_person"> <ul id="list_person" style="display: grid">
</ul> </ul>
<script> <script>
@ -27,7 +27,15 @@
names.push(document.getElementById('entry').value); names.push(document.getElementById('entry').value);
draw_roulette(200, 200, 200, names); draw_roulette(200, 200, 200, names);
let new_element = document.createElement("li"); let new_element = document.createElement("li");
let remove_button = document.createElement('button');
remove_button.innerText = "remove";
remove_button.onclick = function(){remove_person(names.length-1)};
new_element.id = names.length - 1;
remove_button.style.display = 'inline';
new_element.innerHTML = "<h2 style='display: inline'>"+names.slice(-1)+"</h2>";
new_element.appendChild(remove_button);
new_element.style.display = "inline";
document.getElementById("list_person").appendChild(new_element);
}); });
</script> </script>
</body> </body>

8
script.js

@ -2,6 +2,7 @@
function draw_roulette(x, y, r, names){ function draw_roulette(x, y, r, names){
let nb_person = names.length; let nb_person = names.length;
let chart = document.getElementById("roulette").querySelector('g'); let chart = document.getElementById("roulette").querySelector('g');
chart.innerHTML = '';
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]);
let center = new Array(x + r, y + r); let center = new Array(x + r, y + r);
@ -35,7 +36,7 @@ function draw_roulette(x, y, r, names){
function rotate(){ function rotate(){
nb_person = names.length; nb_person = names.length;
let winner = Math.random() * nb_person; let winner = Math.random() * nb_person;
let angle = Math.floor(Math.random()*15)*360 - winner * 360/nb_person; let angle = Math.floor(Math.random()* (15 - 5) + 5)*360 - winner * 360/nb_person;
let result = new Promise((resolve, reject) => { let result = new Promise((resolve, reject) => {
let i = 0; let i = 0;
let add = 0; let add = 0;
@ -67,3 +68,8 @@ function show_winner(winner){
}; };
function remove_person(id) {
names.splice(id, 1);
document.getElementById('list_person').removeChild(document.getElementById(id));
draw_roulette(200, 200, 200, names);
}
Loading…
Cancel
Save