1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| <html> <body> <canvas id="box" width="500" height="500"></canvas> </body> <script> const colors = [ "red", "#FAFAD2", "#9ACD32", "#FFE4B5", "#FFFACD", "#B2DFEE", "#E1BEE7", "#F8BBD0", "#19CAAD", "#FFDEAD", ];
function getArcMidpoint(center, radius, startAngle, endAngle) { var x = center.x + radius * Math.cos((startAngle + endAngle) / 2); var y = center.y + radius * Math.sin((startAngle + endAngle) / 2); return { x: x, y: y }; } function renderArc() { const length = 10; const canvas = document.getElementById('box'); const ctx = canvas.getContext('2d'); const x = canvas.width * .5; const y = canvas.height * .5; const radius = canvas.width * .5; let beginAngel = -(90 + (360 / length) / 2) * Math.PI / 180; for (let i=0;i< length;i+=1) { ctx.beginPath(); ctx.save(); ctx.fillStyle = colors[i]; ctx.moveTo(x, y); const tempAngle = 1 / length * 360 * Math.PI / 180; const endAngel = tempAngle + beginAngel; ctx.arc(x, y, radius, beginAngel, endAngel); ctx.fill(); ctx.restore(); ctx.save(); ctx.fillStyle = 'black'; ctx.font = '50px Aria'; ctx.fontWeight = '500'; const point = getArcMidpoint({x, y}, 200, beginAngel, endAngel); ctx.fillText(`${i + 1}`, point.x - 10, point.y + 10); ctx.restore(); beginAngel = endAngel; } }
</script> <style type="text/css"> body { display: flex; align-items: center; justify-content: center; border: none; outline: none; } .outer { width: 200px; height: 400px; border-radius: 0 200px 200px 0; background-color: blue; } .inner { width: 200px; height: 400px; transform: translateX(-200px) rotate(72deg); background-color: lightgray; transform-origin: right center; opacity: 0.5; } .inner span { color: white; font-size: 50px; font-weight: 500; position: absolute;
left: 60px; top: 10px; transform-origin: center center; background-color: green; transform: rotate(-36deg); } </style> </html>
|