-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrokeAndfill.js
48 lines (35 loc) · 899 Bytes
/
strokeAndfill.js
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
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 900;
canvas.height = 900;
// 文本
ctx.font="50px STHeiTi";
ctx.lineWidth = 2;
ctx.strokeStyle = 'green';
ctx.strokeText('Stroke', 60, 100);
ctx.fillStyle = 'red';
ctx.fillText('Fill', 360, 100);
ctx.fillText('Stroke & Fill', 580, 100);
ctx.strokeText('Stroke & Fill', 580, 100);
// 矩形
ctx.beginPath();
ctx.rect(60, 150, 150, 100);
ctx.stroke();
ctx.beginPath();
ctx.rect(310, 150, 150, 100);
ctx.fill();
ctx.beginPath();
ctx.rect(630, 150, 150, 100);
ctx.stroke();
ctx.fill();
// 画弧线
ctx.beginPath();
ctx.arc(130, 370, 60, 0, Math.PI*3/2);
ctx.stroke();
ctx.beginPath();
ctx.arc(375, 370, 60, 0, Math.PI*3/2);
ctx.fill();
ctx.beginPath();
ctx.arc(700, 370, 60, 0, Math.PI*3/2);
ctx.stroke();
ctx.fill();