亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

canvas時鐘效果

發布時間:2020-07-31 11:31:37 來源:網絡 閱讀:335 作者:素顏豬 欄目:開發技術

效果圖

canvas時鐘效果

html結構

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title>canvas clock</title>

<link rel="stylesheet" href="">

<style>

div{

text-align: center;

margin-top: 250px;

}

</style>

</head>

<body>

<div>

<canvas id="clock" width="500" height="500"></canvas>

</div>

<script type="text/javascript" src="js/clock.js"></script>

</body>

</html>

js腳本

/*1.*/

var dom = document.getElementById("clock");

var ctx = dom.getContext("2d");

var width = ctx.canvas.width;

var height = ctx.canvas.height;

var r = width / 2;

var rem = width / 200;



/*2.*/

function drawBackground(){

ctx.save();

ctx.translate(r,r);

ctx.beginPath();

ctx.lineWidth = 10 * rem;

ctx.arc(0,0,r - ctx.lineWidth / 2,0,2*Math.PI,false);

ctx.stroke();

ctx.closePath();


var hourNumbers = [3,4,5,6,7,8,9,10,11,12,1,2];

ctx.font = 18 * rem +'px Arial';

ctx.textAlign = "center";

ctx.textBaseline = "middle";

hourNumbers.forEach(function(number,i){

var rad = 2 * Math.PI / 12 * i;

var x = Math.cos(rad) * (r-30 * rem);

var y = Math.sin(rad) * (r-30 * rem);

ctx.fillText(number,x,y);

});


for(var i = 0;i< 60;i++){

var rad = 2 * Math.PI / 60 * i;

var x = Math.cos(rad) * (r-18 * rem);

var y = Math.sin(rad) * (r-18 * rem);

ctx.beginPath();

if (i % 5 == 0) {

ctx.fillStyle = "#000";

}else{

ctx.fillStyle = "#ccc";

}

ctx.arc(x,y,2*rem,0,2*Math.PI,false);

ctx.fill();

ctx.closePath();

}

}



/*3*/

function drawCommon(rad,lineWidth,lineCap,moveTo1,moveTo2,lineTo1,lineTo2){

ctx.save();

ctx.beginPath();

ctx.rotate(rad);

ctx.lineWidth = lineWidth;

ctx.lineCap = lineCap;

ctx.moveTo(moveTo1,moveTo2);

ctx.lineTo(lineTo1,lineTo2);

ctx.stroke();

ctx.closePath();

ctx.restore();

}



/*4.*/

function drawHour(hour,minute){

var hrad = 2 * Math.PI / 12 * hour;

var mrad = 2 * Math.PI/ 12 / 60 * minute;

var rad = hrad + mrad;

var lineWidth = 6 * rem;

var lineCap = "round";

var moveTo1 = 0,moveTo2 = 10 * rem;

var lineTo1 = 0,lineTo2 = -r / 2;


drawCommon(rad,lineWidth,lineCap,moveTo1,moveTo2,lineTo1,lineTo2);

}



/*5.*/

function drawMinute(minute){

var rad = 2 * Math.PI / 60 * minute;

var lineWidth = 3 * rem;

var lineCap = "round";

var moveTo1 = 0,moveTo2 = 10 * rem;

var lineTo1 = 0,lineTo2 = -r + 30 * rem;


drawCommon(rad,lineWidth,lineCap,moveTo1,moveTo2,lineTo1,lineTo2);

}



/*6.*/

function drawSecond(second){

var rad = 2 * Math.PI / 60 * second;

ctx.save();

ctx.beginPath();

ctx.fillStyle = "#c14543";

ctx.rotate(rad);

ctx.moveTo(-2 * rem,20 * rem);

ctx.lineTo(2 * rem,20 * rem);

ctx.lineTo(1,-r+18 * rem);

ctx.lineTo(-1,-r+18 * rem);

ctx.fill();

ctx.closePath();

ctx.restore();

}



/*7.*/

function drawDot(){

ctx.beginPath();

ctx.fillStyle = "#fff";

ctx.arc(0,0,3 * rem,0,2*Math.PI,false);

ctx.fill();

ctx.closePath();

}



/*8.*/

function draw(){

ctx.clearRect(0,0,width,height);

var now = new Date();

var hour = now.getHours();

var minute = now.getMinutes();

var second = now.getSeconds();


drawBackground();

drawHour(hour,minute);

drawMinute(minute);

drawSecond(second);

drawDot();

ctx.restore();

}



/*9.*/

draw();

setInterval(draw,1000);

canvas時鐘效果

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宁波市| 榆林市| 奇台县| 福海县| 通许县| 壶关县| 滨州市| 铜陵市| 榆林市| 左贡县| 扎兰屯市| 龙州县| 教育| 延长县| 阿鲁科尔沁旗| 连云港市| 南部县| 南岸区| 淮阳县| 周口市| 喀喇沁旗| 濉溪县| 封丘县| 信宜市| 饶河县| 隆安县| 滨州市| 广水市| 玉林市| 辽阳市| 南涧| 蕉岭县| 武乡县| 商南县| 南皮县| 鄂托克前旗| 明光市| 崇文区| 岳阳市| 天津市| 东至县|