quegzacov
2 years ago
2 changed files with 14 additions and 25 deletions
@ -1,21 +1,14 @@ |
|||||
function draw_roulette(ctx, w, h, datalist){ |
|
||||
var radius = h / 2 - 5; |
|
||||
var center = new Array(w / 2, h / 2); |
|
||||
var init = 0; |
|
||||
var total = datalist.reduce((acc, value) => acc + value, init); |
|
||||
var lastend = 0; |
|
||||
var offset = Math.PI / 2; |
|
||||
for (i=0; i < datalist.length; i++){ |
|
||||
var part = datalist[i]; |
|
||||
|
|
||||
ctx.beginPath(); |
function draw_roulette(nb_person, x, y){ |
||||
ctx.fillStyle = colist[i]; |
let chart = document.getElementById("roulette") |
||||
ctx.moveTo(center[0], center[1]); |
let angle = 0; |
||||
var arcsector = Math.PI * (2 * part / total); |
for (let i=0; i < 1; i++){ |
||||
ctx.arc(center[0], center[1], radius, lastend - offset, lastend + arcsector - offset, false); |
let coo_arr = new Array(250 - 50 * Math.cos(2 * Math.PI / nb_person), 200 - 50 * Math.sin(2 * Math.PI / nb_person)); |
||||
ctx.lineTo(center[0], center[1]); |
let new_path = document.createElement("path"); |
||||
ctx.fill(); |
new_path.setAttribute('fill', 'green'); |
||||
ctx.closePath(); |
new_path.setAttribute('d', "M 200 200 A 50 50 0 0 1 " + coo_arr[0] + " " + coo_arr[1] + " L 250 200 Z"); |
||||
lastend += arcsector; |
chart.appendChild(new_path); |
||||
} |
console.log(new_path.getAttribute('d')); |
||||
} |
} |
||||
|
}; |
||||
|
|
||||
|
Loading…
Reference in new issue