网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

html5canvas画时钟








    // get the canvas
    var myCanvas = document.getElementById("myCanvas");
    var ctx = myCanvas.getContext("2d");

    function showClock(){
        ctx.save();
        ctx.save();
        ctx.save();
        ctx.save();
        ctx.save();
        ctx.save();
        ctx.save();
        ctx.clearRect(0,0,400,400);

        // create the clock border
        ctx.restore();
        ctx.beginPath();
        ctx.strokeStyle="pink";
        ctx.lineWidth=10;
        ctx.arc(200,200,150,0,Math.PI*2,true);
        ctx.stroke();


        // create the hour icon
        ctx.restore();
        ctx.lineWidth=8;
        ctx.strokeStyle="blue";
        ctx.translate(200,200);
        for(var i=0;i<12;i++){
          ctx.beginPath();      
          ctx.moveTo(135,0);
          ctx.lineTo(150,0);
          ctx.rotate(Math.PI/6);
          ctx.stroke();
        }

        // create the minute icon
        ctx.restore();
        ctx.lineWidth=4;
        ctx.strokeStyle="blue";
        ctx.translate(200,200);
        for(var i=0;i<60;i++){
          ctx.beginPath();      
          ctx.moveTo(145,0);
          ctx.lineTo(150,0);
          ctx.rotate(Math.PI/30);
          ctx.stroke();
        }

        var date = new Date();
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        hour = hour>=12?hour-12:hour;
        
        // create the hour hand
        ctx.restore();
        ctx.lineWidth = 14;
        ctx.strokeStyle="pink";
        ctx.translate(200,200);
        ctx.rotate(hour*(Math.PI/6) + (Math.PI/360)*minute + (Math.PI/21600)*second-Math.PI/2);
        ctx.beginPath();      
        ctx.moveTo(-20,0);
        ctx.lineTo(90,0);     
        ctx.stroke();
       

        // create the minute hand
        ctx.restore();
        ctx.lineWidth = 10;
        ctx.strokeStyle="pink";
        ctx.translate(200,200);
        ctx.rotate((Math.PI/30)*minute + (Math.PI/1800)*second-Math.PI/2);
        ctx.beginPath();      
        ctx.moveTo(-30,0);
        ctx.lineTo(125,0);     
        ctx.stroke();

        // create the second hand
        ctx.restore();
        ctx.lineWidth = 4;
        ctx.strokeStyle="pink";
        ctx.translate(200,200);
        ctx.rotate( (Math.PI/30)*second-Math.PI/2);
        ctx.beginPath();      
        ctx.moveTo(-35,0);
        ctx.lineTo(135,0);     
        ctx.stroke();

        ctx.restore();
        setTimeout(showClock,1000);
    }

showClock();



网站栏目:html5canvas画时钟
文章分享:http://bjjierui.cn/article/jehjci.html

其他资讯