-
Notifications
You must be signed in to change notification settings - Fork 0
/
jPacker.min.js
6 lines (6 loc) · 3.79 KB
/
jPacker.min.js
1
2
3
4
5
6
var e=null,f=f||{},i=e,j=e,k=e,l=0,m=e,n=e,o=e;window.mainInit=function(){window.r=function(){return window.r||window.N||window.K||window.M||window.L||function(a){window.setTimeout(a,1E3/60)}}();j=document.getElementById("renderCanvas");k=j.getContext("2d");m=document.getElementsByTagName("title")[0];i=new p.q;n=new q;o=new p.j;i.b.push(o);window.r(s)};function s(a){var b=a-l;l=a;m.innerHTML="jPacker - pack ur rects";i.n(b);k.save();k.setTransform(1,0,0,1,0,0);k.clearRect(0,0,j.width,j.height);k.restore();i.m(n,b);window.r(s)}
window.GetPacked=function(){if(o!=e){var a=o,a=new t(a.D+a.C,a.u.bind(a));a.c.send(a.B)}};function t(a,b){var d,b=b||e;d=d||"text";this.c=new XMLHttpRequest;this.B=e;this.c.open("GET",a,!0);this.c.responseType=d;var c=this;this.c.onreadystatechange=function(){4===c.c.readyState&&(200===c.c.status?b!==e&&b(c.c.response,c.c.responseType):console.log("XMLHttpReq Error: ",c.c.statusText))}};var u="#DEADFA,#C0C0C0,#808080,#BADF00,#BF0000,#800000,#BFBF00,#808000,#00FF00,#008000,#00BFBF,#008080,#0000BF,#000080,#BF00BF,#800080".split(",");function v(a,b,d,c,g,h){h=h||u[Math.floor(Math.random()*u.length)];this.id=g||-1;this.x=a||0;this.y=b||0;this.f=d||0;this.e=c||0;this.color=h}function w(a){var b,d,c;b=b||1;d=d||0;c=c||0;var g=[];g.push({x:d+b*a.x,y:c+b*a.y});g.push({x:d+b*(a.x+a.f),y:c+b*a.y});g.push({x:d+b*(a.x+a.f),y:c+b*(a.y+a.e)});g.push({x:d+b*a.x,y:c+b*(a.y+a.e)});return g};function q(){var a=j;this.G=a;this.a=a.getContext("2d");this.J=a.width;this.I=a.height;this.a.font="16px sans-serif"}function x(a,b,d,c,g){var h;h=h||"16px sans-serif";g=g||"#000000";a.a.save();a.a.fillStyle=g;a.a.font=h;a.a.fillText(b,d,c);a.a.restore()}
function y(a,b,d,c){var g,d=d||e;g=1;var c=c||e,h=b.length;if(!(2>h)){a.a.save();a.a.lineWidth=g;a.a.strokeStyle=d;a.a.beginPath();a.a.moveTo(b[0].x,b[0].y);for(d=1;d<h;++d)g=b[d],a.a.lineTo(g.x,g.y);a.a.closePath();if(c!=e)a.a.fillStyle=c,a.a.fill();a.a.stroke();a.a.restore()}};var p=p||{};p.p={SUSPEND_LOWER:0,RUN_LOWER:1};p.i=function(a){this.t=a=a||p.p.s;this.A=f.F;this.v=!1};p.i.prototype.o=function(){this.A=e};p.i.prototype.n=function(){};p.i.prototype.m=function(){};p=p||{};p.q=function(){this.b=[]};p.q.prototype.n=function(a){for(var b=this.b.length-1;0<=b;--b){var d=this.b[b];d.n(a);if(!0===(d.t===p.p.s))break}a=this.b.length;b=-1;for(d=0;d<a;++d){var c=this.b[d];if(c.v){b=d;break}}if(-1!==b){for(d=a-1;d>=b;--d)c=this.b[d],c.o();this.b.splice(b,a-b)}};p.q.prototype.m=function(a,b){for(var d=this.b.length-1;0<=d;--d){var c=this.b[d];c.m(a,b);if(!0===(c.t===p.p.s))break}};p=p||{};p.j=function(){p.i.call(this);this.z=(new Date).getTime();this.d=10;this.D="http://www.versa-tech.net:3000/";this.C="random";this.k=e;this.l=[];this.g=e};p.j.prototype=new p.i;p.j.prototype.o=function(){console.log("jPackerRunState["+this.z+"]: OnRelease");this.k=e;this.l.length=0;this.H=e;p.i.prototype.o.call(this)};
p.j.prototype.u=function(a){this.k=JSON.parse(a);a=this.k.shift();this.g=new v(a.x,a.y,a.w,a.h,a.id,a.color);for(a=this.l.length=0;a<this.k.length;++a){var b=this.k[a];this.l.push(new v(b.x,b.y,b.w,b.h,b.id,b.color))}};p.j.prototype.n=function(){};
p.j.prototype.m=function(a){var b=j.width,d=j.height,c;c="#000000";a.a.save();a.a.fillStyle=c;a.a.fillRect(0,0,b,d);a.a.restore();x(a,"-- jPacker --",800,30,"#00FF00");for(b=d=b=0;b<this.l.length;++b)c=this.l[b],d+=c.f*c.e,y(a,w(c),"#000000",c.color),x(a,"["+b+"] w: "+c.f/this.d+" h: "+c.e/this.d+" a: "+c.f*c.e/(this.d*this.d),800,50+20*b,"#00FF00"),x(a,""+b,Math.floor(c.x+c.f/2),Math.floor(c.y+c.e/2),"#FFFFFF");this.g!=e&&(y(a,w(this.g),"#FFFFFF"),c=this.g.f*this.g.e,x(a,"-- packed box --",800,50+
20*b,"#FFFFFF"),++b,x(a,"w: "+this.g.f/this.d+" h: "+this.g.e/this.d+" a: "+c/(this.d*this.d),800,50+20*b,"#FFFFFF"),++b,x(a,"space efficiency: ",800,50+20*b,"#FF00FF"),++b,x(a,""+(100*(d/c)).toFixed(2)+"%",800,50+20*b,"#FF00FF"))};