|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED]
Posts: 1,215 Joined: 25-September 05 From: Los Angeles, California Member No.: 12,251 myCENT:ZERO |
Post
#1
Jan 9 2008, 06:46 PM
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!
Attached File(s)
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Post
#2
Jan 9 2008, 07:19 PM
Good enough... I'm sure they're are better ones but that one works good. Well doen
|
![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 99 Joined: 30-October 05 Member No.: 13,571 |
Post
#3
Jan 10 2008, 02:02 AM
This code is excellent !! But I'd like JavaScript clock more, it's real-time and it doesn't use server resource. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED]
Posts: 1,215 Joined: 25-September 05 From: Los Angeles, California Member No.: 12,251 myCENT:ZERO |
Post
#4
Jan 10 2008, 03:40 AM
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
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 403 Joined: 14-October 07 From: ERROR 404 Member No.: 51,575 |
|
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
0 | kvarnerexpress | 567 | 16th December 2004 - 10:51 PM Last post by: kvarnerexpress |
|||
![]() |
4 | Lyon | 2,116 | 5th March 2005 - 08:01 PM Last post by: soulnetwork_tk |
|||
![]() |
1 | alexia | 1,297 | 7th March 2005 - 01:21 PM Last post by: HmmZ |
|||
![]() |
7 | alexia | 1,362 | 13th January 2008 - 05:41 PM Last post by: coldasice |
|||
![]() |
3 | -sanook- | 729 | 3rd March 2005 - 06:46 PM Last post by: -taptoefanaat- |
|||
![]() |
1 | -elitegod- | 314 | 21st November 2004 - 04:40 PM Last post by: -Amras_Ancalimon- |
|||
![]() |
8 | -npsfqqa- | 440 | 9th December 2004 - 11:08 PM Last post by: -npsfqqa- |
|||
![]() |
17 | s243a | 1,812 | 27th April 2005 - 01:52 PM Last post by: NilsC |
|||
![]() |
2 | Static_Fury | 709 | 31st July 2005 - 03:28 AM Last post by: Static_Fury |
|||
![]() |
5 | BuffaloHELP | 560 | 10th October 2005 - 06:07 AM Last post by: tdktank59 |
|||
![]() |
1 | NeOniX | 345 | 18th June 2006 - 08:02 PM Last post by: FirefoxRocks |
|||
![]() |
4 | vinayak | 637 | 7th October 2005 - 12:12 AM Last post by: Lozbo |
|||
![]() |
33 | fraudulentpeanut | 3,001 | 3rd January 2008 - 02:48 AM Last post by: FeedBacker |
|||
![]() |
11 | rogeruk | 765 | 10th March 2006 - 02:58 AM Last post by: believer |
|||
![]() |
4 | tt3 | 1,069 | 28th October 2008 - 05:33 AM Last post by: joeblogg |
|||
|
Open Discussion | Time is now: 10th January 2009 - 03:48 AM |