From 1cf341496d20276fac099450942112f2bec269ce Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 17 Dec 2013 12:05:46 -0500 Subject: avg, show fps --- instructions.html | 1 + js/util.js | 1 + shader-gif.html | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/instructions.html b/instructions.html index 612cf2e..7a36129 100644 --- a/instructions.html +++ b/instructions.html @@ -32,6 +32,7 @@ lerp(n,a,b) mix(n,a,b) step(n,a,b) smoothstep(n,a,b) +avg(m,n,a) cosp, sinp (mapped to [0,1]) pixel(x,y) == 4*(y*w+h) dist(x,y,a,b) diff --git a/js/util.js b/js/util.js index fb15fb5..4f707cf 100644 --- a/js/util.js +++ b/js/util.js @@ -51,6 +51,7 @@ function rgbpixel(d,x,y){ 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 step (n,a,b) { return clamp((n - a) / (b - a), 0.0, 1.0); diff --git a/shader-gif.html b/shader-gif.html index 59d2add..b05894c 100644 --- a/shader-gif.html +++ b/shader-gif.html @@ -60,14 +60,14 @@ div { display: inline-block; padding: 10px;}
+ + +
- - -
@@ -166,18 +166,24 @@ function step_forward(){ } var timeout, raf_id, start_t = 0, old_t = 0, pause_t = 0 var paused = false, dragging = false, rendering = false, scrolling = false; +var fps = 30; function animate(t){ raf_id = requestAnimationFrame(animate); + + var step_t = t - old_t + old_t = t + if (paused || dragging || rendering || scrolling) { - pause_t += t - old_t - old_t = t + pause_t += step_t scrolling = false return } - else { - old_t = t - } + + var timing = +(new Date()) draw(t) + timing -= +(new Date()) + fps = avg(fps, -1000/timing, 4) + status(~~(fps) + " fps") } function draw(t) { t -= start_t -- cgit v1.2.3-70-g09d2