老师检查一下

来源:3-11 编程练习

Raymond0913

2020-09-08 21:28:13

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Android</title>
  <style>
    canvas{background-color: #add8e6;}
  </style>
</head>
<body>
  <canvas id="canvas" width="800" height="1000">
    您的浏览器不支持canvas
  </canvas>
  <script>
    var canvas = document.getElementById("canvas");
    var ctx = canvas.getContext("2d");
    // 左天线
    ctx.moveTo(300,50);
    ctx.lineTo(350,200);
    ctx.lineWidth=5;
    ctx.strokeStyle ="#FFD700"
    ctx.stroke();
    ctx.beginPath();
    // 右天线
    ctx.moveTo(500,50);
    ctx.lineTo(450,200);
    ctx.stroke();
    ctx.beginPath();
    //左边耳朵 
    ctx.fillStyle ="#FFD700";
    
    // ctx.strokeRect(270,230, 30,60);
    ctx.fillRect(270,230,30,60);
    // 右边耳朵
    // ctx.strokeRect(500,230, 30,60);
    ctx.fillRect(500,230,30,60);
    ctx.beginPath();
    // 脸
    ctx.lineWidth=1;
    ctx.strokeStyle= "#ffdab9";
    ctx.fillStyle = "#ffdab9";
    // ctx.strokeRect(300,200, 200,150);
    ctx.fillRect(300,200,200,150);
    ctx.beginPath();

    // 左眼
    ctx.arc(350,250 ,15,0,2*Math.PI,true);
    ctx.fillStyle="black";
    ctx.fill();
    ctx.beginPath();
    // 右眼
    ctx.arc(450,250,15,0,2*Math.PI,true);
    ctx.fill();
    ctx.beginPath();
    // 嘴
    // ctx.strokeRect(370,300, 60,20);
    ctx.fillStyle = "#f00";
    ctx.fillRect(370,300,60,20);
    ctx.beginPath();
    // 身体
    // ctx.strokeRect(350,350, 100,300);
    ctx.fillStyle="#ffb6c1";
    ctx.fillRect(350,350,100,300);
    ctx.beginPath();
    // 左胳膊
    // ctx.strokeRect(100,450,250,30);
    ctx.fillStyle ="#20b2aa";
    ctx.fillRect(100,450,250,30);
    ctx.beginPath();
    // 右胳膊
    // ctx.strokeRect(450,450,250,30);
    ctx.fillRect(450,450,250,30);
    ctx.beginPath();
    // 左腿
    // ctx.strokeRect(360,650,30,250);
    ctx.fillRect(360,650,30,250);
    ctx.beginPath();
    // 右腿
    // ctx.strokeRect(410,650,30,250);
    ctx.fillRect(410,650,30,250);
    ctx.beginPath();
    
  </script>
</body>
</html>


写回答

1回答

好帮手慕言

2020-09-09

同学你好,效果是正确的,继续加油,祝学习愉快~

0

0 学习 · 6815 问题

查看课程

相似问题