php gd库时钟

<?php

/**
 * 
 * php gd函数的使用	
 * 
 * */
//获取系统时间
date_default_timezone_set('PRC');
$h = date('h');
$i = date('i');
$s = date('s');

// 1. 创建画布
$im = imagecreatetruecolor(300,300);

// 2.创建颜色
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);
$white = imagecolorallocate($im,255,255,255);
$iColor = imagecolorallocate($im,0,188,212);
$hColor = imagecolorallocate($im,63,81,181);

// 3.填充颜色
imagefill($im, 0, 0, $white);


// 4. 画圆形
imageellipse($im, 150, 150, 290, 290, $black);
imagefilledellipse($im, 150, 150, 8, 8, $black);

// 表盘数字
imageellipse($im, 150, 150, 250, 250, $white);
$du = 360/12;
for($j=1;$j<=12;$j++){
    $r = 120;
    $ox = $r*sin(pi()/180*$du*$j);
    $oy = $r*cos(pi()/180*$du*$j);
    $x = 145+$ox;
    $y = 144-$oy;
    imagestring($im, 7, $x, $y, $j, $red);
}


// 秒针
$r = 120;
$ox = $r*sin(pi()/30*$s);
$oy = $r*cos(pi()/30*$s);
$x = 150+$ox;
$y = 150-$oy;
// 画秒针
imageline($im, 150, 150, $x, $y, $red);

// 分针
$ir = 100;
$iox = $ir*sin(pi()/1800*($i*60+$s));
$ioy = $ir*cos(pi()/1800*($i*60+$s));
$ix = 150+$iox;
$iy = 150-$ioy;
// 画分针
imageline($im, 150, 150, $ix, $iy, $iColor);


// 时针
$hr = 80;
$hox = $hr*sin(pi()/(1800*12)*($h*3600+$i*60+$s));
$hoy = $hr*cos(pi()/(1800*12)*($h*3600+$i*60+$s));

$hx = 150+$hox;
$hy = 150-$hoy;
// 画时针
imageline($im, 150, 150, $hx, $hy, $hColor);


// 输出、保存
header('Content-type: images/png');
imagepng($im);

// 销毁
imagedestroy($im);



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_最初の心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值