西瓜瓜瓜

导航

用canvas画一个房子

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8"/>
  <script type="application/javascript">
    function draw() {
      var canvas = document.getElementById('canvas');
      if (canvas.getContext) {
        var ctx = canvas.getContext('2d');



        ctx.fillStyle = 'rgba(0, 0, 200, 0.5)';
        ctx.fillRect(120, 120,200, 200);
        ctx.beginPath();

        ctx.fillStyle='#000'
        ctx.moveTo(220, 20);
        ctx.lineTo(90, 140);
        ctx.lineTo(350, 140);
        ctx.fill();
      }
    }
  </script>
  <style type="text/css">
     canvas { border: 1px solid black; }
   </style>
 </head>
 <body onload="draw();">
   <canvas id="canvas" width="500" height="500"></canvas>
 </body>
</html>

  效果图:

 

posted on 2018-11-27 14:33  西瓜瓜瓜  阅读(1830)  评论(0编辑  收藏  举报