Make Clock

By (user deleted)

Description

It same time on your phone :)

Code

Insert this code into your page

[[html]]
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="400" height="400"
style="background-color:#333">
</canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var radius = canvas.height / 2;
ctx.translate(radius, radius);
radius = radius * 0.90
setInterval(drawClock, 1000);
function drawClock() {
 drawFace(ctx, radius);
 drawNumbers(ctx, radius);
 drawTime(ctx, radius);
}
function drawFace(ctx, radius) {
 var grad;
 ctx.beginPath();
 ctx.arc(0, 0, radius, 0, 2*Math.PI);
 ctx.fillStyle = 'white';
 ctx.fill();
 grad = ctx.createRadialGradient(0,0,radius*0.95, 0,0,radius*1.05);
 grad.addColorStop(0, '#333');
 grad.addColorStop(0.5, 'white');
 grad.addColorStop(1, '#333');
 ctx.strokeStyle = grad;
 ctx.lineWidth = radius*0.1;
 ctx.stroke();
 ctx.beginPath();
 ctx.arc(0, 0, radius*0.1, 0, 2*Math.PI);
 ctx.fillStyle = '#333';
 ctx.fill();
}
function drawNumbers(ctx, radius) {
 var ang;
 var num;
 ctx.font = radius*0.15 + "px arial";
 ctx.textBaseline="middle";
 ctx.textAlign="center";
 for(num = 1; num < 13; num++){
 ang = num * Math.PI / 6;
 ctx.rotate(ang);
 ctx.translate(0, -radius*0.85);
 ctx.rotate(-ang);
 ctx.fillText(num.toString(), 0, 0);
 ctx.rotate(ang);
 ctx.translate(0, radius*0.85);
 ctx.rotate(-ang);
 }
}
function drawTime(ctx, radius){
 var now = new Date();
 var hour = now.getHours();
 var minute = now.getMinutes();
 var second = now.getSeconds();
 //hour
 hour=hour%12;
 hour=(hour*Math.PI/6)+
 (minute*Math.PI/(6*60))+
 (second*Math.PI/(360*60));
 drawHand(ctx, hour, radius*0.5, radius*0.07);
 //minute
 minute=(minute*Math.PI/30)+(second*Math.PI/(30*60));
 drawHand(ctx, minute, radius*0.8, radius*0.07);
 // second
 second=(second*Math.PI/30);
 drawHand(ctx, second, radius*0.9, radius*0.02);
}
function drawHand(ctx, pos, length, width) {
 ctx.beginPath();
 ctx.lineWidth = width;
 ctx.lineCap = "round";
 ctx.moveTo(0,0);
 ctx.rotate(pos);
 ctx.lineTo(0, -length);
 ctx.stroke();
 ctx.rotate(-pos);
}
</script>
</body>
</html>
[[/html]]

In action

After inserting

[フレーム]


Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by (user deleted)

Find untagged pages - 15 Feb 2012 00:52
Feed And Zoho Creator Integration - 15 Feb 2012 00:52
Feed Aggregator - 15 Feb 2012 00:52
Extra Side Bar - 15 Feb 2012 00:51
Embed your latest Twitter tweets - 15 Feb 2012 00:50
Embed Code From Other Services - 15 Feb 2012 00:50
EditGrid Spreadsheets - 15 Feb 2012 00:49
Easy Table Title Footers - 15 Feb 2012 00:49
Drop Caps - 15 Feb 2012 00:48
Display Random YT Video - 15 Feb 2012 00:48
Delicious Linkrolls - 15 Feb 2012 00:48
Dailymotion - 15 Feb 2012 00:42
Custom Toolbar Separators - 15 Feb 2012 00:41
CSI Cross site includes - 15 Feb 2012 00:40
Create an RSS Feed Button with Caption - 15 Feb 2012 00:40
Cornify - 15 Feb 2012 00:39
Conditional Blocks - 15 Feb 2012 00:36
Compact Feed Display - 15 Feb 2012 00:35
Collapsible Block Unleashed - 15 Feb 2012 00:33
Choose A Page! - 15 Feb 2012 00:32
Center Video - 15 Feb 2012 00:28
Cbox chatroom - 15 Feb 2012 00:28
Category Templates And Newpage - 15 Feb 2012 00:27
Categories - 15 Feb 2012 00:27
Calc5 - 15 Feb 2012 00:27
Block In Fixed Position In Browser - 15 Feb 2012 00:26
Blip TV - 15 Feb 2012 00:26
Bibliography/Footnotes/Comments Listed in TOC - 15 Feb 2012 00:26
Automatic Sitemap - 15 Feb 2012 00:25
Animoto - 15 Feb 2012 00:23
Alexa traffic ratings - 15 Feb 2012 00:23
Adding A Site Logo - 15 Feb 2012 00:23
3d tagcloud - 15 Feb 2012 00:22
Custom Permissions Error Message - 14 Feb 2012 03:42
New Tabview - 24 Oct 2011 23:53
Random Page - 18 May 2011 09:50
Previous and Next Navigation With ListPages - 24 Nov 2010 15:14
Redirect - 11 Feb 2010 10:00
Spoiler tags - 03 Nov 2009 13:30
How to format wikidot pages using HTML - 04 Aug 2009 15:05
Redirect: From (1st) - 01 Mar 2009 18:18
Redirect: From (2nd) - 01 Mar 2009 18:17
WEB 2.0 tools for Database - 16 Oct 2008 10:48

page 3 of 3« previous 1 2 3

Rate this solution

If you think this solution is useful — rate it up!

rating: +8
How to change its size
lestday233 lestday233 11 Feb 2022 07:15

How to change its size


欢迎访问我的个人主页博客维基

莫谈纷争多扰攘,心宽自可化桑田

by lestday233 lestday233 , 11 Feb 2022 07:15
page revision: 1, last edited: 10 Jan 2021 08:28
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).

AltStyle によって変換されたページ (->オリジナル) /