IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Analog Clock


galexcd
no avatar
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********
Group: [HOSTED]
Posts: 1,215
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251
myCENT:ZERO



Post #1 post 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)
Attached File  back.jpg ( 4.01K ) Number of downloads: 8
Attached File  dot.jpg ( 357bytes ) Number of downloads: 3
 
Go to the top of the page
+Quote Post
kobra500
no avatar
Super Member
*********
Group: [HOSTED]
Posts: 470
Joined: 8-January 08
From: UK - Kent
Member No.: 55,950
myCENT:79.05



Post #2 post Jan 9 2008, 07:19 PM
Good enough... I'm sure they're are better ones but that one works good. Well doen
Go to the top of the page
+Quote Post
gogoily
no avatar
Member [Level 3]
******
Group: Members
Posts: 99
Joined: 30-October 05
Member No.: 13,571



Post #3 post 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.
Go to the top of the page
+Quote Post
galexcd
no avatar
Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********
Group: [HOSTED]
Posts: 1,215
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251
myCENT:ZERO



Post #4 post 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
Go to the top of the page
+Quote Post
Liam_CF
no avatar
Super Member
*********
Group: Members
Posts: 403
Joined: 14-October 07
From: ERROR 404
Member No.: 51,575



Post #5 post Jan 10 2008, 05:55 PM
Woah, nice coding. Well done.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   0 kvarnerexpress 567 16th December 2004 - 10:51 PM
Last post by: kvarnerexpress
No New Posts   4 Lyon 2,116 5th March 2005 - 08:01 PM
Last post by: soulnetwork_tk
No New Posts 1 alexia 1,297 7th March 2005 - 01:21 PM
Last post by: HmmZ
No New Posts   7 alexia 1,362 13th January 2008 - 05:41 PM
Last post by: coldasice
No New Posts   3 -sanook- 729 3rd March 2005 - 06:46 PM
Last post by: -taptoefanaat-
No New Posts   1 -elitegod- 314 21st November 2004 - 04:40 PM
Last post by: -Amras_Ancalimon-
No New Posts   8 -npsfqqa- 440 9th December 2004 - 11:08 PM
Last post by: -npsfqqa-
No new   17 s243a 1,812 27th April 2005 - 01:52 PM
Last post by: NilsC
No New Posts   2 Static_Fury 709 31st July 2005 - 03:28 AM
Last post by: Static_Fury
No New Posts   5 BuffaloHELP 560 10th October 2005 - 06:07 AM
Last post by: tdktank59
No New Posts 1 NeOniX 345 18th June 2006 - 08:02 PM
Last post by: FirefoxRocks
No New Posts 4 vinayak 637 7th October 2005 - 12:12 AM
Last post by: Lozbo
No new   33 fraudulentpeanut 3,001 3rd January 2008 - 02:48 AM
Last post by: FeedBacker
No New Posts   11 rogeruk 765 10th March 2006 - 02:58 AM
Last post by: believer
No New Posts   4 tt3 1,069 28th October 2008 - 05:33 AM
Last post by: joeblogg


 



RSS Open Discussion Time is now: 10th January 2009 - 03:48 AM