note 94435 deleted from function.imageline by googleguy

From: Date: Tue, 22 Oct 2013 11:18:11 +0000
Subject: note 94435 deleted from function.imageline by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197094@lists.php.net to get a copy of this message
Note Submitter: Robert Lozyniak ---- This code shows the current time as on a 24-hour analog clock. (I used Universal Time so as not to muck about with the time libraries.) <?php $t = time(); $cradius = 90; $cmargin = 2; $ccenter = $cradius + $cmargin; $im = imagecreate($ccenter * 2 + 1, $ccenter * 2 + 1); $bgcolor = imagecolorallocate($im,255,255,255); // white background $figscolor = imagecolorallocate($im,0,0,255); // blue figures on face $handcolor = imagecolorallocate($im,0,0,0); // black hands $seccolor = imagecolorallocate($im,255,0,0); // red second hand function myround($x) { if (x>0) return (int)($x+0.5); return (int)($x-0.5); } function mysin($x,$r) { return myround($r*sin(fmod((float)$x,1.0)*2*M_PI)); } function mycos($x,$r) { return myround($r*cos(fmod((float)$x,1.0)*2*M_PI)); } // draw text on face imagestring ($im, 4, $ccenter-11, myround($ccenter-($cradius*0.5)), "UTC", $figscolor); // draw numbers on face for ($i=0; $i<24; $i++) { $x = $ccenter + mysin($i/24,$cradius*0.9); $y = $ccenter - mycos($i/24,$cradius*0.9); imagestring ($im, 4, $x-7, $y-7, substr('0'.$i,-2), $figscolor); } // draw hands imagesetthickness($im, 3); $x = $ccenter + mysin($t/86400,$cradius*0.7); $y = $ccenter - mycos($t/86400,$cradius*0.7); imageline($im, $ccenter, $ccenter, $x, $y, $handcolor); $x = $ccenter + mysin($t/3600,$cradius*0.95); $y = $ccenter - mycos($t/3600,$cradius*0.95); imageline($im, $ccenter, $ccenter, $x, $y, $handcolor); imagesetthickness($im, 1); $x = $ccenter + mysin($t/60,$cradius*0.95); $y = $ccenter - mycos($t/60,$cradius*0.95); imageline($im, $ccenter, $ccenter, $x, $y, $seccolor); header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?>

« previous php.notes (#197094) next »