慕粉1470305008
2018-05-12 21:25
var ss=new Array();
for(var p=0;p<50;p++){
var r=Math.random()*10+10;
var x=Math.random()*can.width;
var y=Math.random()*can.height;
var rott=Math.random()*360;
ss.push([r,x,y]);
if (Math.sqrt(Math.pow(ss[0][1]-x,2)+Math.pow(ss[0][2]-y,2))>ss[0][0]+r){
kk(tex,r,r/2,x,y,rott);
}
}
function kk(tex,R,r,x,y,rot) {
tex.lineWidth=10;
tex.beginPath();
for(var i=0;i<5;i++){
tex.lineTo(Math.cos((18+i*72-rot)/180*Math.PI)*R+x,-Math.sin((18+i*72-rot)/180*Math.PI)*R+y);
tex.lineTo(Math.cos((54+i*72-rot)/180*Math.PI)*r+x,-Math.sin((54+i*72-rot)/180*Math.PI)*r+y);
}
tex.closePath();
tex.fillStyle='#fb3';
tex.strokeStyle='#fb5';
tex.lineWidth=10;
tex.lineJoin='round';
tex.fill();
tex.stroke();
}
这样不行吧
if (Math.sqrt(Math.pow(ss[0][1]-x,2)+Math.pow(ss[0][2]-y,2))>ss[0][0]+r){
kk(tex,r,r/2,x,y,rott);
}
不是应该与前面生成的所有坐标都进行比较吗 你这样貌似只比较了第一个生成的坐标与当前坐标的距离大于直径Canvas绘图详解
73030 学习 · 441 问题
相似问题