xxxxxxxxxx
30
function setup() {
createCanvas(400, 400);
noLoop();
}
function distance(x1, x2, y1, y2){
return sqrt((x2 - x1)*(x2-x1) + (y2-y1)*(y2-y1))
}
function draw() {
// background(220);
var x1 = random() * width;
var x2 = random() * width;
var y1 = random() * width;
var y2 = random() * width;
var m = distance(x1, x2, y1, y2)
var dx = (x1 - x2) / m * 10;
var dy = (y1 - y2) / m * 10;
threshold = 10;
var on = true
while(distance(x1, x2, y1, y2) > threshold){
newX = x1 - dx;
newY = y1 - dy;
if(on){
line(x1, y1, newX, newY);
}
x1 = newX;
y1 = newY;
on = !on;
}
}