moving dynamic clock

[Total: 0    Average: 0/5]

This script creates an analog clock that dynamically keeps track of time and follows your mouse around the screen.

Init Code:

startDelay();

Body Code:

<SCRIPT language=JavaScript>
var dCol='FF0000';//date colour.
var fCol='00FF00';//face colour.
var sCol='0000FF';//seconds colour.
var mCol='FFFF00';//minutes colour.
var hCol='00FFFF';//hours colour.
var ClockHeight=50;
var ClockWidth =50;
var ClockFromMouseY=0;
var ClockFromMouseX=100;

//Alter nothing below! Alignments will be lost! This script creates a 
//dynamic moving clock. Move your mouse around and watch the clock follow it!

var DAYS_ARRAY=new Array();
DAYS_ARRAY[DAYS_ARRAY.length?DAYS_ARRAY.length:0]="SUNDAY";
DAYS_ARRAY[DAYS_ARRAY.length?DAYS_ARRAY.length:0]="MONDAY";
DAYS_ARRAY[DAYS_ARRAY.length?DAYS_ARRAY.length:0]="TUESDAY";
DAYS_ARRAY[DAYS_ARRAY.length?DAYS_ARRAY.length:0]="WEDNESDAY";
DAYS_ARRAY[DAYS_ARRAY.length?DAYS_ARRAY.length:0]="THURSDAY";
DAYS_ARRAY[DAYS_ARRAY.length?DAYS_ARRAY.length:0]="FRIDAY";
DAYS_ARRAY[DAYS_ARRAY.length?DAYS_ARRAY.length:0]="SATURDAY";

var MONTHS_ARRAY=new Array();
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="JANUARY";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="FEBRUARY";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="MARCH";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="APRIL";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="MAY";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="JUNE";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="JULY";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="AUGUST";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="SEPTEMBER";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="OCTOBER";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="NOVEMBER";
MONTHS_ARRAY[MONTHS_ARRAY.length?MONTHS_ARRAY.length:0]="DECEMBER";

var date=new Date();
var day=date.getDate();
var year=date.getYear();
if (year < 2000) year=year+1900;
var TodaysDate=" "+DAYS_ARRAY[date.getDay()]+" "+day+" "+MONTHS_ARRAY[date.getMonth()]+" "+year;
var D=TodaysDate.split('');
var H='...';
    H=H.split('');
var M='....';
    M=M.split('');
var S='.....';
    S=S.split('');
var FACE='1 2 3 4 5 6 7 8 9 10 11 12';
var font='Arial';
var size=1;
var speed=0.6;
var isDOM=document.getElementById?true:false;

var FACE=FACE.split(' ');
var n=FACE.length;
var a=size*10;
var ymouse=0;
var xmouse=0;
var scrll=0;
var props="<font face="+font+" size="+size+" color="+fCol+"><B>";
var props2="<font face="+font+" size="+size+" color="+dCol+"><B>";
var Split=360/n;
var Dsplit=360/D.length;
var HandHeight=ClockHeight/4.5
var HandWidth=ClockWidth/4.5
var HandY=-7;
var HandX=-2.5;
var scrll=0;
var step=0.06;
var currStep=0;
var y=new Array();
var x=new Array();
var Y=new Array();
var X=new Array();
for (var i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0}
var Dy=new Array();
var Dx=new Array();
var DY=new Array();
var DX=new Array();
for (var i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0}
if(isDOM)
{
  document.write("<div id='Od' style='position:absolute;top:0px;left:0px'>");
  for (var i=0; i < DAYS_ARRAY.length; i++)
  {
    document.write("<div id='domDate"+i+"' ");
    document.write("style='position:absolute;");
    document.write("top:0px;");
    document.write("left:0;");
    document.write("height:"+a+";");
    document.write("width:"+a+";");
    document.write("text-align:center'>");
    document.write(props2+DAYS_ARRAY[i]);
    document.write("</font></div>");
  }
  document.write("</div>");

  document.write("<div id='Of' style='position:absolute;top:0px;left:0px'>");
  for (var i=0; i < FACE.length; i++)
  {
    document.write("<div id='domFace"+i+"' ");
    document.write("style='position:absolute;");
    document.write("top:0px;");
    document.write("left:0;");
    document.write("height:"+a+";");
    document.write("width:"+a+";");
    document.write("text-align:center'>");
    document.write(props+FACE[i]);
    document.write("</font></div>");
  }
  document.write("</div>");

  document.write("<div id='Oh' style='position:absolute;top:0px;left:0px'>");
  for (var i=0; i < H.length; i++)
  {
    document.write("<div id='domHours"+i+"' ");
    document.write("style='position:absolute;");
    document.write("top:0px;");
    document.write("left:0;");
    document.write("height:16px;");
    document.write("width:16px;");
    document.write("text-align:center';");
    document.write("font-family:Arial';");
    document.write("font-size:16px';");
    document.write("font-weight:bold';");
    document.write("color:"+hCol+";>");
    document.write(H[i]);
    document.write("</div>");
  }
  document.write("</div>");

  document.write("<div id='Om' style='position:absolute;top:0px;left:0px'>");
  for (var i=0; i < M.length; i++)
  {
    document.write("<div id='domMinutes"+i+"' ");
    document.write("style='position:absolute;");
    document.write("top:0px;");
    document.write("left:0;");
    document.write("height:16px;");
    document.write("width:16px;");
    document.write("text-align:center';");
    document.write("font-family:Arial';");
    document.write("font-size:16px';");
    document.write("font-weight:bold';");
    document.write("color:"+mCol+";>");
    document.write(M[i]);
    document.write("</div>");
  }
  document.write("</div>");

  document.write("<div id='Os' style='position:absolute;top:0px;left:0px'>");
  for (var i=0; i < S.length; i++)
  {
    document.write("<div id='domSeconds"+i+"' ");
    document.write("style='position:absolute;");
    document.write("top:0px;");
    document.write("left:0;");
    document.write("height:16px;");
    document.write("width:16px;");
    document.write("text-align:center';");
    document.write("font-family:Arial';");
    document.write("font-size:16px';");
    document.write("font-weight:bold';");
    document.write("color:"+sCol+";>");
    document.write(S[i]);
    document.write("</div>");
  }
  document.write("</div>");
}
else
{
document.write("Your browser is not DOM compatible. [you need to upgrade]");
}

ns=document.layers?true:false;
function Mouse(evnt){
ymouse = evnt.clientY+ClockFromMouseY;
xmouse = evnt.clientX+ClockFromMouseX;
}
if(isDOM)
{
  document.onmousemove=Mouse;
}
function ClockAndAssign()
{
time = new Date ();
secs = time.getSeconds();
sec = -1.57 + Math.PI * secs/30;
mins = time.getMinutes();
min = -1.57 + Math.PI * mins/30;
hr = time.getHours();
hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;
if (isDOM)
{
  document.getElementById("Od").style.top=window.document.body.scrollTop;
  document.getElementById("Of").style.top=window.document.body.scrollTop;
  document.getElementById("Oh").style.top=window.document.body.scrollTop;
  document.getElementById("Om").style.top=window.document.body.scrollTop;
  document.getElementById("Os").style.top=window.document.body.scrollTop;
}
for (i=0; i < n; i++){
 var F=document.getElementById("domFace"+i).style;
 F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;
 F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);
 }
for (i=0; i < H.length; i++){
 var HL=document.getElementById("domHours"+i).style;
 HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;
 HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs);
 }
for (i=0; i < M.length; i++){
 var ML=document.getElementById("domMinutes"+i).style;
 ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll;
 ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min);
 }
for (i=0; i < S.length; i++){
 var SL=document.getElementById("domSeconds"+i).style;
 SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll;
 SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec);
 }
for (i=0; i < DAYS_ARRAY.length; i++){
 var DL=document.getElementById("domDate"+i).style;
 DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;
 DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);
 }
currStep-=step;
}
function startDelay()
{
  setInterval("Delay()",20);
}
function Delay(){
scrll=0;
Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);
Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);
for (i=1; i < D.length; i++){
Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed);
Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed);
}
y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
for (i=1; i < n; i++){
y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);
}
ClockAndAssign();
}
</SCRIPT>

Times Viewed: 7

Leave a Reply

Your email address will not be published. Required fields are marked *