canvas画圆形图片

function fillMyRect(ctx, x, y, w, h, r) {
  const rightRadio = h / 2;
  const angle = Math.asin(rightRadio / r);
  ctx.save();
  ctx.beginPath();
  ctx.moveTo(x + r * Math.cos(angle), y);
  ctx.lineTo(x + w, y);
  ctx.arc(x + w, y + rightRadio, rightRadio, -0.5 * Math.PI, 0.5 * Math.PI);
  ctx.lineTo(x + r * Math.cos(angle), y + h);
  ctx.arc(x, y + rightRadio, r, angle, -angle, true);
  ctx.setFillStyle("rgb(255, 253, 208)");
  ctx.fill();
  ctx.restore();
}

猜你喜欢

转载自blog.csdn.net/qq_22038259/article/details/85006542
今日推荐