国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 網(wǎng)站 > WEB開發(fā) > 正文

canvas-實(shí)例時(shí)鐘

2024-04-27 15:08:15
字體:
供稿:網(wǎng)友
<!DOCTYPE html><html><head lang="en">    <meta charset="UTF-8">    <title>canvas-clock</title></head><body>    <canvas id="canvas" width="500px" height="500px">        你的瀏覽器不支持該元素!趕緊下載最新版本瀏覽器或使用其他瀏覽器!    </canvas>    <script>        //獲取到canvas元素        var canvas = document.getElementById('canvas');        //獲取canvas中的畫圖環(huán)境        var context = canvas.getContext('2d');        //時(shí)鐘的大小        function drowClock(){            //鐘表的大小:初始值設(shè)置            var clockDimensions = 150;            //清理當(dāng)前畫布,以便后期繪制            context.clearRect(0,0,canvas.width,canvas.height);            //繪制表盤            context.beginPath(); //開啟新路徑            context.lineWidth = clockDimensions/15;            context.strokeStyle = "#A7C0DC";            //繪制表盤圓圈            context.arc(canvas.width/2,canvas.height/2,clockDimensions,0,Math.PI*2,false);            context.stroke();//描邊繪制            //繪制表盤的刻度線            for(var i=1;i<=60;i++){                if(i%5==0){                    context.save();//保存當(dāng)前繪制環(huán)境                    context.beginPath();                    context.lineWidth =clockDimensions/30;                    context.strokeStyle = "#9AABB1";                    //重置坐標(biāo)原點(diǎn)(0,0)                    context.translate(canvas.width/2,canvas.height/2);                    //繪制環(huán)境旋轉(zhuǎn)方法,以(0,0)為參考點(diǎn)進(jìn)行旋轉(zhuǎn)                    context.rotate(Math.PI*2/60 * i);                    context.moveTo(0,clockDimensions-clockDimensions/30);                    context.lineTo(0,clockDimensions-clockDimensions/8);                    context.stroke();                    context.beginPath();                    context.textAlign = 'center';                    context.textBaseline = 'middle';                    context.font = 'bold '+Math.floor(clockDimensions/10)+'px 宋體';                    context.fillStyle = "#03671F";                    context.fillText(i/5,0,0-(clockDimensions-clockDimensions/5));                    context.fill();                    context.restore();//恢復(fù)當(dāng)前保存的繪制環(huán)境                }else {                    context.save();                    context.beginPath();                    context.lineWidth = Math.floor(clockDimensions/100);                    context.strokeStyle = "#8EA5AB";                    //重置坐標(biāo)原點(diǎn)(0,0)                    context.translate(canvas.width / 2, canvas.height / 2);                    //繪制環(huán)境旋轉(zhuǎn)方法,以(0,0)為參考點(diǎn)進(jìn)行旋轉(zhuǎn)                    context.rotate(Math.PI * 2 / 60 * i);                    context.moveTo(0, clockDimensions-clockDimensions/20);                    context.lineTo(0,  clockDimensions-clockDimensions/10);                    context.stroke();                    context.restore();                }            }            //獲取當(dāng)前windows的時(shí)間            var now = new Date();            var sec = now.getSeconds();            var min = now.getMinutes();            var hour = now.getHours();            //獲取精準(zhǔn)的小時(shí)數(shù)            hour = hour +min/60 + sec/3600;            //轉(zhuǎn)換為12進(jìn)制            hour = hour>12?(hour-12):hour;            //獲取精準(zhǔn)的分鐘數(shù)            min = min + sec/60;            //繪制時(shí)針            context.save();            context.beginPath();            context.lineWidth = clockDimensions/30;            context.strokeStyle = "#596C74";            //重置坐標(biāo)原點(diǎn)(0,0)            context.translate(canvas.width / 2, canvas.height / 2);            //繪制環(huán)境旋轉(zhuǎn)方法,以(0,0)為參考點(diǎn)進(jìn)行旋轉(zhuǎn)            context.rotate(Math.PI * 2 / 12 * hour);            context.moveTo(0, clockDimensions/10);            context.lineTo(0, 0-clockDimensions/2);            context.stroke();            context.restore();            //繪制分針            context.save();            context.beginPath();            context.lineWidth = clockDimensions/40;            context.strokeStyle = "#596C74";            //重置坐標(biāo)原點(diǎn)(0,0)            context.translate(canvas.width / 2, canvas.height / 2);            //繪制環(huán)境旋轉(zhuǎn)方法,以(0,0)為參考點(diǎn)進(jìn)行旋轉(zhuǎn)            context.rotate(Math.PI * 2 / 60 * min);            context.moveTo(0, clockDimensions/8);            context.lineTo(0, 0-(clockDimensions-clockDimensions/5));            context.stroke();            context.restore();            //繪制秒針            context.save();            //重置坐標(biāo)原點(diǎn)(0,0)            context.translate(canvas.width / 2, canvas.height / 2);            context.beginPath();            context.lineWidth = clockDimensions/50;            context.strokeStyle = "#738B93";            //繪制環(huán)境旋轉(zhuǎn)方法,以(0,0)為參考點(diǎn)進(jìn)行旋轉(zhuǎn)            context.rotate(Math.PI * 2 / 60 * sec);            context.moveTo(0, clockDimensions/6);            context.lineTo(0, 0-(clockDimensions-clockDimensions/10));            context.stroke();            //修飾秒針            context.beginPath();            context.arc(0,0-(clockDimensions-clockDimensions/3),clockDimensions/20,0,Math.PI*2,true);            context.fillStyle = "#2FFC14";            context.fill();            context.lineWidth = clockDimensions/50;            context.stroke();            //修飾圓心            context.beginPath();            context.fillStyle = "#738B93";            context.arc(0,0,clockDimensions/20,0,Math.PI*2,true);            context.fill();            context.restore();        }        drowClock();        setInterval(drowClock,1000);    </script></body></html>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 罗平县| 巨野县| 惠安县| 泰州市| 保德县| 汉沽区| 交口县| 涿州市| 米泉市| 濉溪县| 淮滨县| 泰顺县| 章丘市| 德令哈市| 上栗县| 常宁市| 舒城县| 蛟河市| 隆子县| 上虞市| 吴川市| 陆丰市| 原阳县| 丘北县| 田东县| 建湖县| 米林县| 安远县| 通江县| 林芝县| 乌兰察布市| 辽阳市| 祁连县| 玉田县| 葵青区| 南汇区| 茂名市| 夹江县| 拉萨市| 娄烦县| 军事|