commit:9256da6552a4cc9cafea96dd0792cb27588143d1
author:Chip Black
committer:Chip Black
date:Tue Sep 15 02:59:37 2009 -0500
parents:
Add Bytex64.FX library
diff --git a/Bytex64.FX.js b/Bytex64.FX.js
line changes: +103/-0
index 0000000..5391fc9
--- /dev/null
+++ b/Bytex64.FX.js
@@ -0,0 +1,103 @@
+if (typeof(Bytex64) == 'undefined') Bytex64 = {};
+Bytex64.FX = {};
+
+Bytex64.FX.Effect = function(fx, secs) {
+    obj = this;
+    this.fx = fx;
+    this.secs = secs;
+
+    this.run = function() {
+        Bytex64.FX.run(this.fx, this.secs);
+    };
+};
+
+Bytex64.FX.ParallelEffect = function(fxs, secs) {
+    this.fx = function(p) {
+        for (i in fxs) {
+            fxs[i](p);
+        }
+    };
+    this.secs = secs;
+
+    this.run = function() {
+        Bytex64.FX.run(this.fx, this.secs);
+    };
+};
+
+Bytex64.FX.EffectChain = function(chain) {
+    this.chain = chain;
+    this.current = 0;
+
+    this.fx_current = function(p) {
+        this.chain[this.current].fx(p);
+    };
+
+    this.run = function() {
+        _this = this;
+
+        fx = function(p) {
+            _this.fx_current(p);
+            if (p == 1.0)
+                _this.run_next();
+        };
+
+        Bytex64.FX.run(fx, this.chain[this.current].secs);
+    };
+
+    this.run_next = function() {
+        this.current++;
+
+        if (this.current >= this.chain.length) {
+            this.current = 0;
+            return;
+        }
+
+        this.run();
+    };
+
+};
+
+Bytex64.FX.updateInterval = 50;
+
+Bytex64.FX.run = function(fx, secs) {
+    secs = secs * 1000;
+
+    var interval;
+    var start = (new Date()).getTime();
+
+    fx(0.0);
+
+    interval = setInterval(function() {
+        var d = (new Date()).getTime() - start;
+        if (d >= secs) {
+            clearInterval(interval);
+            fx(1.0);
+        } else {
+            fx(d/secs);
+        }
+    }, Bytex64.FX.updateInterval);
+}
+
+Bytex64.FX.create = function(fx, secs) {
+    return function() {
+        Bytex64.FX.run(fx, secs);
+    }
+}
+
+Bytex64.FX.fadeIn = function(elem) {
+    return function(p) {
+        if (p == 0.0)
+            elem.style.display = 'block';
+        elem.style.opacity = p;
+    }
+}
+
+Bytex64.FX.fadeOut = function(elem) {
+    return function(p) {
+        elem.style.opacity = 1.0 - p;
+        if (p == 1.0)
+            elem.style.display = 'none';
+    }
+}
+
+/* vim: set ts=4 sts=4 sw=4 expandtab: */