Advertise Here

Author Topic: [Code] Clock  (Read 2239 times)

0 Members and 1 Guest are viewing this topic.

Offline Stewie343

  • SMF For Free Newbie
  • *
  • Posts: 15
    • View Profile
    • Nintendo Hardcore

  • Total Badges: 11
    Badges: (View All)
    Topic Starter Combination Level 2 Level 1 10 Posts
[Code] Clock
« on: October 29, 2007, 07:55:54 pm »
Here is a clock I made. It follows your cursor. It follows the time on your computer. It displays the month, date and time.
Here is the code:

It can go in your header or footers.
Code: [Select]
<SCRIPT language=JavaScript>
dCol='#FF0000';//date colour.
fCol='#0000FF';//face colour.
sCol='#FFFF00';//seconds colour.
mCol='#FF0000';//minutes colour.
hCol='#00FF00';//hours colour.
ClockHeight=50;
ClockWidth=50;
ClockFromMouseY=0;
ClockFromMouseX=100;

//Created by Stewie343
//Alter nothing below! Alignments will be lost!

days=new Array("SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY");
m=new Array("JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER");
date=new Date();
day=date.getDate();
year=date.getYear();
if (year < 2000) year=year+1900;
TodaysDate=" "+days[date.getDay()]+" "+day+" "+m[date.getMonth()]+" "+year;
D=TodaysDate.split('');
clockH='...';
clockH=clockH.split('');
M='....';
M=M.split('');
S='.....';
S=S.split('');
Face='1 2 3 4 5 6 7 8 9 10 11 12';
font='Arial';
size=1;
clkspeed=0.6;
ns=(document.layers);
ie=!ns;
Face=Face.split(' ');
faceLength=Face.length;
a=size*10;
ymouse=0;
xmouse=0;
scrll=0;
props="<font face="+font+" size="+size+" color="+fCol+"><B>";
props2="<font face="+font+" size="+size+" color="+dCol+"><B>";
Split=360/faceLength;
Dsplit=360/D.length;
HandHeight=ClockHeight/4.5
HandWidth=ClockWidth/4.5
HandY=-7;
HandX=-2.5;
scrll=0;
if (ie && !(document.all)){
  step=0.09;
} else {
  step=0.06;
}

currStep=0;
clocky=new Array();clockx=new Array();clockY=new Array();clockX=new Array();
for (clki=0; clki < faceLength; clki++){clocky[clki]=0;clockx[clki]=0;clockY[clki]=0;clockX[clki]=0}
clockDy=new Array();clockDx=new Array();clockDY=new Array();clockDX=new Array();
for (clki=0; clki < D.length; clki++){clockDy[clki]=0;clockDx[clki]=0;clockDY[clki]=0;clockDX[clki]=0}
if (ns){
for (clki=0; clki < D.length; clki++)
document.write('<layer name="nsDate'+clki+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[clki]+'</font></center></layer>');
for (clki=0; clki < faceLength; clki++)
document.write('<layer name="nsFace'+clki+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[clki]+'</font></center></layer>');
for (clki=0; clki < S.length; clki++)
document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S[clki]+'</b></center></font></layer>');
for (clki=0; clki < M.length; clki++)
document.write('<layer name=nsMinutes'+clki+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M[clki]+'</b></center></font></layer>');
for (clki=0; clki < clockH.length; clki++)
document.write('<layer name=nsHours'+clki+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center><b>'+clockH[clki]+'</b></center></font></layer>');
}
if (ie){
document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (clki=0; clki < D.length; clki++)
document.write('<div id="ieDate'+clki+'" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[clki]+'</B></font></div>');
document.write('</div></div>');
document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (clki=0; clki < faceLength; clki++)
document.write('<div id="ieFace' + clki + '" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[clki]+'</B></font></div>');
document.write('</div></div>');
document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (clki=0; clki < clockH.length; clki++)
document.write('<div id="ieHours' + clki + '" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+clockH[clki]+'</div>');
document.write('</div></div>');
document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (clki=0; clki < M.length; clki++)
document.write('<div id="ieMinutes'+clki+'" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[clki]+'</div>');
document.write('</div></div>')
document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
for (clki=0; clki < S.length; clki++)
document.write('<div id="ieSeconds'+clki+'" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[clki]+'</div>');
document.write('</div></div>')
}
(ns)?window.captureEvents(Event.MOUSEMOVE):0;
function Mouse(evnt){
ymouse = (!document.all)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
xmouse = (!document.all)?evnt.pageX+ClockFromMouseX:event.x+ClockFromMouseX;
}
(ns)?window.onMouseMove=Mouse: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 (ie){
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 (clki=0; clki < faceLength; clki++){
 var F=(ns)?document.layers['nsFace'+i]:document.getElementById("ieFace" + clki ).style;
 F.top=clocky[clki] + ClockHeight*Math.sin(-1.0471 + clki*Split*Math.PI/180)+scrll;
 F.left=clockx[clki] + ClockWidth*Math.cos(-1.0471 + clki*Split*Math.PI/180);
 }
for (clki=0; clki < clockH.length; clki++){
 var HL=(ns)?document.layers['nsHours'+clki]:document.getElementById("ieHours"+clki).style;
 HL.top=clocky[clki]+HandY+(clki*HandHeight)*Math.sin(hrs)+scrll;
 HL.left=clockx[clki]+HandX+(clki*HandWidth)*Math.cos(hrs);
 }
for (clki=0; clki < M.length; clki++){
 var ML=(ns)?document.layers['nsMinutes'+clki]:document.getElementById("ieMinutes"+clki).style;
 ML.top=clocky[clki]+HandY+(clki*HandHeight)*Math.sin(min)+scrll;
 ML.left=clockx[clki]+HandX+(clki*HandWidth)*Math.cos(min);
 }
for (clki=0; clki < S.length; clki++){
 var SL=(ns)?document.layers['nsSeconds'+clki]:document.getElementById("ieSeconds" + clki).style;
 SL.top=clocky[clki]+HandY+(clki*HandHeight)*Math.sin(sec)+scrll;
 SL.left=clockx[clki]+HandX+(clki*HandWidth)*Math.cos(sec);
 }
for (clki=0; clki < D.length; clki++){
 var DL=(ns)?document.layers['nsDate'+clki]:document.getElementById("ieDate" + clki).style;
 DL.top=clockDy[clki] + ClockHeight*1.5*Math.sin(currStep+clki*Dsplit*Math.PI/180)+scrll;
 DL.left=clockDx[clki] + ClockWidth*1.5*Math.cos(currStep+clki*Dsplit*Math.PI/180);
 }
currStep-=step;
}
function Delay(){
scrll=(ns)?window.pageYOffset:0;
clockDy[0]=Math.round(clockDY[0]+=((ymouse)-clockDY[0])*clkspeed);
clockDx[0]=Math.round(clockDX[0]+=((xmouse)-clockDX[0])*clkspeed);
for (clki=1; clki < D.length; clki++){
clockDy[clki]=Math.round(clockDY[clki]+=(clockDy[clki-1]-clockDY[clki])*clkspeed);
clockDx[clki]=Math.round(clockDX[clki]+=(clockDx[clki-1]-clockDX[clki])*clkspeed);
}
clocky[0]=Math.round(clockY[0]+=((ymouse)-clockY[0])*clkspeed);
clockx[0]=Math.round(clockX[0]+=((xmouse)-clockX[0])*clkspeed);
for (clki=1; clki < faceLength; clki++){
clocky[clki]=Math.round(clockY[clki]+=(clocky[clki-1]-clockY[clki])*clkspeed);
clockx[clki]=Math.round(clockX[clki]+=(clockx[clki-1]-clockX[clki])*clkspeed);
}
ClockAndAssign();
setTimeout('Delay()',30);
}

if (ns||ie) {
Delay();
}
</SCRIPT>
It currently only works on IE. You can change the colors of the clock, by changing the color codes at the beginning  of the code.
I made it follow your cursor up to a certain point, so it would not get in your way when you're trying to read something.
« Last Edit: October 29, 2007, 08:10:32 pm by Stewie343 »


Offline jonsploder

  • SMF For Free Member
  • *
  • Posts: 21
    • View Profile

  • Total Badges: 10
    Badges: (View All)
    Topic Starter Combination Level 2 Level 1 10 Posts
Re: [Code] Clock
« Reply #1 on: November 03, 2007, 05:01:45 am »
Cool, man you rock. But please give an example.

Offline Stewie343

  • SMF For Free Newbie
  • *
  • Posts: 15
    • View Profile
    • Nintendo Hardcore

  • Total Badges: 11
    Badges: (View All)
    Topic Starter Combination Level 2 Level 1 10 Posts
Re: [Code] Clock
« Reply #2 on: November 03, 2007, 04:09:07 pm »


Offline Hurricane47

  • SMF For Free Master
  • *
  • Posts: 1108
    • View Profile
    • My Graphics Forum!

  • Total Badges: 27
    Badges: (View All)
    Windows User Poll Starter Poll Voter Level 5 Webmaster
Re: [Code] Clock
« Reply #3 on: November 03, 2007, 05:05:38 pm »
kool! But I dont think I would use it, sorry

 

Related Topics

  Subject / Started by Replies Last post
6 Replies
2782 Views
Last post November 16, 2008, 02:20:53 pm
by simply sibyl
15 Replies
7134 Views
Last post August 05, 2007, 04:10:34 am
by guest1608
0 Replies
2638 Views
Last post January 09, 2007, 07:31:39 am
by Legend_Killer
2 Replies
1384 Views
Last post March 29, 2008, 12:19:38 pm
by -Sя.Sharp
1 Replies
1803 Views
Last post December 14, 2008, 03:40:50 am
by WBA Dude