summaryrefslogtreecommitdiff
path: root/js/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/util.js')
-rw-r--r--js/util.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/js/util.js b/js/util.js
index 7bb1c78..cecb210 100644
--- a/js/util.js
+++ b/js/util.js
@@ -43,7 +43,12 @@ function choice(a){ return a[randint(a.length)] }
function deg(n){ return n*180/PI }
function rad(n){ return n*PI/180 }
function xor(a,b){ a=!!a; b=!!b; return (a||b) && !(a&&b) }
-function pixel(x,y){ return 4*(mod(y,h)*w+mod(x,w)) }
+function mod(n,m){ return n-(m * floor(n/m)) }
+function dist(x0,y0,x1,y1){ return sqrt(pow(x1-x0,2)+pow(y1-y0,2)) }
+function angle(x0,y0,x1,y1){ return atan2(y1-y0,x1-x0) }
+function avg(m,n,a){ return (m*(a-1)+n)/a }
+
+function pixel(x,y){ return 4*(mod(y,actual_h)*actual_w+mod(x,actual_w)) }
function rgbpixel(d,x,y){
var p = pixel(~~x,~~y)
r = d[p]
@@ -51,10 +56,7 @@ function rgbpixel(d,x,y){
b = d[p+2]
a = d[p+3]
}
-function mod(n,m){ return n-(m * floor(n/m)) }
-function dist(x0,y0,x1,y1){ return sqrt(pow(x1-x0,2)+pow(y1-y0,2)) }
-function angle(x0,y0,x1,y1){ return atan2(y1-y0,x1-x0) }
-function avg(m,n,a){ return (m*(a-1)+n)/a }
+function fit(d,x,y){ rgbpixel(d,x*actual_w/w,y*actual_h/h) }
function step(a, b){
return (b >= a) + 0