<!DOCTYPE html>
<html>
<head>
  <title>Symmetric Rectangle</title>
</head>
<body>
  <canvas id="myCanvas" width="400" height="200"></canvas>
  <script>
    var canvas = document.getElementById("myCanvas");
    var ctx = canvas.getContext("2d");
    
    var centerX = canvas.width / 2;
    var centerY = canvas.height / 2;
    var rectWidth = 200;
    var rectHeight = 100;
    
    ctx.fillStyle = "blue";
    ctx.fillRect(centerX - rectWidth / 2, centerY - rectHeight / 2, rectWidth, rectHeight);
    
    ctx.fillStyle = "red";
    ctx.fillRect(centerX - rectWidth / 2, centerY + rectHeight / 2, rectWidth, -rectHeight);
  </script>
</body>
</html>

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

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