-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (48 loc) · 1.39 KB
/
index.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
/*
* Entry point for the watch app
*/
import document from 'document';
import { MeterWidget } from './meter_widget';
console.log("App Started");
//this one uses goalValue and .setValue instead of the others that use angle.
let floors = new MeterWidget(document.getElementById('meter7'), {goalValue: 15});
floors.setValue(10);
//bunch of meters that use angle
let meters = [
new MeterWidget(document.getElementById('meter1')),
new MeterWidget(document.getElementById('meter2')),
new MeterWidget(document.getElementById('meter3')),
new MeterWidget(document.getElementById('meter4')),
new MeterWidget(document.getElementById('meter5'), {onChange: colorHandler}),
new MeterWidget(document.getElementById('meter6'))
];
//set them all to different start angles
var angle=0;
var step = 360/meters.length;
meters.forEach((meter, index) => {
meter.setAngle(angle);
angle += step;
});
//handler to change color depending on angle
function colorHandler(sender, angle) {
//change some colors.
if (angle < 90) {
sender.setColor('fb-red');
}
else if (angle < 180) {
sender.setColor('fb-blue');
}
else if (angle < 270) {
sender.setColor('fb-orange');
}
else {
sender.setColor('fb-green');
}
}
//make most of them move on regular interval.
setInterval(() => {
meters.forEach( (meter, index) => {
let angle = meter.getAngle();
meter.setAngle(angle + 10);
});
},1000);