-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdrawLineJoin.html
More file actions
92 lines (80 loc) · 2.7 KB
/
drawLineJoin.html
File metadata and controls
92 lines (80 loc) · 2.7 KB
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
<!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>Canvas学习-画线</title>
<style>
html,
body {
height: 100%;
margin: 0;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="canvas">
<p>你的浏览器不支持Canvas</p>
</canvas>
<script>
function canvasApp() {
var canvas = document.getElementById("canvas");
canvas.height = window.innerHeight
canvas.width = window.innerWidth
var ctx = canvas.getContext('2d');
var w = canvas.width;
var h = canvas.height;
ctx.clearRect(0, 0, w, h);
function drawScreen() {
ctx.font = "24px Arial"
ctx.strokeStyle = "#f9f"
ctx.lineWidth = 30
ctx.beginPath()
ctx.lineJoin = "miter"
ctx.moveTo(30, 50)
ctx.lineTo(120, 50)
ctx.lineTo(120, 280)
ctx.fillText('miter 斜切', 30, 20)
ctx.lineCap = 'square';
ctx.stroke()
ctx.beginPath()
ctx.lineJoin = 'round'
ctx.moveTo(180, 50)
ctx.lineTo(280, 50)
ctx.lineTo(280, 280)
ctx.lineTo(180, 280)
ctx.fillText('round 圆角', 180, 20)
ctx.stroke()
ctx.beginPath()
ctx.lineJoin = 'bevel'
ctx.moveTo(350, 50)
ctx.lineTo(450, 50)
ctx.lineTo(450, 280)
ctx.lineTo(350, 280)
ctx.fillText('bevel 斜角', 350, 20)
ctx.stroke()
ctx.strokeStyle = "red"
ctx.lineWidth = 5
ctx.beginPath()
ctx.lineJoin = 'miter'
for (var i = 0; i < 5; i++) {
ctx.lineTo(Math.cos((18 + 72 * i) / 180 * Math.PI) * 100 + 200, -Math.sin((18 + 72 * i) / 180 * Math.PI) * 100 + 120)
ctx.lineTo(Math.cos((54 + 72 * i) / 180 * Math.PI) * 50 + 200, -Math.sin((54 + 72 * i) / 180 * Math.PI) * 50 + 120)
}
ctx.closePath()
ctx.stroke()
}
drawScreen()
}
function eventWindowLoaded() {
canvasApp()
}
window.addEventListener('load', eventWindowLoaded, false)
window.addEventListener('resize', eventWindowLoaded, false)
</script>
</body>
</html>