{
const canvas = DOM.canvas(300, 200);
const ctx = canvas.getContext('2d');
const samples = 100;
const tension = 0.25;
const interp = new lib.CurveInterpolator(ctrlPoints, { tension, closed: false });
ctx.lineWidth = 1.5;
ctx.strokeStyle = 'blue';
ctx.beginPath();
ctx.moveTo(ctrlPoints[0][0], ctrlPoints[0][1]);
interp.getPoints(samples).forEach(p => {
ctx.lineTo(p[0], p[1]);
});
ctx.stroke();
const t = position;
const length = 50;
const pos = interp.getPointAt(t);
const vTan = interp.getTangentAt(t);
const vNorm = [vTan[1], -vTan[0]];
ctx.strokeStyle = 'green';
ctx.beginPath();
ctx.moveTo(pos[0], pos[1]);
ctx.lineTo(pos[0] + vTan[0] * length, pos[1] + vTan[1] * length);
ctx.stroke();
ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.moveTo(pos[0], pos[1]);
ctx.lineTo(pos[0] + vNorm[0] * length, pos[1] + vNorm[1] * length);
ctx.stroke();
return canvas;
}