summaryrefslogtreecommitdiff
path: root/js/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/util.js')
-rw-r--r--js/util.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/js/util.js b/js/util.js
index 3775ba0..d0d616d 100644
--- a/js/util.js
+++ b/js/util.js
@@ -47,6 +47,13 @@ function rand(n){ return (Math.random()*n) }
function randint(n){ return rand(n)|0 }
function randrange(a,b){ return a + rand(b-a) }
function randsign(){ return random() >= 0.5 ? -1 : 1 }
+
+function xrandom(exp){ return Math.pow(Math.random(), exp) }
+function xrand(exp,n){ return (xrandom(exp)*n) }
+function xrandint(exp,n){ return rand(exp,n)|0 }
+function xrandrange(exp,a,b){ return a + xrand(exp,b-a) }
+function xrandsign(){ return xrandom() >= 0.5 ? -1 : 1 }
+
function choice(a){ return a[randint(a.length)] }
function deg(n){ return n*180/PI }
function rad(n){ return n*PI/180 }
@@ -74,7 +81,6 @@ function step(a, b){
// ^^ bool -> int
}
-
function julestep (a,b,n) {
return clamp(norm(n,a,b), 0.0, 1.0);
}
@@ -160,6 +166,14 @@ d=this.apply(a,arguments))===e?a:d}.bind(d):d;a.init&&a.init.apply(a,arguments)
]!==e&&(d["__"+c]=b[c]);return a(d)},f},typeof module=="object"&&(module.exports
=Model); // c-{{{-<
+function defaults (dest, src) {
+ dest = dest || {}
+ for (var i in src) {
+ dest[i] = typeof dest[i] == 'undefined' ? src[i] : dest[i]
+ }
+ return dest
+}
+
// Naive useragent detection pattern
var is_iphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))
var is_ipad = (navigator.userAgent.match(/iPad/i))