-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlineTo.html
More file actions
73 lines (56 loc) · 2.15 KB
/
lineTo.html
File metadata and controls
73 lines (56 loc) · 2.15 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
<!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: lineTo
Adds a new point to a subpath and connects that point to the last point in the subpath by using a straight line.
# Standard Definition.
http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#dom-context-2d-lineto
# Function signature
void lineTo(unrestricted double x, unrestricted double y);
*/
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');
// Let's translate the drawing to the center of the canvas
ctx.translate( canvas.width/2, canvas.height/2);
// Set the stroke pattern to red
ctx.strokeStyle = "#FF0000";
// Set the fill pattern to grey
ctx.fillStyle = "grey";
// Set the triangle side size
var side = 200;
// Calculate the triangle height
var height = side * Math.cos( Math.PI / 4 );
// Reset the path
ctx.beginPath();
// Let's move to our starting point
ctx.moveTo( 0, -height / 2);
// Let's draw our triangle lines
ctx.lineTo( -side / 2, height / 2);
ctx.lineTo(side / 2, height / 2);
ctx.lineTo(0, -height / 2);
ctx.stroke();
ctx.fill();
// Close the path
ctx.closePath();
}
</script>
</head>
<body onload="draw();">
<p>
<a href="index.html">Back to index</a>
</p>
<canvas id="canvas" width="300" height="300">
This browser or document mode doesn't support canvas
</canvas>
</body>
</html>