這是我使用繪製一些隨機的圓圈部分代碼:重置迭代的for ... in循環
if(circles.length != 0) { //1+ circles have already been drawn
x = genX(radius);
y = genY(radius);
var i = 0;
iCantThinkOfAGoodLabelName:
for(i in circles) {
var thisCircle = circles[i];
if(Math.abs(x-thisCircle["x"])+Math.abs(y-thisCircle["y"])>radius*2) {
//overlaps
} else {
//overlaps
x = genX(radius);
y = genY(radius);
continue iCantThinkOfAGoodLabelName;
}
if(i == circles.length - 1) { //Last iteration
//Draw circle, add to array
}
}
}
的問題是,當存在重疊,與圓不會檢查新生成的座標是否與重疊圓圈已檢查過的圓重疊。在使用continue語句之前,我已經嘗試將i設置爲0,但那不起作用。請幫忙,我真的很困惑。
可以宥創建[的jsfiddle(http://jsfiddle.net)這個? – Ibu
好吧... http://jsfiddle.net/evQ8a/ – JJJollyjim