xxxxxxxxxx
34
const points = [];
function setup() {
createCanvas(640, 360);
}
function mousePressed() {
points.push(createVector(mouseX, mouseY));
}
function draw() {
background(100);
for (let i = 0; i < points.length; i++) {
const pt = points[i];
const next = points[(i + 1) % points.length];
stroke(0);
strokeWeight(2);
lineDash(pt.x, pt.y, next.x, next.y, [5]);
stroke(255);
strokeWeight(10);
point(pt.x, pt.y);
}
if (points.length > 0) {
stroke(255);
strokeWeight(10);
point(points[0].x, points[0].y);
}
}
function lineDash(x1, y1, x2, y2, list) {
drawingContext.setLineDash(list);
line(x1, y1, x2, y2);
drawingContext.setLineDash([]);
}