-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
117 lines (100 loc) · 3.83 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<h1> DYNAMIC ART TEST </h1>
<h2> 28 </h2>
</head>
<body>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<p><input type="button" value="Embeter Serveur" onClick="embeterServeur()"/></p>
<p><input type="button" value="Simuler accelerometre" onClick="simuAccelerometre()"/></p>
<!-- <p><input type="button" value="Init" onclick="init()" /></p> -->
<div id="tempValue">
Temporal values :
</div>
<canvas id="canvas" width="1000" height="1000">
<p>Désolé, votre navigateur ne supporte pas Canvas. Mettez-vous à jour</p>
</canvas>
<script>
var IPSERVEUR = '192.168.0.23'
var myArray = [];
console.log("test de la console");
if (window.DeviceMotionEvent == undefined) {
//No accelerometer is present. Use buttons.
alert("no accelerometer");
}
else {
alert("accelerometer found");
window.addEventListener("devicemotion", accelerometerUpdate, true);
}
alert("ready ?");
var socket = io.connect('http://'+IPSERVEUR+':8080');
var pseudo = prompt('Quel est votre pseudo ?');
socket.emit('new_user', pseudo);
socket.on('message', function(message) { alert('Le serveur a un message pour vous : ' + message)});
function embeterServeur() {
socket.emit('message', 'Salut serveur, ça va ?');
}
function simuAccelerometre(){
var aX = Math.random()*10;
var aY = Math.random()*10;
var aZ = Math.random()*10;
socket.emit('accelerometre', 'Reception de accelerometre : '+aX+'_'+aY+'_'+aZ);
socket.emit('aX', aX);
socket.emit('aY', aY);
socket.emit('aZ', aZ);
xPosition = Math.atan2(aY, aZ);
yPosition = Math.atan2(aX, aZ);
console.log("acceleration aX : " + aX);
console.log("acceleration aY : " + aY);
console.log("acceleration aZ : " + aZ);
//s = document.getElementById('tempValue').innerHTML;
//s+= x;
var canvas = document.querySelector('#canvas');
var context = canvas.getContext('2d');
//context.fillStyle = "gold";
var r = Math.floor(200*(aX+10)/20);
var g = Math.floor(200*(aY+10)/20);
var b = Math.floor(200*(aZ+10)/20);
var alpha = ((aX+10)/20)
s = "Accelerometer config rgba(" + r + ",\n" + g + ",\n" + b + ",\n" + alpha + ")";
document.getElementById('tempValue').innerHTML = s ;
context.fillStyle="rgba(" + r + "," + g + "," + b + "," + alpha + ")";
context.fillRect(2*r,2*b,2*r,g);
}
// for (i=0;i<10;i++){
// myArray.push(Math.floor(Math.random()*200) +1);
// console.log(myArray[i]);}
function accelerometerUpdate(e) {
var aX = event.accelerationIncludingGravity.x*1;
var aY = event.accelerationIncludingGravity.y*1;
var aZ = event.accelerationIncludingGravity.z*1;
socket.emit('accelerometre', 'Reception de accelerometre : '+aX+'_'+aY+'_'+aZ);
socket.emit('aX', aX);
socket.emit('aY', aY);
socket.emit('aZ', aZ);
// Afficher sur le téléphone
xPosition = Math.atan2(aY, aZ);
yPosition = Math.atan2(aX, aZ);
console.log("acceleration aX : " + aX);
console.log("acceleration aY : " + aY);
console.log("acceleration aZ : " + aZ);
//s = document.getElementById('tempValue').innerHTML;
//s+= x;
var canvas = document.querySelector('#canvas');
var context = canvas.getContext('2d');
//context.fillStyle = "gold";
var r = Math.floor(200*(aX+10)/20);
var g = Math.floor(200*(aY+10)/20);
var b = Math.floor(200*(aZ+10)/20);
var alpha = ((aX+10)/20)
s = "Accelerometer config rgba(" + r + ",\n" + g + ",\n" + b + ",\n" + alpha + ")";
document.getElementById('tempValue').innerHTML = s ;
context.fillStyle="rgba(" + r + "," + g + "," + b + "," + alpha + ")";
context.fillRect(2*r,2*b,2*r,g);
}
</script>
</body>
</html>