HTML5利用canvas画布绘制哆啦A梦

效果图:

源码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>蓝胖子</title>
    <style>
        canvas {
            display:block;
            margin:0 auto;
        }

    </style>
</head>
<body>
<div><canvas id="canvas"></canvas></div>
<script>
    var oCanvas = document.getElementById("canvas");
    oCanvas.width = 600;
    oCanvas.height = 600;
    var context = oCanvas.getContext("2d");

    // 脑袋
    context.beginPath();
    context.arc(300, 300, 250, 0, Math.PI * 2);
    context.lineWidth = "5";
    context.stroke();
    context.fillStyle = "rgb(34,118,207)";
    context.fill();

    // 脸
    context.beginPath();
    context.ellipse(300, 380, 200, 170, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "white";
    context.fill();

    // 嘴
    context.beginPath();
    context.arc(300, 460, 50, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "black";
    context.fill();

    context.beginPath();
    context.ellipse(300, 470, 48, 40, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "red";
    context.fill();


    // 眼
    context.beginPath();
    context.ellipse(248, 230, 50, 60, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "white";
    context.fill();
    context.beginPath();
    context.ellipse(270, 230, 20, 30, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "black";
    context.fill();
    context.beginPath();
    context.ellipse(270, 230, 5, 10, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "white";
    context.fill();


    context.beginPath();
    context.ellipse(352, 230, 50, 60, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "white";
    context.fill();
    context.beginPath();
    context.ellipse(330, 230, 20, 30, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "black";
    context.fill();
    context.beginPath();
    context.ellipse(330, 230, 5, 10, 0, 0, Math.PI * 2);
    context.stroke();
    context.fillStyle = "white";
    context.fill();
    // 鼻
    context.beginPath();
    context.lineWidth = "3";
    context.arc(300, 290, 30, 0, 2 * Math.PI);
    context.stroke();
    context.fillStyle = "red";
    context.fill();

    // 胡子
    context.lineWidth="5";
    beard(125,294,230,335);
    beard(113,370,222,366);
    beard(125,434,222,398);
    beard(376,335,465,282);
    beard(385,369,490,354);
    beard(385,400,488,420);


    // 画胡子的方法
    function beard(x1, y1, x2, y2) {
        context.beginPath();
        context.moveTo(x1, y1);
        context.lineTo(x2, y2);
        context.stroke();
    }
</script>
</body>
</html>

  • 4
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

讲台催眠师明哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值