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();

创新互联公司作为成都网站建设公司,专注网站建设公司、网站设计,有关企业网站制作方案、改版、费用等问题,行业涉及玻璃钢坐凳等多个领域,已为上千家企业服务,得到了客户的尊重与认可。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:html5canvas画时钟-创新互联
分享链接:http://myzitong.com/article/dggehg.html