Have been looking at this for an hour, but can't find the problem.
Can anyone help?
var matriXdots = 5;
var matriXspacing = 25;
var maxLine = 2 * matriXspacing;
var clr = new CMYKColor(0,0,0,1); // set stroke color to black, if the selected objects already have a strok color, that will be used.
puntArray = new Array();
var fromX = 0;
var fromY = 0;
var toX = 0;
var toY = 0;
for (a=0; a<matriXdots; a++) {
for (b=0; b<matriXdots; b++) {
id = a+"-"+b;
xpos = 50 * a;
ypos = 50 * b;
var circle = new Path.Circle(new Point(xpos, ypos), 5);
currentLoc = [];
currentLoc[0] = xpos;
currentLoc[1] = ypos;
puntArray.push(currentLoc);
}
}
while(puntArray.length > 0){
randomFrom = Math.floor(Math.random() * puntArray.length);
from = puntArray[randomFrom];
randomTo = Math.floor(Math.random() * puntArray.length);
to = puntArray[randomTo];
fromX = parseInt(from[0]);
fromY = parseInt(from[1]);
toX = parseInt(to[0]);
toY = parseInt(to[1]);
xdistance = Math.abs(fromX - toX);
ydistance = Math.abs(fromY - toY);
distance = Math.sqrt(Math.pow(xdistance,2) + Math.pow(ydistance,2));
if(distance < maxLine){
path = new Path();
// i think the problem is here
path.moveTo(fromX,fromY); //if I change this to 0,0 it works
path.lineTo(toX, toY); //if I change this to 0,0 it works
// but I can't figure out why it works if one of the two is 0, but doesn't work otherwise
puntArray.splice(randomFrom,1);
puntArray.splice(randomTo,1);
} else
{
path.remove();
}
}