distill_difference

Creato Il diff non scade mai
165 rimozioni
714 linee
194 aggiunte
701 linee
// ZIM - https://zimjs.com - DISTILLED NON-MINIFIED
// ZIM - https://zimjs.com - DISTILLED NON-MINIFIED


var WW = window||{}; var createjs = WW.createjs; if (zogr) {zogr("ZIM - duplicate creation of zim (remove import if using a distilled version)");}; var zimDefaultFrame; var zog = console.log.bind(console); if (typeof zon === "undefined") zon = false; if (typeof zns == "undefined") zns = false; var z_i; function zot(v) {return v==null;}
var WW = window||{}; var createjs = WW.createjs; if (zogr) {zogr("ZIM - duplicate creation of zim (remove import if using a distilled version)");}; var zimDefaultFrame; var zog = console.log.bind(console); if (typeof zon === "undefined") zon = false; if (typeof zns == "undefined") zns = false; var z_i; function zot(v) {return v==null;}
WW.zapp_scaling = WW.zapp_width = WW.zapp_height = WW.zapp_color = WW.zapp_outerColor = WW.zapp_assets = WW.zapp_path = WW.zapp_progress = WW.zapp_gpu = WW.zapp_gpuObj = WW.zapp_maxNum = WW.zapp_singleTouch = null;
WW.zapp_scaling = WW.zapp_width = WW.zapp_height = WW.zapp_color = WW.zapp_outerColor = WW.zapp_assets = WW.zapp_path = WW.zapp_progress = WW.zapp_gpu = WW.zapp_gpuObj = WW.zapp_maxNum = WW.zapp_singleTouch = null;
function zid(s) {
function zid(s) {
return document.getElementById(s);
return document.getElementById(s);
}
}


function zil() {
function zil() {
var a = function(e) {if (!e) e = event; if (e.keyCode && (e.keyCode >= 32 && e.keyCode <= 40)) e.preventDefault();};
if (WW.zilK) { // do not double apply
var b = function(e) {if (!e) e = event; e.preventDefault();};
WW.removeEventListener("keydown", WW.zilK);
var c = b;
WW.removeEventListener("wheel", WW.zilW);
window.addEventListener("keydown", a, {passive:false});
WW.removeEventListener("DOMMouseScroll", WW.zilS);
window.addEventListener("wheel", b, {passive:false});
}
window.addEventListener("DOMMouseScroll", c, {passive:false});
WW.zilK = function(e) {if (!e) e = event; if (e.keyCode && (e.keyCode >= 32 && e.keyCode <= 40)) e.preventDefault();};
return [a, b, c];
WW.zilW = function(e) {if (!e) e = event; e.preventDefault();};
WW.zilS = WW.zilW;
WW.addEventListener("keydown", WW.zilK, {passive:false});
WW.addEventListener("wheel", WW.zilW, {passive:false});
WW.addEventListener("DOMMouseScroll", WW.zilS, {passive:false});
return [WW.zilK, WW.zilW, WW.zilS];
}
}


function zet(selector) {
function zet(selector, first) {
function Zet() {
function Zet() {
var that = this;
var that = this;
this.on = function(type, call) {
this.on = function(type, call) {
if (zot(selector) || zot(type) || zot(call)) return;
if (zot(selector) || zot(type) || zot(call)) return;
var tags = that.tags;
var tags = that.tags;
for (var i=0; i<tags.length; i++) {
for (var i=0; i<tags.length; i++) {
tags[i].addEventListener(type, call);
tags[i].addEventListener(type, call);
}
}
};
};
this.off = function(type, call) {
this.off = function(type, call) {
if (zot(selector) || zot(type) || zot(call)) return;
if (zot(selector) || zot(type) || zot(call)) return;
var tags = that.tags;
var tags = that.tags;
for (var i=0; i<tags.length; i++) {
for (var i=0; i<tags.length; i++) {
tags[i].removeEventListener(type, call);
tags[i].removeEventListener(type, call);
}
}
};
};
Object.defineProperty(that, 'tags', {
Object.defineProperty(that, 'tags', {
get: function() {
get: function() {
if (zot(selector)) return [];
if (zot(selector)) return [];
if (typeof selector == 'string' || selector instanceof String) {
if (typeof selector == 'string' || selector instanceof String) {
return document.querySelectorAll(selector);
if (first) zogo(selector, document.querySelector(selector))
if (first) return [document.querySelector(selector)];
else return document.querySelectorAll(selector);
} else { // selector is already an object - assume a tag
} else { // selector is already an object - assume a tag
if (typeof (selector).innerHTML == "string") return [selector];
if (typeof (selector).innerHTML == "string") return [selector];
return [];
return [];
}
}
},
},
set: function() {
set: function() {
}
}
});
});
this.css = function(property, value) {
this.css = function(property, value) {
// if property is object then assign all props in object
// if property is object then assign all props in object
var tags = that.tags;
var tags = that.tags;
for (var i=0; i<tags.length; i++) {
for (var i=0; i<tags.length; i++) {
if (arguments.length == 1 && arguments[0].constructor === {}.constructor) {
if (arguments.length == 1 && arguments[0].constructor === {}.constructor) {
for (var p in property) {
for (var p in property) {
tags[i].style[p] = property[p];
tags[i].style[p] = property[p];
}
}
} else if (arguments.length == 1) {
} else if (arguments.length == 1) {
return that.tags[0].style[property];
return that.tags[0].style[property];
} else {
} else {
tags[i].style[property] = value;
tags[i].style[property] = value;
}
}
}
}
};
};
this.prop = function(property, value) {
this.prop = function(property, value) {
if (zot(property)) return;
if (zot(property)) return;
var tags = that.tags;
var tags = that.tags;
var a = [];
var a = [];
for (var i=0; i<tags.length; i++) {
for (var i=0; i<tags.length; i++) {
if (zot(value)) {
if (zot(value)) {
if (property.constructor === {}.constructor) {
if (property.constructor === {}.constructor) {
for (var p in property) {
for (var p in property) {
tags[i][p] = property[p];
tags[i][p] = property[p];
}
}
} else {
} else {
a.push(tags[i][property]);
a.push(tags[i][property]);
}
}
} else {
} else {
tags[i][property] = value;
tags[i][property] = value;
}
}
}
}
if (zot(value)) return a;
if (zot(value)) return a;
};
};
}
}
return new Zet();
return new Zet();
}
}


function zik(v) {
function zik(v) {
if (zot(v)) return;
if (zot(v)) return;
return zim.Pick.choose(v);
return zim.Pick.choose(v);
}
}
var zogr=zogb=zogp=zogy=zogo=zogl=zogd=zog;
var zogr=zogb=zogp=zogy=zogo=zogl=zogd=zog;
function isDUO(a) {return a.length == 1 && a[0] != undefined && a[0].constructor === {}.constructor;}
function isDUO(a) {return a.length == 1 && a[0] != undefined && a[0].constructor === {}.constructor;}
function zob(func, args, sig, scope) {
function zob(func, args, sig, scope) {
var zimon = (zim && (zim.ZIMONON || window.ZIMONON));
var zimon = (zim && (zim.ZIMONON || window.ZIMONON));
if (isDUO(args)) {
if (isDUO(args)) {
var zp = args[0];
var zp = args[0];
var za = (zot(sig))?func.toString().split(/\n/,1)[0].match(/\((.*)\)/)[1].replace(/\s+/g,"").split(","):sig.replace(/\s+/g,"").split(",");
var za = (zot(sig))?func.toString().split(/\n/,1)[0].match(/\((.*)\)/)[1].replace(/\s+/g,"").split(","):sig.replace(/\s+/g,"").split(",");
var zv = []; var zi; var zt;
var zv = []; var zi; var zt;
for (zi=0; zi<za.length; zi++) {zt=za[zi].split("=")[0]; za[zi]=zt; zv.push(zp[zt]);}
for (zi=0; zi<za.length; zi++) {zt=za[zi].split("=")[0]; za[zi]=zt; zv.push(zp[zt]);}
for (zi in zp) {if (za.indexOf(zi)<0) {if (zon) zog(func,"bad argument "+zi);}};
for (zi in zp) {if (za.indexOf(zi)<0) {if (zon) zog(func,"bad argument "+zi);}};
var zr; if (zr=(func.prototype.isPrototypeOf(scope))?new (func.bind.apply(func,[null].concat(zv)))():func.apply(null,zv)) {if (zimon && !zr.arguments) {zr.arguments = [zp]}; return zr;} else {return true;}
var zr; if (zr=(func.prototype.isPrototypeOf(scope))?new (func.bind.apply(func,[null].concat(zv)))():func.apply(null,zv)) {if (zimon && !zr.arguments) {zr.arguments = [zp]}; return zr;} else {return true;}
} else {
} else {
if (zimon && scope && args && zot(scope.arguments)) {
if (zimon && scope && args && zot(scope.arguments)) {
scope.arguments = Array.prototype.slice.call(args);
scope.arguments = Array.prototype.slice.call(args);
}
}
}
}
}
}
if (!zns) {var orange="#f58e25"; var green="#acd241"; var pink="#e472c4"; var blue="#50c4b7"; var brown="#d1a170"; var yellow="#ebcb35"; var purple="#993399"; var red="#fb4758"; var silver="#999999"; var pewter="#888888"; var tin="#777777"; var granite="#666666"; var grey="#555555"; var gray="#555555"; var charcoal="#444444"; var licorice="#222222"; var lighter="#eeeeee"; var moon = "#dddddd"; var light="#cccccc"; var mist="#bbbbbb"; var fog="#aaaaaa"; var dark="#333333"; var darker="#111111"; var black="#000000"; var white="#ffffff"; var clear="rgba(0,0,0,0)"; var faint="rgba(0,0,0,.01)";}
if (!zns) {var orange="#f58e25"; var green="#acd241"; var pink="#e472c4"; var blue="#50c4b7"; var brown="#d1a170"; var yellow="#ebcb35"; var purple="#993399"; var red="#fb4758"; var silver="#999999"; var pewter="#888888"; var tin="#777777"; var granite="#666666"; var grey="#555555"; var gray="#555555"; var charcoal="#444444"; var licorice="#222222"; var lighter="#eeeeee"; var moon = "#dddddd"; var light="#cccccc"; var mist="#bbbbbb"; var fog="#aaaaaa"; var dark="#333333"; var darker="#111111"; var black="#000000"; var white="#ffffff"; var clear="rgba(0,0,0,0)"; var faint="rgba(0,0,0,.01)";}
if (!zns) {var TIME="seconds"; var TIMECHECK=true; var ANIMATE=true; var OPTIMIZE=false; var ACTIONEVENT="mousedown"; var DEFAULTWIRE="currentValue"; var POSREG=true; var DRAGALL=true;}
if (!zns) {var TIME="seconds"; var TIMECHECK=true; var ANIMATE=true; var OPTIMIZE=false; var ACTIONEVENT="mousedown"; var DEFAULTWIRE="currentValue"; var POSREG=true; var DRAGALL=true;}
if (!zns) {var TOP="top"; var BOTTOM="bottom"; var LEFT="left"; var RIGHT="right"; var CENTER="center"; var MIDDLE="middle"; var HORIZONTAL="horizontal"; var VERTICAL="vertical"; var BOTH="both"; var UP="up"; var DOWN="down"; var AUTO="auto"; var DEFAULT="default"; var AVE="ave"; var DIR="dir"; var START="start"; var END="end"; var NEXT="next"; var PREV="prev"; var GET="get"; var POST="post"; var LOCALSTORAGE="localstorage"; var SOCKET="socket"; var TO="to"; var FROM="from"; var SINE="sine"; var SQUARE="square"; var TRIANGLE="triangle"; var SAW="saw"; var ZAP="zap"}
if (!zns) {var TOP="top"; var BOTTOM="bottom"; var LEFT="left"; var RIGHT="right"; var CENTER="center"; var MIDDLE="middle"; var HORIZONTAL="horizontal"; var VERTICAL="vertical"; var BOTH="both"; var UP="up"; var DOWN="down"; var AUTO="auto"; var DEFAULT="default"; var AVE="ave"; var DIR="dir"; var START="start"; var END="end"; var NEXT="next"; var PREV="prev"; var GET="get"; var POST="post"; var LOCALSTORAGE="localstorage"; var SOCKET="socket"; var TO="to"; var FROM="from"; var SINE="sine"; var SQUARE="square"; var TRIANGLE="triangle"; var SAW="saw"; var ZAP="zap"}
if (!zns) {var TAU=Math.PI*2; var DEG=180/Math.PI; var RAD=Math.PI/180; var VERSION="cat/04/zim";}
if (!zns) {var TAU=Math.PI*2; var DEG=180/Math.PI; var RAD=Math.PI/180; var VERSION="019/zim";}
var zim = function(zim) {
var zim = function(zim) {


zim.extend = function(subclass, superclass, override, prefix, prototype) {
zim.extend = function(subclass, superclass, override, prefix, prototype) {
var sig = "subclass, superclass, override, prefix, prototype";
var sig = "subclass, superclass, override, prefix, prototype";
var duo; if (duo = zob(zim.extend, arguments, sig)) return duo;
var duo; if (duo = zob(zim.extend, arguments, sig)) return duo;
if (zot(subclass) || zot(superclass)) {
if (zot(subclass) || zot(superclass)) {
if (zon && subclass!=zim.StageGL) zog("zim.extend() - please supply a class and its superclass");
if (zon && subclass!=zim.StageGL) zogy("zim.extend() - please supply a class and its superclass");
return;
return;
}
}
// zogr("start")
// zogr("start")
if (zot(prefix)) prefix = "super";
if (zot(prefix)) prefix = "super";
if (zot(override)) override = [];
if (zot(override)) override = [];
if (!Array.isArray(override)) override = [override];
if (!Array.isArray(override)) override = [override];
if (zot(prototype)) prototype = true;
if (zot(prototype)) prototype = true;
// modified CreateJS extend() to include any prototype members already added
// modified CreateJS extend() to include any prototype members already added
// see http://www.createjs.com/docs/easeljs/classes/Utility%20Methods.html
// see https://www.createjs.com/docs/easeljs/classes/Utility%20Methods.html
var existingP = {};
var existingP = {};
for (var f in subclass.prototype) Object.defineProperty(existingP,f,Object.getOwnPropertyDescriptor(subclass.prototype, f));
for (var f in subclass.prototype) Object.defineProperty(existingP,f,Object.getOwnPropertyDescriptor(subclass.prototype, f));
function o() {this.constructor = subclass;}
function o() {this.constructor = subclass;}
o.prototype = superclass.prototype;
o.prototype = superclass.prototype;
subclass.prototype = new o();
subclass.prototype = new o();
for (f in existingP) {
for (f in existingP) {
Object.defineProperty(subclass.prototype,f,Object.getOwnPropertyDescriptor(existingP,f));
Object.defineProperty(subclass.prototype,f,Object.getOwnPropertyDescriptor(existingP,f));
}
}


// modified CreateJS promote() to promote methods other than constructor only if methods is true
// modified CreateJS promote() to promote methods other than constructor only if methods is true
// zim does not override with prototypes so it is uneccessary to loop through the super class methods
// zim does not override with prototypes so it is uneccessary to loop through the super class methods
// added checking an array of string values of methods defined in class (not prototype) that are being overridden
// added checking an array of string values of methods defined in class (not prototype) that are being overridden
var subP = subclass.prototype;
var subP = subclass.prototype;
var supP = (Object.getPrototypeOf&&Object.getPrototypeOf(subP))||subP.__proto__;
var supP = (Object.getPrototypeOf&&Object.getPrototypeOf(subP))||subP.__proto__;
if (supP) {
if (supP) {
subP[(prefix+="_") + "constructor"] = supP.constructor; // constructor is not always innumerable
subP[(prefix+="_") + "constructor"] = supP.constructor; // constructor is not always innumerable
var n;
var n;
for (var i=0; i<override.length; i++) {
for (var i=0; i<override.length; i++) {
n = override[i];
n = override[i];
if (typeof supP[n] == "function") {
if (typeof supP[n] == "function") {
subP[prefix + n] = supP[n];
subP[prefix + n] = supP[n];
}
}
}
}
if (prototype) {
if (prototype) {
for (n in supP) {
for (n in supP) {
if (subP.hasOwnProperty(n) && (typeof supP[n] == "function")) {subP[prefix + n] = supP[n];}
if (Object.prototype.hasOwnProperty.call(subP, n) && (typeof supP[n] == "function")) {subP[prefix + n] = supP[n];}
}
}
}
}
}
}
return subclass;
return subclass;
};
};
zim.orange="#f58e25"; zim.green="#acd241"; zim.pink="#e472c4"; zim.blue="#50c4b7"; zim.brown="#d1a170"; zim.yellow="#ebcb35"; zim.purple="#993399"; zim.red="#fb4758"; zim.silver="#999999"; zim.pewter="#888888"; zim.tin="#777777"; zim.granite="#666666"; zim.grey="#555555"; zim.gray="#555555"; zim.charcoal="#444444"; zim.licorice="#222222"; zim.lighter="#eeeeee"; zim.moon="#dddddd"; zim.light="#cccccc"; zim.mist="#bbbbbb"; zim.fog="#aaaaaa"; zim.dark="#333333"; zim.darker="#111111"; zim.black="#000000"; zim.white="#ffffff"; zim.clear="rgba(0,0,0,0)"; zim.faint="rgba(0,0,0,.01)";
zim.orange="#f58e25"; zim.green="#acd241"; zim.pink="#e472c4"; zim.blue="#50c4b7"; zim.brown="#d1a170"; zim.yellow="#ebcb35"; zim.purple="#993399"; zim.red="#fb4758"; zim.silver="#999999"; zim.pewter="#888888"; zim.tin="#777777"; zim.granite="#666666"; zim.grey="#555555"; zim.gray="#555555"; zim.charcoal="#444444"; zim.licorice="#222222"; zim.lighter="#eeeeee"; zim.moon="#dddddd"; zim.light="#cccccc"; zim.mist="#bbbbbb"; zim.fog="#aaaaaa"; zim.dark="#333333"; zim.darker="#111111"; zim.black="#000000"; zim.white="#ffffff"; zim.clear="rgba(0,0,0,0)"; zim.faint="rgba(0,0,0,.01)";
String.prototype.darken = function(a) {return zim.darken(this, a);}; String.prototype.lighten = function(a) {return zim.lighten(this, a);};
String.prototype.darken = function(a) {return zim.darken(this, a);}; String.prototype.lighten = function(a) {return zim.lighten(this, a);};
zim.TIME="seconds"; zim.TIMECHECK=true; zim.ANIMATE = true; zim.OPTIMIZE = false; zim.ACTIONEVENT = "mousedown"; zim.DEFAULTWIRE = "currentValue"; zim.POSREG = false; zim.DRAGALL = false;
zim.TIME="seconds"; zim.TIMECHECK=true; zim.ANIMATE = true; zim.OPTIMIZE = false; zim.ACTIONEVENT = "mousedown"; zim.DEFAULTWIRE = "currentValue"; zim.POSREG = false; zim.DRAGALL = false;
zim.TOP="top"; zim.BOTTOM="bottom"; zim.LEFT="left"; zim.RIGHT="right"; zim.CENTER="center"; zim.MIDDLE="middle"; zim.HORIZONTAL="horizontal"; zim.VERTICAL="vertical"; zim.BOTH="both"; zim.UP="up"; zim.DOWN="down"; zim.AUTO="auto"; zim.DEFAULT="default"; zim.AVE="ave"; zim.DIR="dir"; zim.START="start"; zim.END="end"; zim.NEXT="next"; zim.PREV="prev"; zim.GET="get"; zim.POST="post"; zim.LOCALSTORAGE="localstorage"; zim.SOCKET="socket"; zim.TO="to"; zim.FROM="from"; zim.SINE="sine"; zim.SQUARE="square"; zim.TRIANGLE="triangle"; zim.SAW="saw"; zim.ZAP="zap"
zim.TOP="top"; zim.BOTTOM="bottom"; zim.LEFT="left"; zim.RIGHT="right"; zim.CENTER="center"; zim.MIDDLE="middle"; zim.HORIZONTAL="horizontal"; zim.VERTICAL="vertical"; zim.BOTH="both"; zim.UP="up"; zim.DOWN="down"; zim.AUTO="auto"; zim.DEFAULT="default"; zim.AVE="ave"; zim.DIR="dir"; zim.START="start"; zim.END="end"; zim.NEXT="next"; zim.PREV="prev"; zim.GET="get"; zim.POST="post"; zim.LOCALSTORAGE="localstorage"; zim.SOCKET="socket"; zim.TO="to"; zim.FROM="from"; zim.SINE="sine"; zim.SQUARE="square"; zim.TRIANGLE="triangle"; zim.SAW="saw"; zim.ZAP="zap"
zim.TAU=Math.PI*2; zim.DEG=180/Math.PI; zim.RAD=Math.PI/180; zim.VERSION="cat/04/zim";
zim.TAU=Math.PI*2; zim.DEG=180/Math.PI; zim.RAD=Math.PI/180; zim.VERSION="019/zim";
zim.distill = function(){zog("zim.Distill() - done - you can remove command")};
zim.distill = function(){zog("zim.Distill() - done - you can remove command")};
function zenable(t,v) {if (v) {t.mouseChildren = true;t.mouseEnabled = true;t._enabled = true;} else {t.mouseChildren = false;t.mouseEnabled = false;t._enabled = false;}}
function zenable(t,v) {if (v) {t.mouseChildren = true;t.mouseEnabled = true;t._enabled = true;} else {t.mouseChildren = false;t.mouseEnabled = false;t._enabled = false;}}


zim.chop = function(obj, cols, rows, tile, margin) {
zim.chop = function(obj, cols, rows, tile, margin, scale) {
if (zot(obj)) return;
if (zot(obj)) return;
if (zot(cols)) cols = 3;
if (zot(cols)) cols = 3;
if (zot(rows)) rows = 3;
if (zot(rows)) rows = 3;
if (zot(tile)) tile = true;
if (zot(tile)) tile = true;
if (zot(margin)) margin = 0;
if (zot(margin)) margin = 0;
var w = obj.width/cols;
if (zot(scale)) scale = 1;
var h = obj.height/rows;
// removed in ZIM ZIM 01 patch - causing parts to be same size canvas as original
// if (obj.uncache) { // testing if it has a CreateJS uncache method
// obj = obj.cache(null,null,null,null,scale).cacheCanvas;
// }
// var w = obj.width/cols;
// var h = obj.height/rows;
if (!obj.getBounds) obj = new zim.Bitmap(obj); // added ZIM ZIM 02
var b = obj.getBounds();
if (zot(b)) zogy("ZIM chop() - obj must have bounds");
var w = b.width/cols;
var h = b.height/rows;
var m = margin;
var m = margin;
var pieces = [];
var pieces = [];
zim.loop(rows, function (r) {
zim.loop(rows, function (r) {
zim.loop(cols, function (c) {
zim.loop(cols, function (c) {
var p = new zim.Bitmap(obj, w+m*2, h+m*2, c*w-m, r*h-m);
var p = new zim.Bitmap(obj, w+m*2, h+m*2, c*w-m, r*h-m, scale);
if (margin != 0) {
if (margin != 0) {
p.setBounds(m,m,w,h);
p.setBounds(m,m,w,h);
p.regX = m;
p.regX = m;
p.regY = m;
p.regY = m;
} else {
p.setBounds(m,m,w,h);
}
}
pieces.push(p);
pieces.push(p);
});
});
});
});
if (tile) return new zim.Tile(pieces,cols,rows,0,0,true);
if (tile) return new zim.Tile(pieces,cols,rows,0,0,true).sca(obj.scaleX,obj.scaleY);
else return pieces;
else return pieces;
};
};


zim.shuffle = function(array) {
zim.shuffle = function(array, different) {
if (zot(array)) return;
if (zot(array)) return;
if (!Array.isArray(array)) array = Object.values(arguments);
var i = array.length, j, temp;
var i = array.length, j, temp;
if (i == 0) return array;
if (i <= 1) return array;
while(--i) {
if (different) {
j = Math.floor(Math.random()*(i+1));
var sur = {};
temp=array[i];
var arr = [];
array[i]=array[j];
for (var i=0; i<array.length; i++) {
array[j]=temp;
sur[i] = array[i];
arr.push(i);
}
var original = zim.copy(arr);
zim.shuffle(arr);
while (zim.arraysEqual(original, arr)) {
zim.shuffle(arr);
}
for (i=0; i<arr.length; i++) {
array[i] = sur[arr[i]];
}
return array;
} else {
while(--i) {
j = Math.floor(Math.random()*(i+1));
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
return array;
}
}
return array;
};
};


zim.rand = function(a, b, integer, negative) {
zim.rand = function(a, b, integer, negative) {
if (zot(a) && zot(b)) return Math.random();
if (zot(a) && zot(b)) return Math.random();
if (zot(a) || isNaN(a)) a = 0;
if (zot(a) || isNaN(a)) a = 0;
if (zot(b) || isNaN(b)) b = 0;
if (zot(b) || isNaN(b)) b = 0;
if (a%1!=0 || b%1!=0) integer = false;
if (a%1!=0 || b%1!=0) integer = false;
if (zot(integer)) integer = true;
if (zot(integer)) integer = true;
if (negative) if (Math.random()>.5) {a*=-1; b*=-1;}
if (negative) if (Math.random()>.5) {a*=-1; b*=-1;}
if (integer) if (a>b) {a++;} else if (b>a) {b++;}
if (integer) if (a>b) {a++;} else if (b>a) {b++;}
var r;
var r;
if (a == 0 && b == 0) return 0;
if (a == 0 && b == 0) return 0;
else if (b == 0) r = Math.random()*a;
else if (b == 0) r = Math.random()*a;
else r = Math.min(a,b) + Math.random()*(Math.max(a,b)-Math.min(a,b));
else r = Math.min(a,b) + Math.random()*(Math.max(a,b)-Math.min(a,b));
if (integer) return Math.floor(r);
if (integer) return Math.floor(r);
else return r;
else return r;
};
};


zim.timeout = function(time, call, pauseOnBlur, timeUnit) {
zim.timeout = function(time, call, pauseOnBlur, timeUnit) {
var sig = "time, call, pauseOnBlur, timeUnit";
var sig = "time, call, pauseOnBlur, timeUnit";
var duo; if (duo = zob(zim.timeout, arguments, sig, this)) return duo;
var duo; if (duo = zob(zim.timeout, arguments, sig, this)) return duo;
if (zot(call)) return;
if (zot(call)) return;
if (typeof call != 'function') return;
if (typeof call != 'function') return;

var o = zim.interval(time, call, 1, false, pauseOnBlur, timeUnit, null, null, true);
var timeType = getTIME(time, timeUnit);
o.type = "timeoutObj";
if (zot(time)) time = timeType=="s"?1:1000;
return o;

time = zim.Pick.choose(time);
var obj = {startTime:Date.now(), time:0, paused:false, done:false, timeUnit:timeUnit};

if (pauseOnBlur) {
if (zot(zim.blurCheck)) zim.setBlurDetect();
zim.pauseOnBlur.push(obj);
}

var lastTime = obj.startTime;
function next() {
var now = Date.now();
obj.time += (now - lastTime)/(timeType=="s"?1000:1);
lastTime = now;
if (obj.time >= time) {
obj.done = true;
(call)(obj);
obj.clear();
return;
}
obj.rid = requestAnimationFrame(next);
}

obj.pause = function(state, immediate, reset) {
if (zot(state)) state = true;
if (state) { // pausing
cancelAnimationFrame(obj.rid);
} else { // unpausing
if (immediate) lastTime = 0; // a long time ago ;-)
else if (reset) {lastTime = Date.now(); obj.time=0;}
else lastTime = Date.now();
next();
}
obj.paused = state;
};

obj.clear = function() {
if (obj) cancelAnimationFrame(obj.rid);
for (var i in obj) {
delete obj[i];
}
obj.pause = function() {};
obj.clear = function() {};
};
next(); // thanks StevenWarren for the glitch fix!
return obj;
};
};


zim.interval = function(time, call, total, immediate, pauseOnBlur, timeUnit) {
zim.interval = function(time, call, total, immediate, pauseOnBlur, timeUnit, complete, completeParams, timeout, mID, tether) {
var sig = "time, call, total, immediate, pauseOnBlur, timeUnit";
var sig = "time, call, total, immediate, pauseOnBlur, timeUnit, complete, completeParams, timeout, mID, tether";
var duo; if (duo = zob(zim.interval, arguments, sig, this)) return duo;
var duo; if (duo = zob(zim.interval, arguments, sig, this)) return duo;
if (zot(call)) return;
if (zot(call)) return;
if (typeof call != 'function') return;
if (typeof call != 'function') return;

var timeType = getTIME(time, timeUnit);
var timeType = getTIME(time, timeUnit);
if (zot(time)) time = timeType=="s"?1:1000;
if (zot(time)) time = timeType=="s"?1:1000;


if (!timeout) {
var initialT = total;
var tag = zim.makeID();

}

if (zot(immediate)) immediate = false;
if (zot(immediate)) immediate = false;
if (!zot(total) && (isNaN(total) || total<=0)) return;
if (!zot(total) && (isNaN(total) || total<=0)) return;
if (zot(total)) total = -1;
if (zot(total)) total = -1;
var obj = {count:0, total:total, paused:false, time:time, active:true, timeUnit:timeUnit};
var obj = {count:(immediate && (!isPick(time) && time <= (timeType=="s"?5/1000:5))) ? -1:0, total:total, paused:false, time:time, active:true, timeUnit:timeUnit};


if (pauseOnBlur) {
if (pauseOnBlur) {
if (zot(zim.blurCheck)) zim.setBlurDetect();
if (zot(zim.blurCheck)) zim.setBlurDetect();
zim.pauseOnBlur.push(obj);
zim.pauseOnBlur.push(obj);
}
}

function interval() {
function interval() {
obj.startTime = Date.now();
obj.startTime = Date.now();
obj.interval = zim.Pick.choose(obj.time);
obj.interval = zim.Pick.choose(obj.time);
obj.id = setTimeout(function() {
obj.id = setTimeout(function() {
if (obj.paused) return;
if (obj.paused) return;
if (!obj.active) return;
if (!obj.active) return;
// obj.rid = requestAnimationFrame(interval);
// obj.rid = requestAnimationFrame(interval);
obj.count++;
obj.count++;
(call)(obj);
(call)(obj);
interval();
interval();
checkTotal();
checkTotal();
}, obj.interval*(timeType=="s"?1000:1));
}, obj.interval*(timeType=="s"?1000:1));


}
}
if (immediate) {
if (immediate && (isPick(time) || time > (timeType=="s"?5/1000:5))) {
setTimeout(function() {
setTimeout(function() {
(call)(obj);
(call)(obj);
checkTotal();
checkTotal();
}, 10);
}, 5);
}
}
function checkTotal() {
function checkTotal() {
if (total == -1) return;
if (total == -1) return;
if (obj.count >= (immediate?obj.total-1:obj.total)) obj.clear();
if (obj.count >= (immediate?obj.total-1:obj.total)) {
if (complete && typeof complete=="function") complete(completeParams);
obj.clear();
}
}
}
var pausedTimeout;
var pausedTimeout;
obj.type = "intervalObject";
obj.pause = function(state, immediate, reset) {
obj.pause = function(state, immediate, reset) {
if (zot(state)) state = true;
if (zot(state)) state = true;
if (state) { // pausing
if (state) { // pausing
clearTimeout(pausedTimeout);
clearTimeout(pausedTimeout);
clearTimeout(obj.id);
clearTimeout(obj.id);
cancelAnimationFrame(obj.rid);
cancelAnimationFrame(obj.rid);
obj.pauseTimeLeft = obj.interval-(Date.now()-obj.startTime)/(timeType=="s"?1000:1);
obj.pauseTimeLeft = obj.interval-(Date.now()-obj.startTime)/(timeType=="s"?1000:1);

} else { // unpausing
} else { // unpausing
if (!obj.paused) obj.pause(true);
if (!obj.paused) obj.pause(true);
pausedTimeout = setTimeout(function() {
pausedTimeout = setTimeout(function() {
obj.count++;
obj.count++;
(call)(obj);
(call)(obj);
interval();
interval();
checkTotal();
checkTotal();
}, immediate?0:(reset?obj.interval:obj.pauseTimeLeft)*(timeType=="s"?1000:1));
}, immediate?0:(reset?obj.interval:obj.pauseTimeLeft)*(timeType=="s"?1000:1));
obj.pauseTimeLeft = null;
obj.pauseTimeLeft = null;

}
}
obj.paused = state;
obj.paused = state;
};
};
obj.next = function() {
obj.count++;
(call)(obj);
checkTotal();
};
obj.clear = function() {
obj.clear = function() {
obj.active = false;
obj.active = false;
clearTimeout(pausedTimeout);
clearTimeout(pausedTimeout);
cancelAnimationFrame(obj.rid);
cancelAnimationFrame(obj.rid);
clearTimeout(obj.id);
clearTimeout(obj.id);
var count = obj.count;
var count = obj.count;
for (var i in obj) {
for (var i in obj) {
delete obj[i];
delete obj[i];
}
}
obj.active = false;
obj.active = false;
obj.count = count;
obj.count = count;
obj.pause = function() {};
obj.pause = function() {};
obj.clear = function() {};
obj.clear = function() {};

};
};
interval();
interval();
return obj;
return obj;
};
};


function getTIME(time, timeUnit, minWarning, maxWarning, noWarning) {
function getTIME(time, timeUnit, minWarning, maxWarning, noWarning) {
var timeType = zot(TIME) ? zot(zim.TIME) ? "seconds" : zim.TIME : TIME;
var timeType = zot(WW.TIME) ? zot(zim.TIME) ? "seconds" : zim.TIME : WW.TIME;
if (timeType && timeType.toLowerCase) timeType = timeType.toLowerCase();
if (timeType && timeType.toLowerCase) timeType = timeType.toLowerCase();
if (timeType != "milliseconds" && timeType != "ms") timeType = "seconds";
if (timeType != "milliseconds" && timeType != "ms") timeType = "seconds";
if (timeUnit && timeUnit.toLowerCase) timeUnit = timeUnit.toLowerCase();
if (timeUnit && timeUnit.toLowerCase) timeUnit = timeUnit.toLowerCase();
if (timeUnit=="ms" || timeUnit=="milliseconds" || timeUnit=="seconds" || timeUnit=="s") timeType = timeUnit;
if (timeUnit=="ms" || timeUnit=="milliseconds" || timeUnit=="seconds" || timeUnit=="s") timeType = timeUnit;
if (zot(time)) return timeType.charAt(0);
if (zot(time)) return timeType.charAt(0);
if (timeType=="ms") timeType = "milliseconds";
if (timeType=="ms") timeType = "milliseconds";
if (timeType=="s") timeType = "seconds";
if (timeType=="s") timeType = "seconds";
timeType = timeType.charAt(0);
timeType = timeType.charAt(0);
if (!noWarning) checkTIME(time, timeType, minWarning, maxWarning);
if (!noWarning) checkTIME(time, timeType, minWarning, maxWarning);
return timeType;
return timeType;
}
}
function checkTIME(time, timeChar, minWarning, maxWarning) {
function checkTIME(time, timeChar, minWarning, maxWarning) {
if (zot(minWarning)) minWarning = 10;
if (zot(minWarning)) minWarning = 10;
if (zot(maxWarning)) maxWarning = 9;
if (zot(maxWarning)) maxWarning = 9;
if (!zim.TIMECHECK && !TIMECHECK) return;
if (!zim.TIMECHECK && !WW.TIMECHECK) return;
if ((timeChar!="m" && time>minWarning) || (timeChar=="m" && time<maxWarning)) {
if ((timeChar!="m" && time>minWarning) || (timeChar=="m" && time<maxWarning)) {
if (zon) zogy("TIME - warning: time is in "+(timeChar=="m"?"milliseconds":"seconds")+ " ("+time+")");
if (zon) zogy("TIME - warning: time is in "+(timeChar=="m"?"milliseconds":"seconds")+ " ("+time+")");
}
}
}
}


zim.copy = function(obj, clone, cloneContainer) {
zim.copy = function(obj, clone, cloneContainer) {
if (zot(clone)) clone = false;
if (zot(clone)) clone = false;
if (zot(cloneContainer)) cloneContainer = true;
if (zot(cloneContainer)) cloneContainer = true;
if (obj==null || !(obj instanceof Array || obj.constructor == {}.constructor)) return clone&&obj!=null?(obj.clone?(obj.type&&((obj.type!="Container"&&obj.type!="Stage"&&obj.type!="StageGL")||cloneContainer)?obj.clone():obj):obj):obj;
if (obj==null || !(obj instanceof Array || obj.constructor == {}.constructor)) return clone&&obj!=null?(obj.clone?(obj.type&&((obj.type!="Container"&&obj.type!="Stage"&&obj.type!="StageGL")||cloneContainer)?obj.clone():obj):obj):obj;
if (obj instanceof Array) {
if (obj instanceof Array) {
var array = [];
var array = [];
for (var i=0; i<obj.length; i++) {
for (var i=0; i<obj.length; i++) {
array[i] = zim.copy(obj[i], clone, cloneContainer);
array[i] = zim.copy(obj[i], clone, cloneContainer);
}
}
return array;
return array;
}
}
if (obj.constructor == {}.constructor) {
if (obj.constructor == {}.constructor) {
var copy = {};
var copy = {};
for (var attr in obj) {
for (var attr in obj) {
var answer = zim.copy(obj[attr], clone, cloneContainer);
var answer = zim.copy(obj[attr], clone, cloneContainer);
if (obj.hasOwnProperty(attr)) copy[attr] = answer;
if (Object.prototype.hasOwnProperty.call(obj, attr)) copy[attr] = answer;
}
}
return copy;
return copy;
}
}
};
};


zim.isEmpty = function(obj) {
zim.isEmpty = function(obj) {
if (zot(obj)) return;
if (zot(obj)) return;
var count = 0;
var count = 0;
for (var o in obj) {
for (var o in obj) {
count++; break;
count++; break;
}
}
return (count == 0);
return (count == 0);
};
};


zim.isPick = function(obj) {
zim.isPick = function(obj) {
if(zot(obj)) return;
if(zot(obj)) return;
return (Array.isArray(obj)||(obj.constructor=={}.constructor && obj.min!=null && obj.max!=null)||(obj.constructor === Function && (obj.array!=null || obj()!=null))); // obj.array is a series
return (Array.isArray(obj)||(obj.constructor=={}.constructor && ((obj.min!=null && obj.max!=null) || obj.noPick))||(obj.constructor === Function && (obj.array!=null || obj()!=null))); // obj.array is a series
};
};


zim.merge = function() {
zim.merge = function() {
var obj = {}; var i; var j;
var obj = {}; var i; var j;
for (i=0; i<arguments.length; i++) {
for (i=0; i<arguments.length; i++) {
for (j in arguments[i]) {
for (j in arguments[i]) {
if (arguments[i].hasOwnProperty(j)) {
if (Object.prototype.hasOwnProperty.call(arguments[i], j)) {
obj[j] = arguments[i][j];
obj[j] = arguments[i][j];
}
}
}
}
}
}
return obj;
return obj;
};
};


zim.zut = function(e) {
zim.zut = function(e) {
if (zot(e) || typeof e == "object") return true;
if (zot(e) || typeof e == "object") return true;
};
};
zim.decimals = function(num, places, addZeros, addZerosBefore, includeZero, time, evt) {
zim.decimals = function(num, places, addZeros, addZerosBefore, includeZero, time, evt) {
if (zot(num)) return 0;
if (zot(num)) return 0;
if (zot(places)) places = 1;
if (zot(places)) places = 1;
if (zot(addZeros)) addZeros = 0;
if (zot(addZeros)) addZeros = 0;
if (zot(addZerosBefore)) addZerosBefore = 1;
if (zot(addZerosBefore)) addZerosBefore = 1;
if (zot(includeZero)) includeZero = true;
if (zot(includeZero)) includeZero = true;
if (zot(time)) time = false;
if (zot(time)) time = false;
// if (addZeros && places < 0) {
// if (addZeros && places < 0) {
// var place = String(num).indexOf(".");
// var place = String(num).indexOf(".");
// var length = String(num).length;
// var length = String(num).length;
// var left = (place < 0) ? length : place;
// var left = (place < 0) ? length : place;
// for (var i=0; i<-places-left; i++) {num = "0" + num;}
// for (var i=0; i<-places-left; i++) {num = "0" + num;}
// return num;
// return num;
// }
// }
var answer = Math.round(num*Math.pow(10, places))/Math.pow(10, places);
var answer = Math.round(num*Math.pow(10, places))/Math.pow(10, places);
if (time) {
if (time) {
var secs = answer - Math.floor(answer);
var secs = answer - Math.floor(answer);
answer = zim.decimals(Math.floor(answer) + secs*60/100, 2);
answer = zim.decimals(Math.floor(answer) + secs*60/100, 2);
}
}

// if (addZeros && places > 0 && answer != 0) {
// if (addZeros && places > 0 && answer != 0) {
// var place = String(answer).indexOf(".");
// var place = String(answer).indexOf(".");
// var length = String(answer).length;
// var length = String(answer).length;
// if (place < 0) {place = length++; answer+=".";}
// if (place < 0) {place = length++; answer+=".";}
// for (var i=0; i<places-(length-place-1); i++) {answer += "0";}
// for (var i=0; i<places-(length-place-1); i++) {answer += "0";}
// }
// }
var sign = zim.sign(answer);
var sign = zim.sign(answer);
var place,length,i;
if (addZeros > 0) {
if (addZeros > 0) {
var place = String(answer).indexOf(".");
place = String(answer).indexOf(".");
var length = String(answer).length;
length = String(answer).length;
if (place < 0) {place = length++; answer+=".";}
if (place < 0) {place = length++; answer+=".";}
for (var i=0; i<addZeros-(length-place-1); i++) {answer += "0";}
for (i=0; i<addZeros-(length-place-1); i++) {answer += "0";}
}
}
if (addZerosBefore > 1) {
if (addZerosBefore > 1) {
// fix this - Dan Zen - negative decimal number problem
// fix this - Dan Zen - negative decimal number problem
if (sign == -1) answer = answer.substr(1,answer.length-1);
if (sign == -1) answer = answer.substr(1,answer.length-1);
var place = String(answer).indexOf(".");
place = String(answer).indexOf(".");
var length = String(answer).length;
length = String(answer).length;
var left = (place < 0) ? length : place;
var left = (place < 0) ? length : place;
for (var i=0; i<addZerosBefore-left; i++) {answer = "0" + answer;}
for (i=0; i<addZerosBefore-left; i++) {answer = "0" + answer;}
if (sign == -1) answer = "-" + answer;
if (sign == -1) answer = "-" + answer;
}
}
if (addZerosBefore == 0) answer = answer.toString().replace(/^0\./,".");
if (addZerosBefore == 0) answer = answer.toString().replace(/^0\./,".");
if ((addZeros + addZerosBefore > 0) && !includeZero && Number(answer) == 0) answer = 0;
if ((addZeros + addZerosBefore > 0) && !includeZero && Number(answer) == 0) answer = 0;
if (time) answer = String(answer).replace(".", ":");
if (time) answer = String(answer).replace(".", ":");
return zim.zut(evt) ? answer : null;
return zim.zut(evt) ? answer : null;
};
};


zim.sign = function(num) {
zim.sign = function(num) {
return num?num<0?-1:1:0;
return num?num<0?-1:1:0;
};
};


zim.constrain = function(num, min, max, negative) {
zim.constrain = function(num, min, max, negative) {
if (zot(num)) return;
if (zot(num)) return;
if (zot(min)) min = 0;
if (zot(min)) min = 0;
if (zot(max)) max = Number.MAX_VALUE;
if (zot(max)) max = Number.MAX_VALUE;
if (max < min) {var max2 = min; max = min; min = max2;} // ES6 Fix to come
if (max < min) {var max2 = min; max = min; min = max2;} // ES6 Fix to come
if (zot(negative)) negative = false;
if (zot(negative)) negative = false;
if (negative && num < 0) {
if (negative && num < 0) {
return Math.max(-max, Math.min(num, -min));
return Math.max(-max, Math.min(num, -min));
} else {
} else {
return Math.max(min, Math.min(num, max));
return Math.max(min, Math.min(num, max));
}
}
};
};


zim.dist = function(a, b, c, d) {
zim.dist = function(a, b, c, d) {
if (zot(a) || zot(b)) return;
if (zot(a) || zot(b)) return;
if (!zot(a.x) && !zot(b.x)) {
if (!zot(a.x) && !zot(b.x)) {
d = b.y;
d = b.y;
c = b.x;
c = b.x;
b = a.y;
b = a.y;
a = a.x;
a = a.x;
} else {
} else {
if (zot(c)) c = 0;
if (zot(c)) c = 0;
if (zot(d)) d = 0;
if (zot(d)) d = 0;
}
}
return Math.sqrt((Math.pow(c-a, 2) + Math.pow(d-b, 2)));
return Math.sqrt((Math.pow(c-a, 2) + Math.pow(d-b, 2)));
};
};


zim.rectIntersect = function(a, b, margin) {
zim.rectIntersect = function(a, b, margin) {
if (zot(margin)) margin = 0;
if (zot(margin)) margin = 0;
if (a.x >= b.x + b.width + margin || a.x + a.width + margin <= b.x ||
if (a.x >= b.x + b.width + margin || a.x + a.width + margin <= b.x ||
a.y >= b.y + b.height + margin || a.y + a.height + margin <= b.y ) {
a.y >= b.y + b.height + margin || a.y + a.height + margin <= b.y ) {
return false;
return false;
} else {
} else {
return true;
return true;
}
}
};
};


zim.boundsAroundPoints = function(points) {
zim.boundsAroundPoints = function(points) {
var tX = 10000;
var tX = 10000;
var tY = 10000;
var tY = 10000;
var bX = -10000;
var bX = -10000;
var bY = -10000;
var bY = -10000;
for (var i=0; i<points.length; i++) {
for (var i=0; i<points.length; i++) {
var p = points[i];
var p = points[i];
if (p.x < tX) tX = p.x;
if (p.x < tX) tX = p.x;
if (p.x > bX) bX = p.x;
if (p.x > bX) bX = p.x;
if (p.y < tY) tY = p.y;
if (p.y < tY) tY = p.y;
if (p.y > bY) bY = p.y;
if (p.y > bY) bY = p.y;
}
}
return {x:tX, y:tY, width:bX-tX, height:bY-tY};
return {x:tX, y:tY, width:bX-tX, height:bY-tY};
};
};


zim.angle = function(x1, y1, x2, y2) {
zim.angle = function(a, b, c, d) {
if (zot(x1) || zot(y1)) return;
if (zot(a) || zot(b)) return;
if (zot(x2)) {x2 = x1; x1 = 0;}
if (!zot(a.x)) {
if (zot(y2)) {y2 = y1; y1 = 0;}
if (zot(b)) {
return (Math.atan2(y2-y1, x2-x1)*180/Math.PI+360)%360;
a = 0;
b = 0;
c = a.x;
d = a.y;
} else {
d = b.y;
c = b.x;
b = a.y;
a = a.x;
}
} else {
if (zot(c)) {c = a; a = 0;}
if (zot(d)) {d = b; b = 0;}
}
return (Math.atan2(d-b, c-a)*180/Math.PI+360)%360;
};
};


zim.Point = function(x, y, z, q, r, s, t, u, v, w) {
if (typeof createjs != "undefined") {
if (zot(x)) x = 0;
zim.Point = function(x, y, z, q, r, s, t, u, v, w) {
if (zot(y)) y = 0;
if (zot(x)) x = 0;
if (zot(z)) z = 0;
if (zot(y)) y = 0;
if (zot(q)) q = 0;
if (zot(z)) z = 0;
if (zot(r)) r = 0;
if (zot(q)) q = 0;
if (zot(s)) s = 0;
if (zot(r)) r = 0;
if (zot(t)) t = 0;
if (zot(s)) s = 0;
if (zot(u)) u = 0;
if (zot(t)) t = 0;
if (zot(v)) v = 0;
if (zot(u)) u = 0;
if (zot(w)) w = 0;
if (zot(v)) v = 0;
this.x = x;
if (zot(w)) w = 0;
this.y = y;
this.createjsPoint_constructor(x,y);
this.z = z;
this.type = "Point";
this.q = q;
this.x = x;
this.r = r;
this.y = y;
this.s = s;
this.z = z;
this.t = t;
this.q = q;
this.u = u;
this.r = r;
this.v = v;
this.s = s;
this.w = w;
this.t = t;
};
this.u = u;
this.v = v;
this.w = w;
this.angle = function(point) {
return this.createjsPoint_angle(point)*180/Math.PI;
}
this.project = function(angle, length) {
return this.createjsPoint_project(angle*Math.PI/180, length);
}
};
zim.extend(zim.Point, createjs.Point, ["angle","project"], "createjsPoint");
}


zim.Boundary = function(x, y, width, height) {
zim.Boundary = function(x, y, width, height) {
if (!zot(x.x)) { // a rectangle or getBounds() is provided
height = x.height;
width = x.width;
y = x.y;
x = x.x;
}
if (zot(x) || zot(y) || zot(width) || zot(height)) return;
if (zot(x) || zot(y) || zot(width) || zot(height)) return;
this.x = x;
this.x = x;
this.y = y;
this.y = y;
this.width = width;
this.width = width;
this.height = height;
this.height = height;

this.contract = function(a,b,c,d) {
this.contract = function(a,b,c,d) {
if (zot(a)) return this;
if (zot(a)) return this;
if (zot(b)) b = a;
if (zot(b)) b = a;
if (zot(c)) {
if (zot(c)) {
c = a*2;
c = a*2;
} else {
} else {
c = c+a;
c = c+a;
}
}
if (zot(d)) {
if (zot(d)) {
d = b*2;
d = b*2;
} else {
} else {
d = d+b;
d = d+b;
}
}
this.x += a;
this.x += a;
this.y += b;
this.y += b;
this.width -= c;
this.width -= c;
this.height -= d;
this.height -= d;
return this;
return this;
};
};
};
};


zim.RadialColor = function(colors,ratios, x0,y0,r0, x1,y1,r1) {
zim.RadialColor = function(colors,ratios, x0,y0,r0, x1,y1,r1) {
this.type = "RadialColor";
this.type = "RadialColor";
this.colors = zot(colors)?["black","white"]:colors;
this.colors = zot(colors)?["black","white"]:colors;
this.ratios = zot(ratios)?[0,1]:ratios;
if (!Array.isArray(this.colors)) this.colors = [this.colors, this.colors];
this.x0 = zot(x0)?0:x0;
if (this.colors.length==1) this.colors.push(this.colors[0]); // at least two colors
this.y0 = zot(y0)?0:y0;
this.ratios = ratios;
this.r0 = zot(r0)?0:r0;
if (!Array.isArray(this.ratios)) {
this.x1 = zot(x1)?0:x1;
this.ratios = [];
this.y1 = zot(y1)?100:y1;
for (var i=0; i<this.colors.length; i++) {
this.r1 = zot(r1)?100:r1;
this.ratios.push(i/(this.colors.length-1))
}
}
this.x0 = x0;
this.y0 = y0;
this.r0 = r0;
this.x1 = x1;
this.y1 = y1;
this.r1 = r1;
};
};


zim.Bezier = function Bezier(a, b, c, d) {
zim.Bezier = function Bezier(a, b, c, d) {
this.a = a;
this.a = a;
this.b = b;
this.b = b;
this.c = c;
this.c = c;
this.d = d;
this.d = d;


this.len = 100;
this.len = 100;
this.arcLengths = new Array(this.len + 1);
this.arcLengths = new Array(this.len + 1);
this.arcLengths[0] = 0;
this.arcLengths[0] = 0;


var ox = this.x(0), oy = this.y(0), clen = 0;
var ox = this.x(0), oy = this.y(0), clen = 0;
for(var i = 1; i <= this.len; i += 1) {
for(var i = 1; i <= this.len; i += 1) {
var x = this.x(i * 0.01), y = this.y(i * 0.01);
var x = this.x(i * 0.01), y = this.y(i * 0.01);
var dx = ox - x, dy = oy - y;
var dx = ox - x, dy = oy - y;
clen += Math.sqrt(dx * dx + dy * dy);
clen += Math.sqrt(dx * dx + dy * dy);
this.arcLengths[i] = clen;
this.arcLengths[i] = clen;
ox = x, oy = y;
ox = x, oy = y;
}
}
this.length = clen;
this.length = clen;
};
};


zim.Bezier.prototype = {
zim.Bezier.prototype = {
map: function(u) {
map: function(u) {
var targetLength = u * this.arcLengths[this.len];
var targetLength = u * this.arcLengths[this.len];
var low = 0, high = this.len, index = 0;
var low = 0, high = this.len, index = 0;
while (low < high) {
while (low < high) {
index = low + (((high - low) / 2) | 0);
index = low + (((high - low) / 2) | 0);
if (this.arcLengths[index] < targetLength) {
if (this.arcLengths[index] < targetLength) {
low = index + 1;
low = index + 1;


} else {
} else {
high = index;
high = index;
}
}
}
}
if (this.arcLengths[index] > targetLength) {
if (this.arcLengths[index] > targetLength) {
index--;
index--;
}
}


var lengthBefore = this.arcLengths[index];
var lengthBefore = this.arcLengths[index];
if (lengthBefore === targetLength) {
if (lengthBefore === targetLength) {
return index / this.len;
return index / this.len;


} else {
} else {
return (index + (targetLength - lengthBefore) / (this.arcLengths[index + 1] - lengthBefore)) / this.len;
return (index + (targetLength - lengthBefore) / (this.arcLengths[index + 1] - lengthBefore)) / this.len;
}
},

mx: function (u) {
return this.x(this.map(u));
},

my: function (u) {
return this.y(this.map(u));
},

x: function (t) {
return ((1 - t) * (1 - t) * (1 - t)) * this.a.x
+ 3 * ((1 - t) * (1 - t)) * t * this.b.x
+ 3 * (1 - t) * (t * t) * this.c.x
+ (t * t * t) * this.d.x;
},

y: function (t) {
return ((1 - t) * (1 - t) * (1 - t)) * this.a.y
+ 3 * ((1 - t) * (1 - t)) * t * this.b.y
+ 3 * (1 - t) * (t * t) * this.c.y
+ (t * t * t) * this.d.y;
}
};

zim.makeID = function(type, length, letterCase) {
if (zot(type)) type = "mixed";
if (zot(length)) length = 5;
if (zot(letterCase)) letterCase = "uppercase";
var choices;
var nums = [2,3,4,5,6,7,8,9];
var lets = "abcdefghjkmnpqrstuvwxyz".split("");
if (type.constructor === Array) {
choices = type;
} else if (type == "numbers") {
choices = nums;
} else if (type == "letters") {
choices = lets;
} else {
choices = nums.concat(lets);
}
var id = "";
var c; // character - note, char is a reserved word for compressor!
var rand;
for (var i=0; i<length; i++) {
c = choices[Math.floor(Math.random()*choices.length)];
rand = Math.random();
if (letterCase == "uppercase" || (letterCase == "mixed" && rand > .5)) {
if (c.toUpperCase) c = c.toUpperCase();
} else {
if (c.toLowerCase) c = c.toLowerCase();
}
id += String(c);
}
return id;
};

zim.series = function() {
var array;
var range;
if (arguments.length == 0) return function(){};
if (arguments.length == 1 && Array.isArray(arguments[0])) {
array = arguments[0];
} el