const polygon = function polygon(opts) {
  const {
    context,
    px = d => d,
    points,
    fill,
    stroke,
    strokeWidth = 1,
    alpha = 1
  } = opts;
  if (!points) return;
  context.save();
  context.globalAlpha = alpha;
  context.beginPath();
  const [start, ...moves] = points;
  context.moveTo(...start);
  moves.forEach(move => {
    context.lineTo(...move);
  });
  context.lineTo(...start);
  context.fillStyle = fill;
  context.fill();
  if (stroke) {
    context.strokeStyle = stroke;
    context.lineWidth = px(strokeWidth);
    context.stroke();
  }
  context.restore();
};
export default polygon;