-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (64 loc) · 1.59 KB
/
main.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
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
'use strict'
$(document).ready(init);
var api = 'http://api.wunderground.com/api/df45a7cd0539b861/'
function init() {
gW();
var track;
var gainNode;
var caveB = 0;
var bass =0;
var violin = 0;
var kick = 0;
var hipitch = 0;
var snap = 0;
var hihat = 0;
var myAudio;
myAudio = new AudioContext();
myAudio.crossOrigin = 'anonymous';
$('.star').mousedown(start)
function start() {
if (caveB === 0) {
gainNode = myAudio.createGain();
var caveStory = new Audio();
caveStory.src = 'cavestory.wav';
caveStory.autoplay = true;
caveStory.loop = true;
document.body.appendChild(caveStory);
caveB = 1
var source = myAudio.createMediaElementSource(caveStory);
gainNode.connect(myAudio.destination);
source.connect(gainNode);
}
document.body.addEventListener('mousemove', calcPos)
document.body.addEventListener('mouseup', stopMove)
}
function calcPos(event){
runVolume(event.y)
}
function runVolume(y) {
var pos = 1 - (y/1000)
var volume = 1 - (y/700)
gainNode.gain.value= volume;
$('.star').css('bottom',pos*850+'px')
}
function stopMove(event) {
document.body.removeEventListener('mousemove',calcPos)
}
function gW() {
var url = api+'astronomy/q/autoip.json'
$.get(url)
.done(function(data){
var x = data.sun_phase.sunrise.hour
if (x.length === 1) {var x ="0"+x}
var y = data.sun_phase.sunrise.minute
$('#rise').text(x+':'+y)
var a = data.sun_phase.sunset.hour
if (a.length === 1) {var a ="0"+a}
var b = data.sun_phase.sunset.minute
$('#set').text(a+':'+b)
})
.fail(function(data){
console.log(data)
});
}
}