13.1.4 画时钟

13.1.4 画时钟

demo.html

<body>
    <img id="time" src="test.php" />


    <script>
        setInterval(function(){
                document.getElementById("time").src="test.php?"+Math.random();
                
            },1000);
    </script>   
</body>

test.php

<?php
    //获取系统时间
    date_default_timezone_set("PRC");

    $h = date("H");
    $i = date("i");
    $s = date("s");

    //1 创建资源(画布的大小)
    $img = imagecreatetruecolor(200, 250);  
    //设置画布的颜色
    $white =  imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
    $red =  imagecolorallocate($img, 255, 0, 0);
    $blue =  imagecolorallocate($img, 0, 0, 0XFF);
    $pink =  imagecolorallocate($img, 0XFF, 0, 0XFF);
    $green =  imagecolorallocate($img, 0, 0xFF, 0);
    
    
    imagefill($img, 0, 0, $white);
    //2. 制作各种颜色
    imageellipse($img, 100, 100, 190, 190, $blue);
    imagefilledellipse($img, 100, 100, 4, 4, $blue);

    imagestring($img, 3, 95, 8,  "12", $blue);
    imagestring($img, 3,180, 95, "03", $blue);
    imagestring($img, 3, 95, 180,  "06", $blue);
    imagestring($img, 3, 11, 95,  "09", $blue);

    //秒针

    $len = 80;


     $a = $len*sin(pi()/30*$s);
     $b = $len*cos(pi()/30*$s);
    $x = 100 + $a;
    $y = 100 - $b;


    imageline($img, 100, 100, $x, $y, $red);

    //数字的时间
    imagestring($img, 5, 20, 230, "NOW: {$h}:{$i}:{$s}", $red);

    //4保存,或输出给浏览, 写第二个参数就是保存
    header("Content-Type:images/gif");
    imagegif($img);

    //5. 释放资源
    imagedestroy($img);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容