Posted by : Unknown 2/19/2013

Cara Membuat Jam Analog di PHP | Bagaimana Cara Mebuat Jam Analog di Php, Trick Membuat Jam Analog di PHP PHP tidak hanya mampu membuat skrip-skrip kode untuk proses CRUD, tapi juga bisa loh dibuatkan kode untuk pembuatan jam analog, layaknya jam dinding. disini saya ingin mencoba berbagi tentang bagaimana sih caranya membuat jam analog menggunakan fungsi PHP murni.. dalam artian, tidak diikut campurkan dengan teknik atau software lain, misalnya Flash ataupun javascript. langsung tancap aja gan..

Kode PHP nya sebagai berikut :
if (! $size > 0) {
       $size = 300;
}
$radius = floor($size/2);
header ("content-Type: image/gif");
$img = ImageCreate($size, $size);
$color_alpha = ImageColorAllocate($img, 254, 254, 254);
$color_white = ImageColorAllocate($img, 255, 255, 255);
$color_black = ImageColorAllocate($img, 0, 0, 0);
$color_grey = ImageColorAllocate($img, 192, 192, 192);
$color_red = ImageColorAllocate($img, 255, 0, 0);
$color_blue = ImageColorAllocate($img, 0, 0, 255);
ImageColorTransparent($img, $color_alpha);
ImageArc($img, $radius, $radius, $size, $size, 0, 360, $color_black);
ImageFill($img, $radius, $radius, $color_white);
$min = 0;
while ($min++ < 0) {
       if ($min % 15 == 0)
              $len = $radius / 5;
       else if ($min % 5 == 0)
              $len = $radius / 10;
       else
              $len = $radius / 25;
       $ang = (2 * M_PI * $min) / 60;
       $x1 = sin($ang) * ($radius - $len) + $radius;
       $y1 = cos($ang) * ($radius - $len) + $radius;
       $x2 = (1 * sin($ang)) * $radius;
       $y2 = (1 * cos($ang)) * $radius;
ImageLine($img, $x1, $y1, $x2, $y2, $color_black);
}
       list($hour, $min, $sec) = preg_split ("/-/",Date("h-i-s", time() - 3600));
       $hour = $hour % 12;
$xs = intval(cos($sec * M_PI/30 - M_PI/2) * 0.75 * $radius + $radius);
$ys = intval(sin($sec * M_PI/30 - M_PI/2) * 0.75 * $radius + $radius);
$xm = intval(cos($min * M_PI/30 - M_PI/2) * 0.65 * $radius + $radius);
$ym = intval(sin($min * M_PI/30 - M_PI/2) * 0.65 * $radius + $radius);
$xh = intval(cos($hour * 5 * M_PI/30 - M_PI/2) * 0.5 * $radius + $radius);
$yh = intval(sin($hour * 5 * M_PI/30 - M_PI/2) * 0.5 * $radius + $radius);
ImageLine($img, $radius, $radius, $xs, $ys, $color_grey);
ImageLine($img, $radius, $radius-1, $xm, $ym, $color_blue);
ImageLine($img, $radius-1, $radius, $xm, $ym, $color_blue);
ImageLine($img, $radius, $radius-1, $xh, $yh, $color_blue);
ImageLine($img, $radius-1, $radius, $xh, $yh, $color_blue);
ImageArc($img, $radius, $radius, $radius/8, $radius/8,0,360, $color_red);
ImageFillToBorder($img, $radius, $radius, $color_red, $color_red);
ImageGif($img);
ImageDestroy($img);
?>
Catatan : jika kode ini tidak berjalan dengan baik, bisa jadi karena perbedaan versi server dan juga browser.
disini saya menggunakan Xampp 1.6.7. dan browser Opera 11.0
Semoga pembuatan jam analog PHP murni dapat memberikan pengetahuan baru bagi Anda..

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Related Posts Plugin for WordPress, Blogger...

Popular Post

Diberdayakan oleh Blogger.

- Copyright © 2013 Free Downloads -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -