zoukankan      html  css  js  c++  java
  • html5 canvas 钟表

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style>
    body{
        background:pink;
        }
    #c1{
        background:white;
        }
    </style>
    <script>
        window.onload = function ()
        {
            var oc = document.getElementById('c1');
            var ogc = oc.getContext('2d');
            
            function toDraw()
            {
                var x = 200;
                var y = 200;
                var r = 150;
                
                ogc.clearRect(0,0,oc.width,oc.height);
                
                var aDate = new Date();
                var oHouse = aDate.getHours();
                var oMin = aDate.getMinutes();
                var oSen = aDate.getSeconds();
                
                var oHoursevalue = ( -90 + oHouse*30 + oMin/2)*Math.PI/180;
                var oMinvalue = ( -90 + oMin*6 )*Math.PI/180;
                var oSenvalue = ( -90 + oSen*6)*Math.PI/180;
                
                ogc.beginPath();
                for(var i = 0; i < 60; i++)
                {
                    ogc.moveTo(x,y);
                    ogc.arc(x,y,r,6*i*Math.PI/180,6*(i+1)*Math.PI/180,false);
                    ogc.stroke();
                }
                
                ogc.closePath();
                
                ogc.beginPath();
                ogc.fillStyle = 'white';
                ogc.moveTo(x,y);
                ogc.arc(x,y,r*19/20,0,360,false);
                ogc.fill();
                
                ogc.closePath();
                
                ogc.beginPath();
                ogc.lineWidth = 3
                for(var i = 0; i < 12; i++)
                {
                    ogc.moveTo(x,y);
                    ogc.arc(x,y,r,30*i*Math.PI/180,30*(i+1)*Math.PI/180,false);
                    ogc.stroke();
                }
                
                ogc.closePath();
                
                ogc.beginPath();
                ogc.fillStyle = 'white';
                ogc.moveTo(x,y);
                ogc.arc(x,y,r*18/20,0,360,false);
                ogc.fill();
                
                ogc.closePath();
                
                
                
                ogc.beginPath();
                ogc.lineWidth = 5
                ogc.moveTo(x,y);
                ogc.arc(x,y,r*5/20,oHoursevalue,oHoursevalue,false);
                ogc.stroke();
                ogc.closePath();
                
                ogc.beginPath();
                ogc.lineWidth = 3
                ogc.moveTo(x,y);
                ogc.arc(x,y,r*8/20,oMinvalue,oMinvalue,false);
                ogc.stroke();
                ogc.closePath();
                
                ogc.beginPath();
                ogc.lineWidth = 1
                ogc.moveTo(x,y);
                ogc.arc(x,y,r*18/20,oSenvalue,oSenvalue,false);
                ogc.stroke();
                ogc.closePath();
                
            }
            
            toDraw();
            
            setInterval(toDraw,1000);
            
        }
    </script>
    </head>
    
    <body>
    
    <canvas id="c1" width="400" height="400"></canvas>
    </body>
    </html>
  • 相关阅读:
    思维导图
    网络面经
    2.17 C++ 专项练习 错题复盘
    C++面经
    2.15 C++专项练习 错题复盘
    uboot下读取flash,上传tftp服务器、下载
    Hi3516EV100烧录出厂固件
    用Hi3518EV200板当spi烧录器
    生而为人,我很抱歉!深夜爬虫, 我很抱歉 ,附微信 “ 网抑云” 公众号爬虫教程!
    阿里HR: 你会 Android 实现侧滑菜单-design吗? CN看了,原来这么简单呀!
  • 原文地址:https://www.cnblogs.com/mayufo/p/4286322.html
Copyright © 2011-2022 走看看