-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrokeText.html
More file actions
60 lines (49 loc) · 2 KB
/
strokeText.html
File metadata and controls
60 lines (49 loc) · 2 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
<!DOCTYPE html>
<html>
<head>
<title>Canvas 2D Context API Primer</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=1024" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<!--SCRIPTS-->
<script type="text/javascript">
/*
# Context 2d API: strokeText
Renders the specified text at the specified position by using the current font, lineWidth, and strokeStyle property.
# Standard Definition.
http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#dom-context-2d-stroketext
# Function signature
void strokeText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth);
*/
function draw(){
// Get a reference to the canvas
var canvas = document.getElementById('canvas');
// Get a reference to the drawing context
var ctx = canvas.getContext('2d');
gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
// Add the colors with fixed stops at 1/4 of the width.
gradient.addColorStop("0", "magenta");
gradient.addColorStop(".25", "blue");
gradient.addColorStop(".50", "green");
gradient.addColorStop(".75", "yellow");
gradient.addColorStop("1.0", "red");
// Set the fill pattern
ctx.strokeStyle = gradient;
// Set the font
ctx.font = "italic 200 36px/2 Unknown Font, sans-serif"
var i;
for (i = 0; i < 450; i += 50) {
ctx.strokeText("Canvas 2D", i, i + 50);
}
}
</script>
</head>
<body onload="draw();">
<p>
<a href="index.html">Back to index</a>
</p>
<canvas id="canvas" width="600" height="500">
This browser or document mode doesn't support canvas
</canvas>
</body>
</html>