xxxxxxxxxx
34
let vertices = [];
function setup() {
createCanvas(500, 300);
textSize(18);
text("Click anywhere to place a vertice at that point", 10, 20);
}
function mouseClicked() {
// Update the vertices array with
// current mouse position
vertices.push({ x: mouseX, y: mouseY });
clear();
text("Click anywhere to place a vertice at that point", 10, 20);
// Start the shape using beginShape()
beginShape();
// Use the vertices in the array
// with the vertex() function
for (let i = 0; i < vertices.length; i++)
vertex(vertices[i].x, vertices[i].y);
// End the shape using endShape()
endShape();
// Draw a circle at the last drawn vertice
// for demonstration
circle(mouseX, mouseY, 15);
console.log(mouseX, mouseY);
}