Port to JavaScript

CoffeeScript is not worth the extra hassle for such a simple piece of
software
This commit is contained in:
Maximilian Gaß 2012-03-22 20:26:32 +01:00
parent 5ca92c6914
commit b9cc313471
2 changed files with 28 additions and 25 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
/genregen.js

View File

@ -1,4 +1,4 @@
genres = [ var genres = [
'Aggrotech', 'Aggrotech',
'Ambient', 'Ambient',
'Beat', 'Beat',
@ -44,7 +44,7 @@ genres = [
'Triphop', 'Triphop',
'Twostep', 'Twostep',
'Western', 'Western',
] ];
subgenres = [ subgenres = [
'30s', '30s',
@ -156,7 +156,7 @@ subgenres = [
'Wave', 'Wave',
'West Coast', 'West Coast',
'World', 'World',
] ];
cities = [ cities = [
'Berlin', 'Berlin',
@ -170,26 +170,30 @@ cities = [
'Rio', 'Rio',
'Rotterdam', 'Rotterdam',
'San Francisco', 'San Francisco',
] ];
rand_choose = (array) ->
array[Math.floor(Math.random() * array.length)]
chance = (percent) ->
Math.floor(Math.random() * 100) < percent
generate_genre = ->
parts = []
parts.push rand_choose(cities) if chance 20
parts.push rand_choose(subgenres) if chance 70
parts.push rand_choose(subgenres)
parts.push rand_choose(genres)
genre = parts.join(' ')
$('#genre a').text(genre)
$('title').text('Listen to ' + genre)
$(document).ready ->
$('#genre a').click(generate_genre)
generate_genre()
function rand_choose(array) {
return array[Math.floor(Math.random() * array.length)];
}
function chance(percent) {
return Math.floor(Math.random() * 100) < percent;
}
function generate_genre() {
var parts = [];
if (chance(20)) parts.push(rand_choose(cities));
if (chance(70)) parts.push(rand_choose(subgenres));
parts.push(rand_choose(subgenres));
parts.push(rand_choose(genres));
var genre = parts.join(' ');
$('#genre a').text(genre);
return $('title').text('Listen to ' + genre);
}
$(document).ready(function() {
$('#genre a').click(generate_genre);
generate_genre();
});