Skip to content
html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    html, 
    body {
      width: 100vw;
      height: 100vh;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>

  <script>
    const canvas = document.querySelector('#canvas')
    const context = canvas.getContext('2d')

    canvas.style.background = '#ddd'
    canvas.width = 700
    canvas.height = 700

    context.shadowColor = 'rgba(0, 0, 0, .8)'
    context.shadowOffsetX = 12
    context.shadowOffsetY = 12
    context.shadowBlur = 15

    context.beginPath()
    context.arc(200, 200, 150, 0, Math.PI * 2)
    context.arc(200, 200, 100, 0, Math.PI * 2, true)
    context.fillStyle = 'rgba(100, 140, 230, .5)'
    // 创建好路径之后,浏览器运用”非零环绕规则“,对外围圆形的内部进行填充,不过填充范围
    // 不包括里面的圆,就产生了剪纸图案的效果。
    context.fill()
    context.restore()

    // 如果在当前路径存在子路经的情况下调用 stroke(),就会从子路经的终点向当前路径的起点连接
    // 起来,调用 beginPath() 方法将当前路径下的所有子路径都清除掉,这样就不会有连线了
    context.beginPath()
    context.rect(30, 400, 400, 200)
    context.stroke()
    context.arc(100, 500, 30, 0, Math.PI * 2, true)
    context.fillStyle = 'rgba(100, 140, 230, .5)'
    context.fill()
  </script>
</body>
</html>