脑袋的背景色修改成这样,不对吧

来源:3-11 编程练习

unbreakable_全栈

2020-09-27 09:54:38

<!DOCTYPE html>

<html>


<head>

    <meta charset="UTF-8">

    <title>canvas</title>

    <style>

        canvas {

            background-color: lightblue;

        }

    </style>

</head>


<body>

    <canvas id="canvas" width="800" height="800">

        您的浏览器不支持canvas

    </canvas>


    <script>

        //在此处写出代码

        var canvas = document.getElementById('canvas')

        var ctx = canvas.getContext('2d')

        ctx.lineWidth = 3

        ctx.moveTo(300, 50)

        ctx.lineTo(350, 200)

        ctx.strokeStyle = 'yellow'

        ctx.stroke()

        ctx.beginPath();

        ctx.moveTo(500, 50)

        ctx.lineTo(450, 200)

        ctx.stroke()

        ctx.beginPath();

        ctx.fillStyle = 'FFDAB9' // 脑袋

        ctx.fillRect(300, 200, 200, 100) // 绘制一个矩形的边框

        ctx.fillStyle = 'yellow'

        ctx.fillRect(290, 220, 10, 20) // 绘制一个矩形的边框 耳朵

        ctx.fillStyle = 'yellow'

        ctx.fillRect(500, 220, 10, 20) // 绘制一个矩形的边框 耳朵

        ctx.arc(335, 230, 10, 0, 2*Math.PI, true) // 参数:圆心,圆心,半径,起始弧度,终止弧度,顺时针/逆时针

        ctx.fillStyle = '#000'

        ctx.fill()

        ctx.beginPath(); 

        ctx.arc(455, 230, 10, 0, 2*Math.PI, true) // 参数:圆心,圆心,半径,起始弧度,终止弧度,顺时针/逆时针

        ctx.fillStyle = '#000'

        ctx.fill()

        ctx.beginPath(); 


        ctx.fillStyle = '#F00'

        ctx.fillRect(380, 260, 40, 20) // 绘制一个矩形的边框 嘴巴

        ctx.fill()


        ctx.fillStyle = 'pink'

        ctx.fillRect(338, 300, 130, 200) // 绘制一个矩形的边框 肚子


        ctx.fillStyle = 'green'

        ctx.fillRect(178, 370, 160, 30) // 绘制一个矩形的边框

        ctx.fillStyle = 'green'

        ctx.fillRect(468, 370, 160, 30) // 绘制一个矩形的边框

        ctx.fillStyle = 'green'

        ctx.fillRect(360, 500, 30, 160) // 绘制一个矩形的边框

        ctx.fillStyle = 'green'

        ctx.fillRect(420, 500, 30, 160) // 绘制一个矩形的边框

    </script>

</body>


</html>


写回答

1回答

好帮手慕星星

2020-09-27

同学你好,十六进制的颜色需要加#,否则颜色不生效默认为黑色

http://img.mukewang.com/climg/5f6ff90a090b0ddb04640088.jpg

修改效果绘制效果没有问题,很棒!

0

0 学习 · 6815 问题

查看课程