第 5 课 14 / 19 | 编码:L05-17
代码推演

restore 会撤销已经画出的矩形吗?

<canvas id="art" width="300" height="160">矩形颜色对比</canvas>
<script>
  const ctx = document.querySelector('#art').getContext('2d');
  ctx.fillStyle = 'navy';
  ctx.save();
  ctx.fillStyle = 'orange';
  ctx.fillRect(10, 20, 100, 80);
  ctx.restore();
  ctx.fillRect(130, 20, 100, 80);
</script>