function drawCircle(x,y,r){ //圆弧上每一个像素长的距离一个点 算出一共需要多少个点 var pointCount=Math.round(2*Math.PI*r); //循环算出每一个点的坐标 并将生成的点添加到body中(body可以是其他的容器 如div) for (var i=0;i<=pointCount;i++){ var a=(i*2*Math.PI)/(pointCount); X1=(x+Math.cos(a)*r);//根据圆心 半径 和三角函数计算x Y1=(y+Math.sin(a)*r);//同计算x var point=document.createElement("div"); point.style.position='absolute'; point.style.background='red'; point.style.left=X1; point.style.top=Y1; point.style.width='3px'; point.style.height='3px'; document.getElementsByTagName("body")[0].appendChild(point); } }
用javascript画圆形
最新推荐文章于 2024-08-07 21:58:12 发布