From 8981d25c07941e240ec2f3cd1bdfbe04d35edff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz=20=28arab=2C=20vx?= =?UTF-8?q?p=29?= Date: Thu, 25 Oct 2018 01:29:02 +0200 Subject: [PATCH] js/{blit,shader}.js: merged into js/gfx.js. index.html: updates script URIs. --- index.html | 3 +-- js/{blit.js => gfx.js} | 59 ++++++++++++++++++++++++++++++++++++++++++ js/shader.js | 58 ----------------------------------------- 3 files changed, 60 insertions(+), 60 deletions(-) rename js/{blit.js => gfx.js} (63%) delete mode 100644 js/shader.js diff --git a/index.html b/index.html index 729a680..50090d5 100644 --- a/index.html +++ b/index.html @@ -138,9 +138,8 @@ - + - diff --git a/js/blit.js b/js/gfx.js similarity index 63% rename from js/blit.js rename to js/gfx.js index 2dce3e5..7efe45d 100644 --- a/js/blit.js +++ b/js/gfx.js @@ -1,3 +1,62 @@ +var shader = (function(){ + var fn_str, fn, lex + var exports = {} + var animating = false + + exports.init = function(){ + lex = new Lex (0, 0) + exports.build(demo_shader.innerHTML) + } + exports.build = function (fn_str){ + try { + new_fn = new Function('lex', 'x', 'y', 'w', 'h', 't', fn_str) + new_fn(lex, 0, 0, 1, 1, 0) + } + catch (e) { + throw 'Shader execution error' + } + exports.fn = fn = new_fn + return fn + } + exports.run = function(canvas){ + var t = +new Date + shader.canvas = shader.canvas || canvas + var w = shader.canvas.w, h = shader.canvas.h + shader.canvas.forEach(function(lex, x, y){ + fn(lex, x, y, w, h, t) + lex.build() + }) + } + exports.toggle = function(state){ + animating = typeof state == "boolean" ? state : ! animating + shader_fps_el.classList.toggle('hidden') + return animating + } + exports.pause = function(){ + animating = false + shader_fps_el.classList.add('hidden') + shader.fps_time = 0 + } + exports.play = function(){ + animating = true + shader_fps_el.classList.remove('hidden') + } + exports.animate = function (t){ + requestAnimationFrame(exports.animate) + if (! animating) { return } + if (shader.fps_time){ + var ms = Date.now() - shader.fps_time + fps = 1000 / ms + shader_fps_el.innerHTML = (fps | 0) + ' fps' + } + shader.fps_time = Date.now() + exports.run(canvas) + } + + return exports + +})() + var blit = (function(){ var blit = {} blit.and = blit.atop = function(A, B, x, y){ diff --git a/js/shader.js b/js/shader.js deleted file mode 100644 index f0ed548..0000000 --- a/js/shader.js +++ /dev/null @@ -1,58 +0,0 @@ -var shader = (function(){ - var fn_str, fn, lex - var exports = {} - var animating = false - - exports.init = function(){ - lex = new Lex (0, 0) - exports.build(demo_shader.innerHTML) - } - exports.build = function (fn_str){ - try { - new_fn = new Function('lex', 'x', 'y', 'w', 'h', 't', fn_str) - new_fn(lex, 0, 0, 1, 1, 0) - } - catch (e) { - throw 'Shader execution error' - } - exports.fn = fn = new_fn - return fn - } - exports.run = function(canvas){ - var t = +new Date - shader.canvas = shader.canvas || canvas - var w = shader.canvas.w, h = shader.canvas.h - shader.canvas.forEach(function(lex, x, y){ - fn(lex, x, y, w, h, t) - lex.build() - }) - } - exports.toggle = function(state){ - animating = typeof state == "boolean" ? state : ! animating - shader_fps_el.classList.toggle('hidden') - return animating - } - exports.pause = function(){ - animating = false - shader_fps_el.classList.add('hidden') - shader.fps_time = 0 - } - exports.play = function(){ - animating = true - shader_fps_el.classList.remove('hidden') - } - exports.animate = function (t){ - requestAnimationFrame(exports.animate) - if (! animating) { return } - if (shader.fps_time){ - var ms = Date.now() - shader.fps_time - fps = 1000 / ms - shader_fps_el.innerHTML = (fps | 0) + ' fps' - } - shader.fps_time = Date.now() - exports.run(canvas) - } - - return exports - -})()