xxxxxxxxxx
54
let points = []
function drawPath() {
background(220)
stroke("darkgreen")
strokeWeight(5)
for(let p of points)
point(p)
if(points.length < 3)
return
stroke("darkblue")
// strokeWeight(1)
let start = p5.Vector.lerp(points[0], points[1], 0.5)
beginShape()
vertex(start.x, start.y)
for(let i = 1; i < points.length - 1; ++i) {
quadraticVertex(points[i].x, points[i].y,
lerp(points[i].x, points[i+1].x, 0.5),
lerp(points[i].y, points[i+1].y, 0.5) )
}
let last = points[points.length - 1]
let c = p5.Vector.lerp(last, points[0], 0.5)
// Close path
// quadraticVertex(last.x, last.y, c.x, c.y)
// quadraticVertex(points[0].x, points[0].y, start.x, start.y)
endShape()
}
function mouseClicked() {
points.push(createVector(mouseX, mouseY))
drawPath()
}
function doubleClicked() {
points = []
background(220)
}
function draw() {
background(220)
}
function setup() {
createCanvas(400, 400)
noFill()
noLoop()
}