-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_9_strok_fill.html
72 lines (60 loc) · 1.36 KB
/
2_9_strok_fill.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>2-9 Stroking and filling text, rectangles, and arcs</title>
</head>
<body>
<canvas id="canvas" width="950" height="630"></canvas>
</body>
<script type="text/javascript">
var ctx = document.getElementById('canvas').getContext('2d');
// Drawing attributes
ctx.font = '48px helvetica';
ctx.strokeStyle = 'rgba(250, 200, 0, 1)';
ctx.fillStyle = 'green';
ctx.lineWidth = 2; // for text
// Text
ctx.strokeText('Stroke', 60, 100);
ctx.fillText('Fill', 440, 110);
ctx.strokeText('Stroke & Fill', 650, 110);
ctx.fillText('Stroke & Fill', 650, 110);
// Rectangles
ctx.lineWidth = 5; // for shapes
ctx.beginPath();
ctx.rect(80, 150, 150, 100);
ctx.stroke();
ctx.beginPath();
ctx.rect(400, 150, 150, 100);
ctx.fill();
ctx.beginPath();
ctx.rect(750, 150, 150, 100);
ctx.stroke();
ctx.fill();
// Open arcs
ctx.beginPath();
ctx.arc(150, 370, 60, 0, Math.PI*3/2);
ctx.stroke();
ctx.beginPath();
ctx.arc(475, 370, 60, 0, Math.PI*3/2);
ctx.fill();
ctx.beginPath();
ctx.arc(820, 370, 60, 0, Math.PI*3/2);
ctx.stroke();
ctx.fill();
// Closed arcs
ctx.beginPath();
ctx.arc(150, 550, 60, 0, Math.PI*3/2);
ctx.closePath();
ctx.stroke();
ctx.beginPath();
ctx.arc(475, 550, 60, 0, Math.PI*3/2);
ctx.closePath();
ctx.fill();
ctx.beginPath();
ctx.arc(820, 550, 60, 0, Math.PI*3/2);
ctx.closePath();
ctx.stroke();
ctx.fill();
</script>
</html>