-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
58 lines (53 loc) · 1.79 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
56
57
58
<!doctype html>
<html>
<head>
<title>LeapPointer Demo</title>
<script src="leap_sdk.js"></script>
<script src="leap_sdk_plugin.js"></script>
<script src="LeapPointer.js"></script>
<style>
html, body { width: 100%; height: 100%; }
canvas {
touch-action: none; /* Disable panning */
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas width="1680" height="1050"></canvas>
<script>
window.addEventListener("pointermove", paint);
var pointers = [];
var colors = ["red", "blue", "green", "yellow", "black", "orange"];
var context = document.querySelector("canvas").getContext("2d");
function paint(event) {
if(event.pointerType == "touch")
console.log(event.clientX);
if(!pointers[event.pointerId]) {
pointers[event.pointerId] = [{x: event.offsetX, y: event.offsetY},
{x: event.offsetX, y: event.offsetY},
{x: event.offsetX, y: event.offsetY},
{x: event.offsetX, y: event.offsetY}];
}
event.preventDefault();
//Get points for this pointerId
var points = pointers[event.pointerId];
//Create path
context.beginPath();
context.moveTo(points[0].x, points[0].y);
context.bezierCurveTo( points[1].x, points[1].y,
points[2].x, points[2].y,
points[3].x, points[3].y);
//Paint path
context.lineWidth = (event.width + event.height)*3 || event.pressure*10 || 4; //Use width
context.strokeStyle = colors[event.pointerId%colors.length];
context.stroke();
context.closePath();
//Update points
pointers[event.pointerId].shift();
pointers[event.pointerId].push({x: event.offsetX, y: event.offsetY});
}
</script>
</body>
</html>