Browse Source

3.14159265358979323846264338327950288419

master
quegzacov 2 years ago
parent
commit
60c4dbd1f4
  1. BIN
      bdd.db
  2. 30
      index.php
  3. 54
      script.js

BIN
bdd.db

Binary file not shown.

30
index.php

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Roulette à eau</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<code>
<?php
$bdd = new SQlite3('bdd.db');
$query = $bdd -> query('SELECT * FROM Info');
$res = $query -> fetchArray();
var_dump($res);
?>
</code>
<svg id="roulette" width="800" height="800">
<g stroke="black" stroke-width=2></g>
</svg>
<script type="text/javascript">
let names = new Array("arthur", "jimmy", "Jamel");
draw_roulette(200, 200, 200, names);
</script>
<button onclick="rotate(3)">Tourner</button>
</body>
</html>

54
script.js

@ -18,6 +18,7 @@ function draw_roulette(x, y, r, names){
text.setAttribute("y", text_coo[1]);
text.setAttribute("textLength", r/2);
text.setAttribute('text-anchor', 'middle');
text.setAttribute('alignment-baseline', 'middle');
text.setAttribute("font-size", r/5)
text.setAttribute("stroke-width", "1");
text.setAttribute("transform", "rotate("+(360)/nb_person*(i+0.5)+", "+center[0]+", "+center[1]+")");
@ -31,31 +32,46 @@ function draw_roulette(x, y, r, names){
};
function rotate(nb_person){
function rotate(){
nb_person = names.length;
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)';
}
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));
result.then((val) => show_winner(val));
};
function show_winner(winner){
let h1 = document.getElementById('winner');
h1.innerText = winner;
};
function validateForm() {
let x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("Name must be filled out");
return false;
}
names.push(x);
draw_roulette(200,200,200, names);
}

Loading…
Cancel
Save