aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Bornand <nicolas74@gmail.com>2014-05-10 20:03:24 +0200
committerNicolas Bornand <nicolas74@gmail.com>2014-05-10 20:03:24 +0200
commitaa232c0366ff5d46769a4425c72690fdceb77fdf (patch)
tree8b8bdb5a4af901b89b63b24f8963d38e484e6138
parentdf80261549771840a61d85c941e124289c259f41 (diff)
downloadplayGraph-aa232c0366ff5d46769a4425c72690fdceb77fdf.tar.gz
playGraph-aa232c0366ff5d46769a4425c72690fdceb77fdf.tar.bz2
playGraph-aa232c0366ff5d46769a4425c72690fdceb77fdf.zip
modify the way points are randomly chosen
-rw-r--r--app/js/services.js22
1 files changed, 7 insertions, 15 deletions
diff --git a/app/js/services.js b/app/js/services.js
index 6a66e25..a7f4eda 100644
--- a/app/js/services.js
+++ b/app/js/services.js
@@ -30,24 +30,16 @@ app.service('pathService', function() {
});
//select the songs
var selection = [];
+ var tuning = .5;
+ songListCopy.sort(function(song){
+ return (tuning + tuning*Math.random())*song.minDist;}
+ );
while(duration > 0 && songListCopy.length > 0){
- //randomly select one song
- var index = Math.floor(Math.random()*songListCopy.length);
- var song = songListCopy[index];
- var tuneParameter = 1.00;
- var ratio = song.minDist/(maxDistOverall*tuneParameter);
- console.log(ratio);
- //favor the ones closer to the path
- var weight = ratio * ratio * ratio;
- console.log("weight: ", weight);
- if(Math.random() > weight){
- songListCopy.splice(index, 1);
- selection.push(song);
- duration -= 10;
- }
+ var removed = songListCopy.splice(0, 1);
+ selection.push(removed[0]);
+ duration -= 10;
}
selection.sort(function(item){ return item.closestIndex;});
- console.log(selection);
return selection;
}
};