<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Dva Demo</title> <link rel="stylesheet" href="index.css" /> </head> <body> <div id="root"> <canvas width="800" height="800" id="canvas"></canvas> </div> <script src="index.js"></script> <script> let canvas=document.getElementById('canvas'); let context=canvas.getContext('2d'); context.beginPath(); for(let i=0;i<5;i++) { context.lineTo(Math.cos((18+72*i)/180*Math.PI)*300+400,-Math.sin((54+72*i)/180*Math.PI)*300+400); context.lineTo(Math.cos((18+72*i)/180*Math.PI)*150+400,-Math.sin((54+72*i)/180*Math.PI)*150+400); } context.closePath(); context.lineWidth=10; context.stroke(); </script> </body> </html>
哈哈哈,我也是,改一下小圆的起启度数就可以
context.lineTo(Math.cos((18+72*i)/180*Math.PI)*300+400,-Math.sin((18+72*i)/180*Math.PI)*300+400); context.lineTo(Math.cos((54+72*i)/180*Math.PI)*150+400,-Math.sin((54+72*i)/180*Math.PI)*150+400);
你把大圆小圆的角度x写成18,y写成54了