-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
67 lines (57 loc) · 1.91 KB
/
sketch.js
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
let initialPosition = null;
let currentPosition = null;
let pos;
let positionIniatilized = false;
let x = 0;
let y = 0;
// const watchOptions = {
// enableHighAccuracy: true,
// timeout: 1000,
// maximumAge: 0
// };
// function setup() {
// pos = createVector();
// watchPosition(positionChanged, watchOptions);
// console.log(initialPosition)
// createCanvas(innerWidth, innerHeight);
// background(51);
// }
// function draw() {
// // background(51);
// translate(width / 2, height / 2);
// // console.log(initialPosition);
// // for (const pos of position) {
// ellipse(pos.x, pos.y, 30);
// // }
// if (frameCount % 60 == 0) console.log(pos);
// }
// function positionChanged(position) {
// document.getElementById('X').innerHTML = 'X: ' + position.latitude;
// document.getElementById('Y').innerHTML = 'Y: ' + position.longitude;
// currentPosition = position;
// // here we get the starting position
// if (!positionIniatilized && position != undefined) {
// initialPosition = position;
// positionIniatilized = true;
// }
// pos = coordToXY(currentPosition, initialPosition);
// console.log(pos);
// }
// function coordToXY(current, initial) {
// let curr = createVector(current.latitude, current.longitude);
// let init = createVector(initial.latitude, initial.longitude);
// let result = p5.Vector.sub(init, curr);
// return result.mult(100000);
// }
// function windowResized() {
// resizeCanvas(innerWidth, innerHeight);
// }
function handleMotionEvent(event) {
x = event.accelerationIncludingGravity.x;
y = event.accelerationIncludingGravity.y;
document.getElementById('X').innerHTML = 'X: ' + x;
document.getElementById('Y').innerHTML = 'Y: ' + y;
// var z = event.accelerationIncludingGravity.z;
// Do something awesome.
}
window.addEventListener("devicemotion", handleMotionEvent, true);