【小玩意】time-passing-by clock
就着youtube上的教程用html和js做了个小时钟。
Code:
clock.html
//clock.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<canvas id="canvas" width="500" height="500">
<script type="text/javascript" src="C:\Users\Administrator\Desktop\Clock\clock.js"></script>
</canvas>
</body>
</html>
clock.js
//clock.js
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.strokeStyle = 'lightblue';
ctx.lineWidth = 17;
ctx.lineCap = 'round';
ctx.shadowBlur = 15;
ctx.shadowColor = 'lightblue'; function degToRad(degree) {
var factor = Math.PI/180;
return degree*factor;
} function renderTime() { var now = new Date();
var today = now.toDateString();
var time = now.toLocaleTimeString();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var milliseconds = now.getMilliseconds();
var newSeconds = seconds+(milliseconds/1000); //Background
gradient = ctx.createRadialGradient(250, 250, 5, 250, 250, 300);
gradient.addColorStop(0,'GREY');
gradient.addColorStop(1,'BLACK');
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 500, 500); //Hours
ctx.beginPath();
ctx.arc(250, 250, 200, degToRad(270), degToRad(hours*15-90));
ctx.stroke(); //Minutes
ctx.beginPath();
ctx.arc(250, 250, 170, degToRad(270), degToRad(minutes*6-90));
ctx.stroke(); //Seconds
ctx.beginPath();
ctx.arc(250, 250, 140, degToRad(270), degToRad(newSeconds*6-90));
ctx.stroke(); //Date
ctx.font = "25px Arial";
ctx.fillStyle = 'lightblue';
ctx.fillText(today, 175, 250); //Time
ctx.font = "25px Arial";
ctx.fillStyle = 'lightblue';
ctx.fillText(time, 175, 280); } setInterval(renderTime, 40);
效果图:我配色是真的无能= - =

【小玩意】time-passing-by clock的更多相关文章
- JTAG Simplified
JTAG Simplified So the other day, I explored the JTAG bus interface which is frequently found in CPL ...
- [Angular 2] Passing Observables into Components with Async Pipe
The components inside of your container components can easily accept Observables. You simply define ...
- [Angular 2] Passing Template Input Values to Reducers
Angular 2 allows you to pass values from inputs simply by referencing them in the template and passi ...
- Glitch-free clock switch
With multi-frequency clocks being used in today’s devices, it's necessary to switch the source of a ...
- 修改Linux系统日期与时间date clock
先设置日期 date -s 20080103 再设置时间 date -s 18:24:30 为了永久生效,需要将修改的时间写入CMOS. 查看CMOS的时间: #clock -r 将当前系统时间写到C ...
- 操作系统页面置换算法(opt,lru,fifo,clock)实现
选择调出页面的算法就称为页面置换算法.好的页面置换算法应有较低的页面更换频率,也就是说,应将以后不会再访问或者以后较长时间内不会再访问的页面先调出. 常见的置换算法有以下四种(以下来自操作系统课本). ...
- Cesium应用篇:3控件(1)Clock
创建 跟Clock相关的主要有Animation控件和Timeline控件,通常两者会放在一起使用. 在Cesium中,Viewer默认开启这两个控件,如果你想要不显示控件,可以在Viewer初始化中 ...
- 解决: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19
错误信息:C:\Python27\lib\site-packages\sklearn\utils\validation.py:395: DeprecationWarning: Passing 1d a ...
- Unity: Passing Constructor Parameters to Resolve
In this tutorial we will go through of couple different ways of using custom constructor parameters ...
随机推荐
- 【php】php位运算及其高级应用
我们之前学过逻辑与(&&) 条件1 && 条件2 当两边条件同时成立时候返回1 逻辑或(||) 条件1 || 条件2 当两边条件只要有一 ...
- A.01.01—模块的输入—低端输入
汽车电子模块的输入一般包含数字量低端输入.数字量高端输入.模拟量输入.脉宽调制输入.总线信号输入.脉冲信号输入,对于无线信号输入和视频信号音频信号我们不做讨论. 数字量低端输入是应用最为广泛的一种输入 ...
- Python模块之time、random、os、sys、序列化、re
Time模块 和时间有关系的我们就要用到时间模块.在使用模块之前,应该首先导入这个模块. #常用方法 1.time.sleep(secs) (线程)推迟指定的时间运行.单位为秒. 2.time.tim ...
- poj 3258"River Hopscotch"(二分搜索+最大化最小值问题)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 块岩石,从中去掉任意 M 块后,求相邻两块岩石最小距离最大是多少? 题解 ...
- poj 2229 Sumsets(记录结果再利用的DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 将一个数N分解为2的幂之和共有几种分法? 题解: 定义dp[ i ]为数 i 的 ...
- A*搜索算法
先了解一下什么是A*算法. A*搜寻算法,俗称A星算法.A*算法是用于寻找两点之间的最短路径,同时它也是一种静态路网中求解最短路最有效的直搜索方法.这是一种在图形平面上,有多个节点的路径,求出最低通过 ...
- Luogu P2336 [SCOI2012]喵星球上的点名
题目链接 \(Click Here\)_ \(200\)行纯干货的代码,一发\(WA\)掉真的是让人窒息,幸好最后找到了锅在哪.(差点就要弃掉了\(QAQ\)) [调出来的时候真的是要高兴到哭出来了\ ...
- 干货分享:互联网运营 学习SEO从零开始 SEO深度解析学习笔记
最近在自学SEO,互联网运营,把做的笔记干货分享给大家啊! 希望能帮到大家,如有好的建议可以关注我[磨人的小妖精]或留言,大家一起探讨. 之前还写过一篇文章互联网运营+SEO:推荐必看的5本书籍,学习 ...
- 洛谷P1073 Tarjan + 拓扑排序 // 构造分层图
https://www.luogu.org/problemnew/show/P1073 C国有 n n个大城市和 mm 条道路,每条道路连接这 nn个城市中的某两个城市.任意两个城市之间最多只有一条道 ...
- 极光推送java代码
package com.zheng.cms.web.jpush.util; import cn.jpush.api.JPushClient; import cn.jpush.api.common.AP ...