summaryrefslogtreecommitdiff
path: root/app/client/util
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-09-23 18:34:30 +0200
committerJules Laplace <julescarbon@gmail.com>2018-09-23 18:34:30 +0200
commite2c13867baf66a6ae22c975563f8755e782d07a9 (patch)
treefa7c51a6a6628a5b1e1173c6cd1a381ff15cc500 /app/client/util
parentf3885f7d43dffe4e0fcf49e3e8f9f9e248bc6f76 (diff)
adding timeline component
Diffstat (limited to 'app/client/util')
-rw-r--r--app/client/util/format.js11
-rw-r--r--app/client/util/math.js16
2 files changed, 19 insertions, 8 deletions
diff --git a/app/client/util/format.js b/app/client/util/format.js
index ee1f47f..2c94de1 100644
--- a/app/client/util/format.js
+++ b/app/client/util/format.js
@@ -1,3 +1,13 @@
+const FRAME_RATE = 25
+export function frameTimestamp(n = 0) {
+ n /= FRAME_RATE
+ let s = pad((n % 60).toFixed(1))
+ n = Math.floor(n / 60)
+ if (n > 60) {
+ return Math.floor(n / 60) + ':' + pad(n % 60) + ':' + s
+ }
+ return (n % 60) + ':' + s
+}
export function timeInSeconds(n){
return (n / 10).toFixed(1) + ' s.'
}
@@ -144,3 +154,4 @@ export function get_age (t) {
return r(age) + "y"
}
export function courtesy_s (n, s) { return n == 1 ? "" : (s || "s") }
+export function pad(n, r){ return n < 10 ? '0' + n : n }
diff --git a/app/client/util/math.js b/app/client/util/math.js
index c301ffd..064d37c 100644
--- a/app/client/util/math.js
+++ b/app/client/util/math.js
@@ -4,14 +4,14 @@ export const norm = (n,a,b) => (n-a) / (b-a)
export const lerp = (n,a,b) => (b-a)*n+a
export const mix = (n,a,b) => a*(1-n)+b*n
export const randint = (n) => Math.floor(Math.random()*n)
-export function randrange(a,b){ return Math.random() * (b-a) + a }
-export function randsign(){ return Math.random() >= 0.5 ? -1 : 1 }
-export function choice (a){ return a[ Math.floor(Math.random() * a.length) ] }
-export function angle(x0,y0,x1,y1){ return Math.atan2(y1-y0,x1-x0) }
-export function dist(x0,y0,x1,y1){ return Math.sqrt(Math.pow(x1-x0,2)+Math.pow(y1-y0,2)) }
-export function xor(a,b){ a=!!a; b=!!b; return (a||b) && !(a&&b) }
-export function quantize(a,b){ return Math.floor(a/b)*b }
-export function shuffle(a){
+export const randrange = (a,b) => Math.random() * (b-a) + a
+export const randsign = () => Math.random() >= 0.5 ? -1 : 1
+export const choice = (a) => a[ Math.floor(Math.random() * a.length) ]
+export const angle = (x0,y0,x1,y1) => Math.atan2(y1-y0, x1-x0)
+export const dist = (x0,y0,x1,y1) => Math.sqrt(Math.pow(x1-x0, 2) + Math.pow(y1-y0, 2))
+export const xor = (a,b) => { a=!!a; b=!!b; return (a||b) && !(a&&b) }
+export const quantize = (a,b) => Math.floor(a/b)*b
+export const shuffle = (a) => {
for (var i = a.length; i > 0; i--){
var r = randint(i)
var swap = a[i-1]