• 【一天一个canvas】半圆与圆弧的不同画法(十)


    昨天写的博客中,写到了HTML5中使用Canvas画圆的方法,昨晚试了一下画一个笑脸,其实挺简单的,就是两个实心圆做眼睛,一个半圆弧做嘴,这个简单的笑脸就完成了,但是在做嘴的时候开始出现了问题:

    <!DOCTYPE html>
    <html>
     <head>
        <meta charset="utf-8">
        <title>Canvas</title>
     </head>
     <style type="text/css">
        body{margin:20px auto; padding:0; 800px; }
        canvas{border:dashed 2px #CCC}
     </style>
     <script type="text/javascript">
        function $$(id){
            return document.getElementById(id);
        }
        function pageLoad(){
            var can = $$('can');
            var cans = can.getContext('2d');
            cans.beginPath();
            cans.arc(400,300,200,0,Math.PI,1);
            cans.closePath();
            cans.strokeStyle = 'red';
            cans.lineWidth = 10;
            cans.stroke();
        }
     </script>
    <body onload="pageLoad();">
        <canvas id="can" width="800px" height="600px"></canvas>
    </body>
    </html>

    这几天正在看一本书——陶国荣的《HTML5实战》,这本书里的一个笑脸实例让我顿悟,方法更是简单的让我汗颜啊~~~

    先看效果,再上代码

    <!DOCTYPE html>
    <html>
     <head>
        <meta charset="utf-8">
        <title>Canvas</title>
     </head>
     <style type="text/css">
        body{margin:20px auto; padding:0; 800px; }
        canvas{border:dashed 2px #CCC}
     </style>
     <script type="text/javascript">
        function $$(id){
            return document.getElementById(id);
        }
        function pageLoad(){
            var can = $$('can');
            var cans = can.getContext('2d');
            cans.beginPath();
            cans.arc(400,300,200,0,Math.PI,1);
            cans.strokeStyle = 'red';
            cans.lineWidth = 10;
            cans.stroke();
            cans.closePath();
        }
     </script>
    <body onload="pageLoad();">
        <canvas id="can" width="800px" height="600px"></canvas>
    </body>
    </html>

    OK啦,这样就可以实现我那个的笑脸的嘴了~~

  • 相关阅读:
    Linux下的”锁“事儿
    拿得起,放得下,想得开
    关于TCP协议握手的那些事儿

    C++中的RTTI机制解析
    C/C++中产生随机数
    数据库-事务和锁
    JS 数组Array常用方法
    C# 压缩 SharpZipLib
    正则表达式学习3-负向零宽断言
  • 原文地址:https://www.cnblogs.com/babysay123/p/4645048.html
Copyright © 2020-2023  润新知