💾ctx.polyline()

browsercanvaspath ⟩ ctx.polyline()

💾 replit:canvas curves

⬆️ 需要: Vector

// 🔸 ctx.polyline()
CanvasRenderingContext2D.prototype.polyline = function(pts, {
    color = 'gray',
    lineWidth = 1,
}={}) {

    this.save();
    this.beginPath();

    pts.forEach((p, i) => {
        i === 0 ? this.moveTo(...p.coords) : this.lineTo(...p.coords);
    });

    this.strokeStyle = color;
    this.lineWidth = lineWidth;
    this.stroke();
    this.restore();
};

Last updated