draw = {
let ctx = canvas.getContext("2d");
ctx.fillStyle = "lightgray";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "black";
for (let p of points) {
ctx.beginPath();
ctx.fillStyle = p.notsmooth ? "green" : "black";
ctx.arc(p.x, p.y, 5, 0, Math.PI * 2);
ctx.fill();
}
let n = points.length;
if (n > 1) {
if (show.indexOf("o") >= 0) {
ctx.strokeStyle = "#222";
ctx.lineWidth = 0.7;
ctx.beginPath();
let p = points[n - 1];
ctx.moveTo(p.x, p.y);
for (let p of points) ctx.lineTo(p.x, p.y);
ctx.stroke();
}
let m = controlPoints.length;
if (show.indexOf("c") >= 0) {
ctx.strokeStyle = "blue";
ctx.lineWidth = 1;
ctx.beginPath();
let a = controlPoints[1];
ctx.moveTo(a.x, a.y);
for (let i = 0; i < m; i += 3) {
let b = controlPoints[(i + 2) % m];
let c = controlPoints[(i + 3) % m];
let d = controlPoints[(i + 4) % m];
ctx.lineTo(b.x, b.y);
ctx.lineTo(c.x, c.y);
ctx.lineTo(d.x, d.y);
}
ctx.stroke();
}
if (show.includes("s")) {
ctx.strokeStyle = "green";
ctx.fillStyle = "#0F05";
ctx.beginPath();
for (let p of subdiv) ctx.lineTo(p.x, p.y);
ctx.closePath();
ctx.stroke();
ctx.fill();
}
if (show.indexOf("b") >= 0) {
ctx.lineWidth = 1.5;
ctx.strokeStyle = "red";
ctx.fillStyle = "#F005";
ctx.beginPath();
let a = controlPoints[1];
ctx.moveTo(a.x, a.y);
for (let i = 0; i < m; i += 3) {
let b = controlPoints[(i + 2) % m];
let c = controlPoints[(i + 3) % m];
let d = controlPoints[(i + 4) % m];
ctx.bezierCurveTo(b.x, b.y, c.x, c.y, d.x, d.y);
}
ctx.stroke();
ctx.fill();
}
}
}