xxxxxxxxxx
41
points = []
offset = []
function setup() {
createCanvas(400, 400);
}
function calcOff(i){
dx = points[i][0]-points[i + 1][0]
dy = points[i][1]-points[i + 1][1]
vx = 1
vy = -vx * dx /dy
m = sqrt(vx*vx + vy*vy)
vx = vx / m * 10
vy = vy / m * 10
offset.push([points[i][0] + vx, points[i][1] + vy])
}
function draw() {
background(255);
points.push([mouseX, mouseY]);
if(points.length >= 2){
calcOff(points.length - 2)
}
if(points.length > 100){
points.shift();
}
if(offset.length > 100){
offset.shift();
}
for(var i = 0; i < points.length - 1; i ++){
stroke(0);
line(points[i][0], points[i][1], points[i + 1][0], points[i + 1][1])
}
for( i = 0; i < offset.length - 1; i ++){
stroke(200);
line(offset[i][0], offset[i][1], offset[i + 1][0], offset[i + 1][1])
}
}