-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2DTextExample01.htm
executable file
·51 lines (41 loc) · 1.72 KB
/
2DTextExample01.htm
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
<!DOCTYPE html>
<html>
<head>
<title>Canvas Text Example</title>
</head>
<body>
<canvas id="drawing" width="200" height="200">Your browser doesn't support the canvas tag.</canvas>
<script type="text/javascript">
window.onload = function(){
var drawing = document.getElementById("drawing");
//make sure <canvas> is completely supported
if (drawing.getContext){
var context = drawing.getContext("2d");
//start the path
context.beginPath();
//draw outer circle
context.arc(100, 100, 99, 0, 2 * Math.PI, false);
//draw inner circle
context.moveTo(194, 100);
context.arc(100, 100, 94, 0, 2 * Math.PI, false);
//draw hour hand
context.moveTo(100,100);
context.lineTo(100, 15);
//draw minute hand
context.moveTo(100, 100);
context.lineTo(35, 100);
context.stroke();
//add some text - not supported by all browsers
if (context.strokeText){
context.font = "bold 14px Arial";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("12", 100, 20);
} else {
alert("Your browser doesn't support the canvas text API.");
}
}
};
</script>
</body>
</html>