PDA

View Full Version : Analog Clock Script Needed


Mathew
24th March 2006, 18:16
Hi All
I have been searching for a good clock script and still no joy. So I was wondering if any of you web design people fancy giving a little trick of the trade away. Do you have any good scripts for analog clocks that can be placed on a website? I am ideally looking for a clear face and hands that will also display AM/PM on the face. If possible it would be great to place a destination name as well.

Anything would be gratefully received

desk2web
24th March 2006, 18:22
Have a look at http://analogclock.caiphp.com/ - I have used Flash clocks on some sites, but I can't find the links at the minute - I'll keep looking.

Demo of the php clocks here:

http://www.desk2web.co.uk/examples/plain.php
http://www.desk2web.co.uk/examples/blue.php
http://www.desk2web.co.uk/examples/osx.php

Allan

Mathew
24th March 2006, 19:18
That’s amazing thanks Allan it’s easy when you are in the know. I am not looking for flash clocks so this is perfect. Anything with a moving second hand?

desk2web
24th March 2006, 20:40
If you don't mind a little advertising link try http://www.clocksforweb.com/
they have a good seleciton, or

http://www.desk2web.co.uk/clock.htm
(theres a link to download the swf file, just insert it into your html and away you go!)

Mortime Business Software
25th March 2006, 10:20
It is quite easy to write your own if you know how to calculate the relevant points on the circles for the hands. Then you could give them away with your own little advert on them.

If you draw a circle on the (x,y)-plane with centre the origin, then you will see that all you have to do is draw lines from the centre (the point (0,0)) to a set of points on the circle. If an arbitrary point on the circle is P(x,y), then we need to find x and y. The equations for this are...

x = rcosA
y = rsinA

where r is the radius of the circle, and A is the angle between the radius and the positive direction of the x-axis.

Every minute, the angle between the minute-hand and the positive direction of the x-axis changes by 360 / 60 = 6 degrees, and the hour-hand angle changes by (360 / 12) / 60 = 0.5 degrees.

Of course you will have to adjust your origin to be suitable for the screen's (x,y)-plane which has its origin at the top left corner.

If you want to know how the above parametric equations are derived, read below the dotted line. Ellipses can also be parametrised so you can have an elliptical clock. The equations are...

x = acosA
y = bsinA

where a is half the length of the major axis of the ellipse along the x-axis, and b is half the length of the minor axis of the ellipse along the y-axis. The derivation of these equations is a little more complicated than for the circle.

Dave

----------------------------------------------

To derive the pair of parametric equations for points on a circle...

Draw a circle on the (x,y)-plane with centre the origin O (the point (0,0)).
Mark a point P(x,y) on the circle in the first quadrant.
Draw a line from O to P, so OP is the radius of the circle.
Drop a vertical line from P to meet the x-axis.
We now have a right-angled triangle.
Mark the angle between the radius and the positive direction of the x-axis with label A.
Mark the adjacent side of the triangle x, and the opposite side y, and the hypotenuse r.

Now from your O-level trigonometry, you can see that...

cosA = x / r (adjacent divided by hypotenuse)
x = rcosA

...and...

sinA = y / r (opposite divided by hypotenuse)
y = rsinA

----------------------------------------------

Mathew
28th March 2006, 22:25
Allan we are not there yet I have found out that this script requires GD and my hosting company will not support this programme. So do you know of anything else like this script and does not use GD??

I think this one may have beaton us

Rob Holmes
28th March 2006, 22:28
Allan we are not there yet I have found out that this script requires GD and my hosting company will not support this programme. So do you know of anything else like this script and does not use GD??

I think this one may have beaton us

maybe host the script with a web host that does have GD (I take it you mean GD Library) and then include it in your web pages as an 'include'

Rob

Mathew
29th March 2006, 18:06
Yes GD Libray is what mean sorry. No can do regrding the webhosting so does antone have any ideas????

Rob Holmes
29th March 2006, 18:21
Yes GD Libray is what mean sorry. No can do regrding the webhosting so does antone have any ideas????

GD Library is bundled with php so your host may unknowingly already have it installed.

Else have something custom written for you.

Out of interest why 'no can do' with the webhosting - it would solve this problem and is simple to integrate and would set yopu back about £30 a year!

Rob

Mathew
29th March 2006, 18:24
They say they dont support it

crus
29th March 2006, 18:34
<? phpinfo() ?>

put that in a text file and upload it to your server as test.

It is rare, but not unheard of, for GD not to be part of the PHP build your webhost is using.

the above will output a load of stuff which will confirm if GD libs are present and what version.

I suspect that they will be but in a much constrained form.

D

Rob Holmes
29th March 2006, 18:36
By your answer I'm not sure you understood fully...

I have GD Library enabled on all my servers. If you generate the clock on a webpage hosted on one of my servers your programmer can then simply include the image in realtime on your webpage and it will pull the info across. Your webpage will show the clock.

Failing that I think MattK works with .asp - maybe ask him how he'd do it - or even pay him to do it!!

Best regards,

Rob

Mortime Business Software
29th March 2006, 19:54
I have GD Library enabled on all my servers. If you generate the clock on a webpage hosted on one of my servers your programmer can then simply include the image in realtime on your webpage and it will pull the info across. Your webpage will show the clock.


Are active server pages not similar to PHP files in that an interpreter on the server executes code within web pages and plonks the output between a pair of tags?

If so, then wouldn't it be better to use a Java applet, or something that runs the clock from the client's clock on the client's machine? This would be much more efficient, and the second hand would be no problem since the browser wouldn't need to pull the data from the server every time the clock needed to be updated.

Or am I missing something in your suggestion?

Dave

desk2web
29th March 2006, 20:03
I thought I put some flash clocks up as well? why not just use them?

Rob Holmes
30th March 2006, 05:56
Are active server pages not similar to PHP files in that an interpreter on the server executes code within web pages and plonks the output between a pair of tags?

If so, then wouldn't it be better to use a Java applet, or something that runs the clock from the client's clock on the client's machine? This would be much more efficient, and the second hand would be no problem since the browser wouldn't need to pull the data from the server every time the clock needed to be updated.

Or am I missing something in your suggestion?

Dave

Yup - I think the java suggestions been made before which makes good sense.

There are a few ways of doing this and I guess I don't understand what the real problem is because I don't see a problem!

Rob