You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.3 KiB

2 years ago
function draw_roulette(nb_person, x, y, r, names){
console.log(names);
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]);
let center = new Array(x + r, y + r);
2 years ago
let angle = 0;
for (let i=0; i < nb_person; i++){
let coo_arr = new Array(center[0] - r * Math.cos(2 * Math.PI / nb_person * (i+1)), center[1] - r * Math.sin(2 * Math.PI / nb_person * (i+1)));
2 years ago
let new_path = document.createElement("path");
new_path.setAttribute('fill', 'green');
new_path.setAttribute('d', "M " + starting_coo[0] + " " + starting_coo[1] + " A " + r + " " + r + " 0 0 1 " + coo_arr[0] + " " + coo_arr[1] + " L " + center[0] + " " + center[1] + " Z");
let text = document.createElement("text");
text.innerText = names[i];
text.setAttribute("x", text_coo[0]);
text.setAttribute("y", text_coo[1]);
text.setAttribute("textLength", r/2);
text.setAttribute('text-anchor', '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]+")");
2 years ago
chart.appendChild(new_path);
chart.appendChild(text);
2 years ago
chart.innerHTML += ' ';
2 years ago
console.log(new_path.getAttribute('d'));
starting_coo = coo_arr
2 years ago
}
2 years ago
};