网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 HTML5 Canvas锯齿图代码实例
内容
    效果图:
    名单
    提示:把代码复制到一个html文件中并保存,直接打开即可看到效果。
    实现代码:
    代码如下:
    <!doctype html>
    <html lang="zh">
    <head>
    <meta charset="gbk">
    <title>锯齿图</title>
    <script type="text/javascript">
    window.addEventListener("load", eventWindowLoaded, false);
    function eventWindowLoaded(){
    var x,y;
    var theCanvas = document.getElementById("canvas");
    var context = theCanvas.getContext("2d");
    //Box
    context.strokeStyle = '#00f';
    context.lineWidth=10;
    context.strokeRect(0, 0, theCanvas.width-0, theCanvas.height-0);
    context.fillStyle = "#00f";
    for(x=5;x<=canvas.width;x=x+10){
    context.beginPath();
    context.arc(x,5,5,0,Math.PI,false);
    context.closePath();
    context.fill();
    context.beginPath();
    context.arc(x,canvas.height-5,5,0,Math.PI,true);
    context.closePath();
    context.fill();
    }
    for(y=5;y<=canvas.height;y=y+10){
    context.beginPath();
    context.arc(5,y,5,0,Math.PI*2,true);
    context.arc(canvas.width-5,y,5,0,Math.PI*2,true);
    context.closePath();
    context.fill();
    }
    }
    </script>
    </head>
    <body>
    <div>
    <canvas id="canvas" width="300" height="300">
    </div>
    </body>
    </html>
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/18 8:36:04