Jul 26, 2008

Analog Clock

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

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.
Confirm Code:

Recent Queries:-
  1. analog clock.swf - 7.36 hr back. (2)
  2. analog clock javascript - 9.83 hr back. (1)
  3. javascript analogue web clock - 11.80 hr back. (1)
  4. free codes analog clock - 25.46 hr back. (1)
  5. php clock analogue - 32.53 hr back. (1)
  6. analog clock javascript free - 36.15 hr back. (1)
  7. yugop countdown clock flash - 49.35 hr back. (1)
  8. analog clock free code for html website - 77.01 hr back. (1)
  9. free analog clock code - 77.56 hr back. (1)
  10. how to make a analog clock in php - 78.44 hr back. (1)
  11. analog clock code - 98.81 hr back. (2)
  12. php analog clock - 13.79 hr back. (3)
  13. clock javascript analog - 123.27 hr back. (1)
Similar Topics

Keywords : analog


    Looking for analog, clock

Searching Video's for analog, clock
advertisement



Analog Clock



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
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