就着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的更多相关文章

  1. JTAG Simplified

    JTAG Simplified So the other day, I explored the JTAG bus interface which is frequently found in CPL ...

  2. [Angular 2] Passing Observables into Components with Async Pipe

    The components inside of your container components can easily accept Observables. You simply define ...

  3. [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 ...

  4. Glitch-free clock switch

    With multi-frequency clocks being used in today’s devices, it's necessary to switch the source of a ...

  5. 修改Linux系统日期与时间date clock

    先设置日期 date -s 20080103 再设置时间 date -s 18:24:30 为了永久生效,需要将修改的时间写入CMOS. 查看CMOS的时间: #clock -r 将当前系统时间写到C ...

  6. 操作系统页面置换算法(opt,lru,fifo,clock)实现

    选择调出页面的算法就称为页面置换算法.好的页面置换算法应有较低的页面更换频率,也就是说,应将以后不会再访问或者以后较长时间内不会再访问的页面先调出. 常见的置换算法有以下四种(以下来自操作系统课本). ...

  7. Cesium应用篇:3控件(1)Clock

    创建 跟Clock相关的主要有Animation控件和Timeline控件,通常两者会放在一起使用. 在Cesium中,Viewer默认开启这两个控件,如果你想要不显示控件,可以在Viewer初始化中 ...

  8. 解决: 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 ...

  9. Unity: Passing Constructor Parameters to Resolve

    In this tutorial we will go through of couple different ways of using custom constructor parameters ...

随机推荐

  1. String Reconstruction (并查集)

    并查集维护和我这个位置的字母连续的已经被填充的字母能到达的最右边的第一个还没有填充的位置,然后把这个位置填上应该填的东西,然后把这个位置和下一个位置连接起来,如果下一个位置还没有填,我就会把下一个位置 ...

  2. 微信小程序支付(PHP后端)

    1.申请开通小程序支付,我们正式开通的微信支付是在微信公众平台上,我们需要绑定之前的微信商户平台即可,这一点不过多强调 2.小程序支付开发步骤 (1).统一下单 大家看到微信的统一下单接口密密麻麻的一 ...

  3. JS小积累(二)— 自动获取浏览器尺寸

    JS小积累-获取浏览器窗口尺寸 作者: 狐狸家的鱼 GitHub:八至 autodivheight(); function autodivheight() { //函数:获取尺寸 //获取浏览器窗口高 ...

  4. DAY1初识Python----变量及命名规则,注释,数据类型,常量,交互

     1.认识和了解python  python是一门解释型语言,弱类型语言 2.python发展史   2008年 2.X,3.X 3.第一个python程序  python语句可以写在命令行中,进行编 ...

  5. 使用 windows 下的 secureCRT 软件的 通过 sftp 上传和下载文件到远端 linux 设备

    secureCRT 按下ALT+P就开启新的会话进行ftp操作. 输入:help命令,显示该FTP提供所有的命令 pwd:  查询linux主机所在目录(也就是远程主机目录) lpwd: 查询本地目录 ...

  6. ArrayList 实现随机点名

    package lijun.cn.demo1; import java.util.ArrayList; import java.util.Random; public class CallName { ...

  7. nginx根据cookie分流

    转载互联网 nginx根据cookie分流众所周知,nginx可以根据url path进行分流,殊不知对于cookie分流也很强大,同时这也是我上篇提到的小流量实验的基础. 二话不说,先看需求,两台服 ...

  8. 物理服务器Linux下软RAID和UUID方式挂载方法--Megacli64

    一.业务部门需求说明:公司最近来了一批服务器,用于大数据业务部署.数据节点服务器由14块物理磁盘,其中有2块是900G的盘,12块是4T的盘.在服务器系统安装时,进入系统的BIOS界面:1)将2块90 ...

  9. 兄弟连Linux运维学习笔记

    最新经典linux运维兄弟连Linux运维学习笔记... --------------- 全程1.5倍播放.加油我一定可以学完Linux----------------------Unix与Linux ...

  10. #1479 : 三等分(树形DP)

    http://hihocoder.com/problemset/problem/1479 #1479 : 三等分 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最 ...