HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
In these chapters we build an analog clock using HTML Canvas
To start the clock, call the drawClock function at intervals:
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var radius = canvas.height / 2;
ctx.translate(radius, radius);
radius = radius * 0.90
//drawClock();
setInterval(drawClock, 1000);
The only thing you have to do (to start the clock) is to call the drawClock function at intervals.
Substitute:
drawClock();
With:
setInterval(drawClock, 1000);
The interval is in milliseconds. drawClock will be called for each 1000 milliseconds.
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); }