<!DOCTYPE html>
<html>
  <head>
    <style>
      canvas {
        border: 1px solid black;
      }
    </style>
  </head>
  <body>
    <canvas id="catCanvas" width="400" height="400"></canvas>
<pre><code>&lt;script&gt;
  var canvas = document.getElementById(&quot;catCanvas&quot;);
  var ctx = canvas.getContext(&quot;2d&quot;);

  // 绘制猫的头部
  ctx.beginPath();
  ctx.arc(200, 200, 100, 0, 2 * Math.PI);
  ctx.fillStyle = &quot;gray&quot;;
  ctx.fill();

  // 绘制猫的眼睛
  ctx.beginPath();
  ctx.arc(160, 160, 20, 0, 2 * Math.PI);
  ctx.fillStyle = &quot;white&quot;;
  ctx.fill();

  ctx.beginPath();
  ctx.arc(240, 160, 20, 0, 2 * Math.PI);
  ctx.fillStyle = &quot;white&quot;;
  ctx.fill();

  ctx.beginPath();
  ctx.arc(160, 160, 5, 0, 2 * Math.PI);
  ctx.fillStyle = &quot;black&quot;;
  ctx.fill();

  ctx.beginPath();
  ctx.arc(240, 160, 5, 0, 2 * Math.PI);
  ctx.fillStyle = &quot;black&quot;;
  ctx.fill();

  // 绘制猫的鼻子
  ctx.beginPath();
  ctx.moveTo(200, 170);
  ctx.lineTo(180, 200);
  ctx.lineTo(220, 200);
  ctx.closePath();
  ctx.fillStyle = &quot;pink&quot;;
  ctx.fill();

  // 绘制猫的嘴巴
  ctx.beginPath();
  ctx.arc(200, 220, 40, 0.4 * Math.PI, 0.6 * Math.PI);
  ctx.lineWidth = 5;
  ctx.strokeStyle = &quot;black&quot;;
  ctx.stroke();

  // 绘制猫的身体
  ctx.beginPath();
  ctx.moveTo(200, 300);
  ctx.lineTo(100, 400);
  ctx.lineTo(300, 400);
  ctx.closePath();
  ctx.fillStyle = &quot;gray&quot;;
  ctx.fill();

  // 绘制猫的尾巴
  ctx.beginPath();
  ctx.moveTo(300, 400);
  ctx.lineTo(350, 350);
  ctx.lineTo(350, 450);
  ctx.closePath();
  ctx.fillStyle = &quot;gray&quot;;
  ctx.fill();

  // 绘制猫的脚
  ctx.beginPath();
  ctx.arc(150, 400, 30, 0, 2 * Math.PI);
  ctx.fillStyle = &quot;gray&quot;;
  ctx.fill();

  ctx.beginPath();
  ctx.arc(250, 400, 30, 0, 2 * Math.PI);
  ctx.fillStyle = &quot;gray&quot;;
  ctx.fill();
&lt;/script&gt;
</code></pre>
  </body>
</html>

原文地址: https://www.cveoy.top/t/topic/pEgt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录