galexcd 0 Report post Posted January 9, 2008 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: <?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! Share this post Link to post Share on other sites
kobra500 1 Report post Posted January 9, 2008 Good enough... I'm sure they're are better ones but that one works good. Well doen Share this post Link to post Share on other sites
gogoily 0 Report post Posted January 10, 2008 This code is excellent !!But I'd like JavaScript clock more, it's real-time and it doesn't use server resource. Share this post Link to post Share on other sites
galexcd 0 Report post Posted January 10, 2008 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 Share this post Link to post Share on other sites
Liam_CF 0 Report post Posted January 10, 2008 Woah, nice coding. Well done. Share this post Link to post Share on other sites