var clock=document.getElementById ("jam ");
var cxt=clock.getContext("2d");
function drawNow(){
var now=new Date();
var hour=now.getHours( );
var min=now.getMinutes();
var sec=now.getSeconds();
hour=hour>12?hour-12:hour;
hour=hour min/60 ;
//Dail (biru)
cxt.lineWidth=10;
cxt.strokeStyle="blue"
cxt.beginPath();
cxt.arc(250,250,200,0,360 );
cxt.closePath();
cxt.stroke();
//Skala
//Skala masa
untuk(var i=0;i<12;i ){
cxt.save();
cxt.lineWidth=7;
cxt.strokeStyle="black";
cxt.translate(250,250);
cxt.rotate(i*30* Matematik. PI/180);//Sudut putaran*Math.PI/180=radian
cxt.beginPath();
cxt.moveTo(0,-170);
cxt.lineTo(0, - 190);
cxt.closePath();
cxt.stroke();
cxt.restore();
}
//Skor
untuk(var i=0 ;i<60;i ){
cxt.save();
//Tetapkan ketebalan sub-skala
cxt.lineWidth=5;
//Tetapkan semula asal kanvas
cxt. translate(250,250);
//Tetapkan sudut putaran
cxt.rotate(i*6*Math.PI/180);
//Lukis skala jarum minit
cxt. strokeStyle="black";
cxt.beginPath();
cxt.moveTo(0,-180);
cxt.lineTo(0,-190);
cxt.closePath();
cxt.stroke ();
cxt.restore();
}
//Jam tangan
cxt.save();
// Tetapkan gaya jarum jam
cxt.lineWidth=7;
cxt.strokeStyle="black";
cxt.translate(250,250);
cct.rotate(hour*30*Math.PI/180);
cxt .beginPath();
cxt .moveTo(0,-140);
cxt.lineTo(0,10);
cxt.closePath();
cxt.stroke();
cxt.restore();
//Minute hand
cxt.save();
cxt.lineWidth=5;
cxt.strokeStyle="black";
//Set the tengah kanvas jarum minit dalam dimensi berbeza
cxt .translate(250,250);
cxt.rotate(min*6*Math.PI/180);
cxt.beginPath();
cxt .moveTo(0,-160);
cxt .lineTo(0,15);
cxt.closePath();
cxt.stroke()
cxt.restore();
//Second hand
cxt.save();
//Tetapkan gaya second hand
//Color: red
cxt.strokeStyle="red";
cxt.lineWidth =3;
//Tetapkan semula asal
cxt.translate (250,250);
//Tetapkan sudut
//cxt.rotate(330*Math.PI/180);
cxt.rotate(sec*6*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-170);
cxt.lineTo(0,20);
cxt.closePath();
cxt.stroke();
//Lukis persilangan jarum jam, jarum minit dan jarum detik
cxt.beginPath();
cxt.arc( 0,0,5,0,360,false);
cxt.closePath();
//Set fill
cxt.fillStyle="gray";
cxt.fill();
//cxt.strokeStyle="red";
cxt.stroke();
//Lukis titik kecil untuk tangan kedua
cxt.beginPath();
cxt.arc(0, -140,5,0,360,false);
cxt.closePath();
//Set the fill
cxt.fillStyle="gray";
cxt.fill();
//cxt.strokeStyle="red";
cxt.stroke(); p>
cxt.restore();
}
fungsi drawClock(){
cxt.clearRect(0,0,500,500);
drawNow();
}
drawNow();
setInterval(drawClock, 1000);