forked from lupine-dev/bitlisten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransaction.js
More file actions
50 lines (42 loc) · 1.72 KB
/
Copy pathtransaction.js
File metadata and controls
50 lines (42 loc) · 1.72 KB
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
function Transaction(bitcoins, highlight, currency, currencyName) {
Floatable.call(this);
this.area = bitcoins * 100 + 3000;
this.width = this.height = Math.sqrt(this.area / Math.PI) * 2;
this.addImage(bubbleImage, this.width, this.height);
var bitcoinString = "฿" + bitcoins.toFixed(2);
if (bitcoinString == "฿0.00")
bitcoinString = "<฿0.01";
if (!highlight) {
this.addText(bitcoinString);
} else {
this.addText('<span style="color: yellow;">' + bitcoinString + '</span><br /><span style="color: cyan;">Donation</span><br /><span style="color: lime;">Thanks!</span>');
}
if (currency && currencyName) {
this.addText('<br />' + currency.toFixed(2) + ' ' + currencyName);
}
this.initPosition();
// Sound
var maxBitcoins = 1000;
var minVolume = 0.3;
var maxVolume = 0.7;
var volume = bitcoins / (maxBitcoins / (maxVolume - minVolume)) + minVolume;
if (volume > maxVolume)
volume = maxVolume;
var maxPitch = 100.0;
// We need to use a log that makes it so that maxBitcoins reaches the maximum pitch.
// Well, the opposite of the maximum pitch. Anyway. So we solve:
// maxPitch = log(maxBitcoins + logUsed) / log(logUsed)
// For maxPitch = 100 (for 100%) and maxBitcoins = 1000, that gives us...
var logUsed = 1.0715307808111486871978099;
// So we find the smallest value between log(bitcoins + logUsed) / log(logUsed) and our max pitch...
var pitch = Math.min(maxPitch, Math.log(bitcoins + logUsed) / Math.log(logUsed));
// ...we invert it so that a bigger transaction = a deeper noise...
pitch = maxPitch - pitch;
// ...and we play the sound!
if(globalScalePitch) {
Sound.playPitchAtVolume(volume, pitch);
} else {
Sound.playRandomAtVolume(volume);
}
}
extend(Floatable, Transaction);