就着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. kafka清理数据日志

    背景问题: 使用kafka的路上踩过不少坑,其中一个就是在测试环境使用kafka一阵子以后,发现其日志目录变的很大,占了磁盘很大空间,定位到指定目录下发现其中一个系统自动创建的 topic,__con ...

  2. Centos7下源码编译安装python3.6

    测试环境: 操作步骤: 1. 下载Python源码包(python3.6.0) 官网下载地址:https://www.python.org/downloads/ 搜狐下载地址:http://mirro ...

  3. javascript Object的新方法

    今天复习es6,又看到Object的一堆方法,与es5的表现又有不一致,耗费了一整天,整理一下: 前几天在司徒正美的书里又看到了es5 Object的字眼,为了向下兼容,大神们也是牛逼的整理出一系列i ...

  4. Surface Pro 4 系统优化全教程及QA

    甲.如何根据你的需求选择相应版本的surface1.Core M3-6Y30,Core i5-6300U,Core i7-6650U的性能差距有多大?2.HD 515,HD520,Iris 540的性 ...

  5. (五)Oracle 的 oracle 表查询

    http://www.hechaku.com/Oracle/oracle_tables_chack.html 通过scott用户下的表来演示如何使用select语句,接下来对emp.dept.salg ...

  6. 记录替换django的user模型出现的异常InconsistentMigrationHistory

    django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applie ...

  7. PHP和PHP-FPM 配置文件优化

    前言:乘着这次空闲,来记录下关于PHP和PHP-FPM配置文件的优化,也方便以后自己复习. 先说PHP的 1.PHP脚本执行时间 max_execution_time = 30 该选项设定PHP程序的 ...

  8. Nginx.conf配置文件参数说明与优化

    参考连接:nginx 核心配置优化详解 先说下优化 1.nginx运行工作进程个数 worker_processes  1; Nginx进程,一般设置为和cpu核数一样(nginx启动后有多少个wor ...

  9. template specifiers not specified in declaration of ‘template<class Key> class hash’

    尝试写显示特化样例的时候,写了如下代码 #include <iostream> #include <cstddef> using namespace std; #define ...

  10. plsql无法正常显示汉字

    首先执行语句 select * from V$NLS_PARAMETERS  查看第一行中PARAMETER项中为NLS_LANGUAGE 对应的VALUE项中是否为SIMPLIFIED CHINES ...