温馨提示×

PHP 绘制时钟 高洛峰 细说PHP

发布时间:2020-05-27 06:36:42 阅读:428 作者:津沙港湾 栏目:web开发

显示页面代码

 <!DOCTYPE html >
<html>
<head>
<title>time</title>
</head>
<body>
<img id="time" src="index.php"/>
<script>
setInterval(function(){
        document.getElementById('time').src="index.php?"+Math.random();
                                   },1000);
</script>
</body>
</html>

画图页面代码

/*
 * 绘制时钟
 */

//获取系统时间
date_default_timezone_set('PRC');
$h = date('H');
$i = date('i');
$s = date('s');
//1.创建资源 画布的大小
 $img = p_w_picpathcreatetruecolor(200250);
 $white = p_w_picpathcolorallocate($img, 0xFF,  0xFF,  0xFF);
 $red = p_w_picpathcolorallocate($img, 25500);
 $blue = p_w_picpathcolorallocate($img,000xFF);
 $pink = p_w_picpathcolorallocate($img, 0xFF00xFF);
 p_w_picpathfill($img,0,0,$white);
 //画椭圆
 p_w_picpathellipse($img, 100100190190, $blue);
 p_w_picpathfilledellipse($img, 10010044, $blue);
 
 p_w_picpathstring($img, 4958'12', $pink);
 p_w_picpathstring($img, 417595'03', $pink);
 p_w_picpathstring($img, 495175'06', $pink);
 p_w_picpathstring($img, 41195'09', $pink);
 
 //秒针
 $len = 80;
 $a = $len*sin(pi()/30*$s);//注意是秒针与竖线形成的夹角 每秒走过6度  sin()里面是按弧度作为参数 要将度换算成弧度
 $b = $len*cos(pi()/30*$s);
 $x = 100 + $a;//秒针线末端x轴的坐标
 $y = 100 - $b;//秒针线末端y轴的坐标
 
 //分钟
 $len1 =1;
 $a1 = $len*sin(pi()/1800*$s);
 $b1 = $len*cos(pi()/1800*$s);
 $x1 = 100 + $a1;//秒针线末端x轴的坐标
 $y1 = 100 - $b1;//秒针线末端y轴的坐标
 
 //秒针
 p_w_picpathline($img, 100100, $x, $y, $red);
 //指针
 p_w_picpathline($img, 100100, $x1, $y1,$blue);
 
 
 //数字的时间
p_w_picpathstring($img, 520230"now:{$h}:{$i}:{$s}",$red);
 //4.保存 或输出给浏览器 写第二个参数就是保存
 header('Content-type:p_w_picpath/jpeg');
 p_w_picpathpng($img);
 
 //5.释放资源
 p_w_picpathdestroy($img);

结果为

PHP 绘制时钟 高洛峰 细说PHP

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

温馨提示×

网络异常,请检查网络