Analog Clock

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Analog Clock

galexcd
ok so i was bored and was inspired by the php clock topic to make this dynamic image of an analog clock:




so anyway here's the source code:
CODE
<?php
/*
All images and lines of code were written/drawn from scratch by alex...
*/
header("Content-type: image/jpeg");
function newclockhand($time,$color,$length,$thickness){
global $clock;
imagefilledpolygon($clock,array(96,89,99-$thickness+cos(deg2rad($time+90))*2,92+$thickness+sin(deg2rad($time+90))*2,$length*cos(deg2rad($time))+165-$length,$length*sin(deg2rad($time))+165-$length),3,$color);
}
$clock=imagecreatetruecolor(200,200);
$back=imagecreatefromjpeg("back.jpg");
$dot=imagecreatefromjpeg("dot.jpg");
imagecopy($clock,$back,0,0,0,0,200,200);
newclockhand(intval(date("i"))/60*360-90,imagecolorallocate($clock,0,0,0),70,3);
newclockhand(intval(date("g"))/12*360-80+30*intval(date("i"))/60,imagecolorallocate($clock,10,10,10),55,5);
newclockhand(intval(date("s"))/60*360-90,imagecolorallocate($clock,255,0,0),70,1);
imagecopy($clock,$dot,97,91,0,0,6,6);
imagejpeg($clock);
imagedestroy($clock);
?>

and attached are all the images needed.

but if you refresh a bit you can tell there are a few bugs... especially with the thickness of the hands changing. I'm not that great at trig functions, I just know the basic unit circle which I used to make this, but i had to play around with some of the numbers to get it right, but I never got the thickness to work quite right. If any of you math whizzes out there want to improve my code go for it. Also changing the length of the hands affects the time sometimes so make sure you compensate for it by adding degrees within the deg2rad() function.

But other than those 2 the clock works pretty good. Have fun!

 

 

 


Reply

kobra500
Good enough... I'm sure they're are better ones but that one works good. Well doen

Reply

gogoily
This code is excellent !!
But I'd like JavaScript clock more, it's real-time and it doesn't use server resource.

Reply

galexcd
Yes it isn't very useful but like I said I only did it because I was bored and wanted to do something random in php

Reply

Liam_CF
Woah, nice coding. Well done.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. swf clock s 40 - 0.46 hr back. (1)
  2. flash analog clock swf - 2.25 hr back. (3)
  3. java analog speed clock - 3.63 hr back. (1)
  4. javascript clock php tutorial - 7.71 hr back. (1)
  5. javascript analog clock source - 8.18 hr back. (1)
  6. "analog clock " " java" " source code " " " - 10.51 hr back. (1)
  7. php analogue clock - 14.50 hr back. (2)
  8. free javascript analog clock - 19.42 hr back. (1)
  9. free analog clock code - 20.55 hr back. (1)
  10. binary clock.swf - 30.53 hr back. (1)
  11. program for analog clock in java - 30.87 hr back. (1)
  12. code for digital spin clock in java - 51.07 hr back. (1)
  13. alarm clock.swf - 52.33 hr back. (1)
  14. index of swf analog clock - 52.77 hr back. (1)
Similar Topics

Keywords : analog, clock

  1. Background Image Swap Script
    Change a Background Image based on clock time (15)
  2. Alarm - Free Digital Clock
    a great digital alarm clock! (0)
    *** Some one tell me how to delete posts*** seems i posted in the wrong section, sorry for this....
  3. Elprime Clock Pro - Review
    a very nice visual enhancement (1)
    Elprime Clock Pro - Review This software adds an analogue clock face to your desktop.
    You can opt to have the clock on top of all your programs or only have it show when it all programs
    are minimised (show on desktop). An incredibly useful feature is that when you put your mouse over
    the clock, it gradually invisibilises meaning that you can read text/click on buttons that the clock
    would have been hiding. The really nice thing about this visual enhancement is that you can select
    from a variety of skins: 21 come pre-installed and about 40 skins are download....
  4. Including An Imgs Clock For Your Web
    PHP Tutorial (1)
    When you load a page, is nice to see what day it is, and the time of the moment of loading the page,
    but isn't nicer to see the time with custom imgs?, i.e. you could put a binary clock at the top
    of your web, ect. So, there's another php microtutorial that i hope it's going2help
    someone. First of All, you have to set in your mind clearly what kind of clock want to put in your
    web (always with numbers, digital), and then, you have to do in Photoshop or your chosen image
    editor, the images for the numbers. In example, if you want a classic digital clock tha....
  5. Clock Hanging In The Air
    Levitating Clocks (18)
    It seems to be magic when you see this clock hanging in the air with no support. But its the
    magnetic force which plays a major role. Just plug the base (which has to be bought alongwith the
    clock) and adjust the clock in between until there is a beep indicating the right place. The
    levitating clock uses the magnetic force to float an LCD clock inside a funny looking base. It also
    features an auto-rotate mechanism to spin objects clockwise, or counter-clockwise (as well as the
    clock you can buy an optional floating space shuttle). I think this is probably best us....
  6. Windows Xp Clock
    (3)
    How can I make the clock in the system tray display seconds as well as hours and minutes?....
  7. Cpus With 5-ghz Clock Speeds On Their Way
    (11)
    Well according to Silicon Valley, 5 GHz CPU's are on their way, which are suppose to be feasible
    and hitting our shelves soon.. Transitior counts doubling from 1 billion to 2 billion in 2 years,
    and to 4 billion in 4 years.
    QUOTE Intel and AMD have said CPU clock speeds -- measured in gigahertz -- will
    not increase to the same degree as in years past due to constraints in power consumption and heat.
    However, the companies will take advantage of increasing chip densities to pac....
  8. Ibm Promises 10 Times Faster Wifi
    operates at a clock speed of 60 GHZ at 630 Mbps (3)
    QUOTE The chip is based on the evolving IEEE 802.15.3c specification for wireless
    communication, which utilizes frequencies higher than the Wi-Fi or any other wireless standard. IBM
    said that the chip operates at a clock speed of 60 GHZ , far faster than the standard 2.4 gigahertz
    or 5 gigahertz speeds that WiFi wireless networking chips use today. In the lab, Gaucher said
    IBM's prototype chip could transfer data at 630 Mbps , and could improve in a few years to
    anywhere from 1 gigabit a second to 5 gigabits a second. Full article : http://www.cdrinfo.c....
  9. Flying Alarm Clock
    yes its true (33)
    I heard about this on a tech site a couple of days ago and I havent been able to find out anything
    else about it. Supposedly, it goes off in the morning and if you hit the snooze button it will fly
    around the room chirping until you catch it and turn it off. If anyone has any other information on
    this or if there is anywhere to buy it please let me know because I am really interested in
    purchasing one of these as I am the type of person that will just keep ihitting the snooze button.....
  10. Set Alarm Clock
    set alarm clock in your computer (4)
    Hello Set an alarm that will play any sound from your computer You can even select a
    snooze time after it sounds. Awesome! Visit this sites
    http://javascript.internet.com/clocks/alarm-clock.html ....
  11. Digital Clock
    the finest moment of evolution (5)
    http://www.yugop.com/ver3/stuff/03/fla.html Speaking of The Deathclock post...I present to you
    a real working clock...the rumor has it that it took them 4 years in completing. LMAO I can see why.
    It's ingenious, actually! Very well thought out plan but what a waste of resources and
    bandwidth. But still, I can't get enough /laugh.gif' border='0' style='vertical-align:middle'
    alt='laugh.gif' /> ....
  12. Needs Self-resetting Countdown Clock
    any help? (2)
    HEy, I hope i can post and ask for help here without getting into trouble. Anyways, I searched
    the web for countdown clocks and i just cant fid what i am looking for; What i find is a bunch of
    graphics, or generators that generate for like days and years at a time. What i am looking for is a
    clock that counts down from 24hrs to zero then resets hr:m:sec format. With so many scripts out
    there about countdown clocks i think it would be seemingly easy for those who know Java. Changed
    Topic Title from Html N00b, Needs Some Java Help to Needs Self-Resetting Countdown....
  13. Is The Army Clock Still Ticking?
    (17)
    I looked at how many wizard I have and at the start of the day, I thought I had 700 and some. It
    looks like I have nearly a thousand now. Did I not pay attention this morning? If the clock is still
    ticking the first people back on the Army system are really going to clean up? If the clock is still
    ticking I don’t know a fair way to start except announcing a start time at which point the server
    will probably get loaded down again. Shall, I be plundered or be a plunder after the next restart if
    it ever comes. ....
  14. i nee clock
    (3)
    Hi Friends Please any one send me Java Scripts for clock on homepage. Regard sanook....
  15. The Belgian electronic clock !
    (8)
    Hi http://www.lares.dti.ne.jp/%7Eyugo/storage...3/03/index.html Bye ~ title
    edited ~ Infraid ....
  16. Free Clock to put in your blocks for phpBB or phpNuke
    (1)
    http://www.vietvip.com http://www.elitegod.com Site is still underconstruction those......
  17. 6 Script
    Clock / Password / BookMark / FavIcon / Back and forward but (0)
    1 - Script Back And forward Button CODE <script LANGUAGE="JavaScript">
    <!-- hide this script tag's contents from old browsers function goHist(a) {
    history.go(a); // Go back one. } // <!-- done hiding from old browsers -->
    </script> <form METHOD="post"> <input TYPE="button"
    VALUE="BACK" onClick="goHist(-1)"> <input TYPE="button"
    VALUE="FORWARD" onClick="goHist(1)"> </form><!-- -->
    ....
  18. Php Clock
    source Code (7)
    Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> CODE <? // Binary Clock //
    script copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
    [url=http://www.psychodad.at/clock/]http://www.psychodad.at/clock/[/url] //
    free to use, copy and modify but leave comments untouched;) // just include this file where
    your binary clock should appear // version 1.2   03 September 2003 // below you can ....
  19. Nice Flash Clock
    (1)
    I Find This clock (SWF) Its Really Nice Clock /blink.gif' border='0'
    style='vertical-align:middle' alt='blink.gif' /> For Designers Is good To be Find This samples and
    learn there Technic see this :: http://www.lares.dti.ne.jp/~yugo/storage/m.../29/bclock.html ....
  20. Flash Clock
    Great for your website (4)
    Here: http://script4you.freesuperhost.com/clock41.html If you don't know how to download
    it from the browser and if you don't know how to change it to a different width and height for
    you to add to your website, just reply to this post and i will send in the size details you want.....
  21. Rock Around The Clock
    Rock Around The Clock (0)
    was on April 12, 1954 - 50 years ago last Monday - that Bill Haley and the Comets assembled at New
    York's Pythian Temple and recorded the song that started it all. Haley died in 1981 at age 55,
    long overshadowed by the often bizarre procession of rock supernovas he had set in motion. But the
    Original Comets, of which Mr Lytle was the bass player, are still rocking away on the old numbers -
    the ones that ended the age of the Great American Songbook and brought on de noise and de funk.
    Long live Rock 'n' Roll! Kvarner....

    1. Looking for analog, clock

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for analog, clock

*MORE FROM TRAP17.COM*
advertisement



Analog Clock



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE