我正在使用以下代码生成与页面中另一个元素的最大距离的随机点:
function drawPoints (maxdistance, npoints) {
var start = $('#startingPoint').position();
var draw = document.getElementById('draw');
var i = npoints;
while(i--) {
var n = document.createElement('div');
n.style.position = 'absolute';
n.style.top = ( - (Math.random() * maxdistance) -10 + start.top).toString() + 'px';
n.style.left = ( - (Math.random() * maxdistance) + 50 + start.left).toString() + 'px';
n.style.width = '6px';
n.style.height = '6px';
n.style.backgroundColor = 'black';
n.style.borderRadius = '6px';
draw.appendChild(n);
}
}
例如,drawPoints(150, 20);
将绘制 20 个点,距离起点的最大距离为 150。
问题是,我如何绘制某种弧线或线条来连接这些点?