64.canvas画一个表(1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            text-align: center;
        }
    </style>
</head>
 
<body>
    <canvas id="canvas"></canvas>
    <script>
        let canvasWidth = 600;
        let canvasHeight = 600;
        let centerX = canvasWidth / 2;
        let centerY = canvasHeight / 2;
        let r = canvasWidth / 2 - 4;
        let canvas = document.getElementById('canvas');
        canvas.width = canvasWidth;
        canvas.height = canvasHeight;
        let ctx = canvas.getContext('2d');
 
        function setCanvasStrokeStyle() {
 
        }
 
        function drawClock() {
            ctx.beginPath();
            ctx.strokeStyle = "orange";
            ctx.lineWidth = 4;
            ctx.arc(centerX, centerY, r, 0, Math.PI * 2, true);
            ctx.stroke()
        }
 
        function drawHours() {
            let rad = 2 * Math.PI / 12
            for (let i = 1; i <= 12; i++) {
                ctx.save();
                ctx.beginPath();
                ctx.translate(centerX, centerY);
                ctx.rotate(rad * i)
                ctx.translate(-centerX, -centerY);
                ctx.strokeStyle = "orange";
                ctx.lineWidth = 4;
                ctx.moveTo(centerX, centerY - r);
                ctx.lineTo(centerX, centerY - r + 24);
                ctx.font = "26px Arial";
                ctx.textAlign = "center";
                ctx.fillStyle = "orange";
                ctx.fillText(i, centerX, centerY - r + 54);
                ctx.stroke();
                ctx.restore()
 
            }
        }
 
        function drawMinutes() {
            let rad = 2 * Math.PI / 60
            for (let i = 1; i <= 60; i++) {
                ctx.save();
                ctx.beginPath();
                ctx.translate(centerX, centerY);
                ctx.rotate(rad * i)
                ctx.translate(-centerX, -centerY);
                ctx.strokeStyle = "orange";
                ctx.lineWidth = 2;
                ctx.moveTo(centerX, centerY - r);
                ctx.lineTo(centerX, centerY - r + 16);
                ctx.stroke();
                ctx.restore()
 
            }
        }
        // 画时针 分针 秒针
        function drawTimeLine() {
            ctx.beginPath();
            ctx.arc(centerX, centerY, 20, 0, Math.PI * 2, true);
            ctx.fillStyle = "orange";
            ctx.fill();
            // 时针
            ctx.save()
            ctx.beginPath();
            ctx.lineWidth = 10;
            ctx.translate(centerX, centerY);
            ctx.rotate(Math.PI / 4)
            ctx.translate(-centerX, -centerY);
            ctx.moveTo(centerX, centerY);
            ctx.lineTo(centerX, centerY - r + 148);
            ctx.stroke();
            ctx.restore()
                // 分针
            ctx.save()
 
            ctx.beginPath();
            ctx.translate(centerX, centerY);
            ctx.rotate(Math.PI / 2)
            ctx.translate(-centerX, -centerY);
            ctx.lineWidth = 6;
            ctx.moveTo(centerX, centerY);
            ctx.lineTo(centerX, centerY - r + 108);
            ctx.stroke();
            ctx.restore()
 
            // 秒针
            ctx.beginPath();
            ctx.lineWidth = 4;
            ctx.moveTo(centerX, centerY);
            ctx.lineTo(centerX, centerY - r + 68);
            ctx.stroke();
 
        }
        drawClock();
        drawHours();
        drawMinutes();
        drawTimeLine();
    </script>
</body>
 
</html>

  

posted @   famCc  阅读(301)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示