SitePoint Sponsor

User Tag List

Results 1 to 21 of 21

Thread: Amazing Clock!

  1. #1
    SitePoint Wizard dominique's Avatar
    Join Date
    Dec 2000
    Location
    orbis terrarum
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Amazing Clock!

    This is the coolest JavaScript clock! Just save the code as an HTML file and open it in your browser.

    There is no malicious code, that I know of anyway.

    Part 1
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252">
    <META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
    <BODY>
    <SCRIPT language=JavaScript>
    dCol='000000';//date colour.
    fCol='000000';//face colour.
    sCol='000000';//seconds colour.
    mCol='000000';//minutes colour.
    hCol='000000';//hours colour.
    ClockHeight=40;
    ClockWidth=40;
    ClockFromMouseY=0;
    ClockFromMouseX=100;
    
    //Alter nothing below! Alignments will be lost!
    
    d=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=" "+d[date.getDay()]+" "+day+" "+m[date.getMonth()]+" "+year;
    D=TodaysDate.split('');
    H='...';
    H=H.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;
    speed=0.6;
    ns=(document.layers);
    ie=(document.all);
    Face=Face.split(' ');
    n=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/n;
    Dsplit=360/D.length;
    HandHeight=ClockHeight/4.5
    HandWidth=ClockWidth/4.5
    HandY=-7;
    HandX=-2.5;
    scrll=0;
    step=0.06;
    currStep=0;
    y=new Array();x=new Array();Y=new Array();X=new Array();
    for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0}
    Dy=new Array();Dx=new Array();DY=new Array();DX=new Array();
    for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0}
    if (ns){
    for (i=0; i < D.length; i++)
    document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>');
    for (i=0; i < n; i++)
    document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>');
    for (i=0; i < S.length; i++)
    document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></layer>');
    for (i=0; i < M.length; i++)
    document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center><b>'+M[i]+'</b></center></font></layer>');
    for (i=0; i < H.length; i++)
    document.write('<layer name=nsHours'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center><b>'+H[i]+'</b></center></font></layer>');
    }
    if (ie){
    document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < D.length; i++)
    document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props2+D[i]+'</B></font></div>');
    document.write('</div></div>');
    document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < n; i++)
    document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a+';width:'+a+';text-align:center">'+props+Face[i]+'</B></font></div>');
    document.write('</div></div>');
    document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < H.length; i++)
    document.write('<div id="ieHours" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>');
    document.write('</div></div>');
    document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < M.length; i++)
    document.write('<div id="ieMinutes" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>');
    document.write('</div></div>')
    document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < S.length; i++)
    document.write('<div id="ieSeconds" style="position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>');
    document.write('</div></div>')
    }

  2. #2
    SitePoint Wizard dominique's Avatar
    Join Date
    Dec 2000
    Location
    orbis terrarum
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Part 2
    Code:
    (ns)?window.captureEvents(Event.MOUSEMOVE):0;
    function Mouse(evnt){
    ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
    xmouse = (ns)?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){
    Od.style.top=window.document.body.scrollTop;
    Of.style.top=window.document.body.scrollTop;
    Oh.style.top=window.document.body.scrollTop;
    Om.style.top=window.document.body.scrollTop;
    Os.style.top=window.document.body.scrollTop;
    }
    for (i=0; i < n; i++){
     var F=(ns)?document.layers['nsFace'+i]:ieFace[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=(ns)?document.layers['nsHours'+i]:ieHours[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=(ns)?document.layers['nsMinutes'+i]:ieMinutes[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=(ns)?document.layers['nsSeconds'+i]:ieSeconds[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 < D.length; i++){
     var DL=(ns)?document.layers['nsDate'+i]:ieDate[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 Delay(){
    scrll=(ns)?window.pageYOffset: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();
    setTimeout('Delay()',20);
    }
    if (ns||ie)window.onload=Delay;
    </SCRIPT>
    <BR><BR><BR><BR><BR><BR><BR><BR><BR><FONT color=blue>Hi SitePointers, this is 
    amazing!</FONT><BR>I do not know who wrote this HTML code.</BODY></HTML>

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could someone explain?

    var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style;

    what the '?' means and ':'

  4. #4
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Andrew-J2000
    Could someone explain?

    var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style;

    what the '?' means and ':'
    I forget what they are actually called. But esentially

    () is the if statement
    ? is the first choice
    : is the else
    ; end

    so

    (age=21)?document.write("I am 21"):document.write("I am not 21");

    Pseudo code
    if my age is 21
    echo "I am 21"
    else my age isn't 21
    echo "I am not 21"

    Damn I wish I could remember what they are called but they are my favorite way to do small and effective conditions...This technique works in php and any c syntax language (from what I know)
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  5. #5
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's a one-line switch. If the left is true, execute the left, if the right is true, execute the right
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  6. #6
    SitePoint Wizard dominique's Avatar
    Join Date
    Dec 2000
    Location
    orbis terrarum
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They are called trinaries.

    As Maelstrom and Jeremy W. indicated, a trinary generally takes the form of:

    boolean ? true : false

    , depending on your language of implementation, in which you replace boolean with the proper statement you want tested, and true and false with the proper statements you want executed.

    If boolean is true, then the true statement will be executed, else the false statement will be executed.


    Just out of curiosity, has anyone actually saved the code to see the clock? It's the most amazing clock ever!

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea I did, Looks good.

    thanks for that, strange name for it though?

  8. #8
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    spinny

  9. #9
    SitePoint Wizard dominique's Avatar
    Join Date
    Dec 2000
    Location
    orbis terrarum
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Andrew-J2000
    thanks for that, strange name for it though?
    You mean "trinary"? Not really, it does have three parts to it -> tri.

  10. #10
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as apposed to Bi(two)nary

    quadary?

  11. #11
    busy Steelsun's Avatar
    Join Date
    Mar 2001
    Location
    Houston, Tejas; Future Capital of the World
    Posts
    2,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anybody have the code up on a page for others to look at?
    Brian Poirier
    SunStockPhoto: Stock Photos, Fine Art Photos, Event Photography

  12. #12
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    dom, the spinny text is VERY distracting, but this is quite possibly the coolest whatsit ever...

    What's a whatsit, you might ask?

    Totally useless and yet totally cool
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  13. #13
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe that just lazinss

  14. #14
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  15. #15
    Non-Member mmi's Avatar
    Join Date
    Jun 2001
    Location
    Rhode Island
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't get this to work on mmy N6 - the page I created yesterday didn't work - figured it was something I did wrong, although there was precious little opportunity - but now Jeremy's page seems "timeless" on N6 as well

  16. #16
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I just tried NS6.2 and didn't get it either.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  17. #17
    Non-Member mmi's Avatar
    Join Date
    Jun 2001
    Location
    Rhode Island
    Posts
    587
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just to be clear, it does work on N4.78

  18. #18
    SitePoint Wizard dominique's Avatar
    Join Date
    Dec 2000
    Location
    orbis terrarum
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm glad you guys like it! I was flabbergasted by it!


    Hmm, I should probably change
    Code:
    <FONT color=blue>Hi SitePointers, this is 
    amazing!</FONT><BR>I do not know who wrote this HTML code.
    with
    Code:
    <FONT color=blue>Hi SitePointers, this is 
    amazing!</FONT><BR>I do not know who wrote this JavaScript code.
    seeing how it is JavaScript and not HTML afterall.

  19. #19
    busy Steelsun's Avatar
    Join Date
    Mar 2001
    Location
    Houston, Tejas; Future Capital of the World
    Posts
    2,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeremy.

    It is a neat effect. My wife had received it a few weeks back via email somehow. I did have to yell at her for having Javascript enabled in her email though.
    Brian Poirier
    SunStockPhoto: Stock Photos, Fine Art Photos, Event Photography

  20. #20
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how long do you think before this is on every geocities page ever made?

  21. #21
    pg for mild peril cow's Avatar
    Join Date
    Mar 2000
    Location
    nevada, usa
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, i got this a couple weeks ago via the javascripts update email newsletter from javascripts.com... it's pretty easy to customize too. useless, true, but certainly cool...you can get some cool effects when you move your mouse from side to side!
    "There's no justice like angry mob justice!" --Seymour Skinner


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •