/
demo.html
55 lines (50 loc) · 1.41 KB
/
demo.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
<!doctype html>
<html>
<head>
<title>Canvas demo</title>
<meta charset="utf8">
<script src="dist/draw.min.js"></script>
</head>
<body>
<canvas id="board" width="500" height="500"></canvas>
<script>
// Construct the canvas and context
var canvas = document.getElementById('board')
var context = canvas.getContext('2d')
context.strokeStyle = '#222'
context.lineWidth = 5
// drawing a segment
var start = point(10, 10),
end = point(60,340)
draw(context, segment(start, end))
// drawing a polygon
var points = [
point(50, 50),
point(150, 50),
point(350, 150),
point(250, 10),
point(50, 50)
]
context.strokeStyle = 'red'
draw(context, polygon(points))
// drawing a circle
var center = point(250, 250)
context.strokeStyle = 'blue'
context.lineWidth = 10
draw(context, circle(center, 77))
// draw an arc of circle
var a = point(150, 250),
b = point(350, 250),
c = point(250, 150)
context.strokeStyle = 'orange'
var theArc = arc(a, b, c)
console.log(theArc)
draw(context, theArc)
// // draw rectangle
var topLeft = point(10, 10),
bottomRight = point(290, 400)
context.strokeStyle = 'green'
draw(context, rectangle(topLeft, bottomRight))
</script>
</body>
</html>