Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: vtron/PixelJS
base: a74f5ac73f
...
head fork: vtron/PixelJS
compare: 1a00de6436
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 22 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -1,2 +1,3 @@
.DS_STORE
.idea/
+Src/TODO
View
92 Build/Pixel.js
@@ -1,38 +1,54 @@
-if(!Pixel){var Pixel={};if(!px)var px=Pixel}
-Pixel.App=new Class({Extends:Pixel.Canvas,Implements:Events,bSetup:!1,bRunning:!0,bIsMobileApp:!1,fps:60,curFPS:0,bShowFPS:!1,nFPSSamples:50,fpsSamples:[],curFpsSample:-1,curFps:0,startTime:0,prevTime:0,initialize:function(){this.parent(Pixel.RENDER_MODE_2D);this.prevTime=this.startTime=(new Date).getTime();$(document.body).addEvent("touchstart",this.touchStartListener.bind(this));$(document.body).addEvent("touchmove",this.touchMovedListener.bind(this));$(document.body).addEvent("touchend",this.touchEndListener.bind(this));
-TWEEN.start()},start:function(){this.bRunning=!0},stop:function(){this.bRunning=!1},run:function(){if(this.bRunning){if(this.setup!=void 0&&this.bSetup==!1)this.setup(),this.bSetup=!0;this.update();this.draw();this.bShowFPS&&(this.updateFPS(),this.drawFPS());window.requestAnimFrame(this.run.bind(this))}},setFramerate:function(a){this.fps=a},getFPS:function(){return this.fps},showFPS:function(){for(var a=0;a<this.fpsSamples.length;a++)this.fpsSamples[a]=0;this.bShowFPS=!0},hideFPS:function(){this.bShowFPS=
-!1},updateFPS:function(){this.curFpsSample++;if(this.curFpsSample>=this.nFPSSamples)this.curFpsSample=0;var a=this.getElapsedTime();this.fpsSamples[this.curFpsSample]=1E3/(a-this.prevTime);for(var c=0,d=0;d<this.fpsSamples.length;d++)c+=this.fpsSamples[d];c/=this.fpsSamples.length;this.curFps=Math.floor(c);this.prevTime=a},drawFPS:function(){this.setFont("Verdana",10);this.setColor(0,0,0);this.drawText("FPS: "+this.curFps.toFixed(2),20,20);this.setColor(255,255,2550);this.drawText("FPS: "+this.curFps.toFixed(2),
-22,22)},getElapsedTime:function(){return(new Date).getTime()-this.startTime},touches:[],touchStartListener:function(a){if(this.touchStart!=void 0)for(var c=0;c<a.changedTouches.length;c++){for(var d=null,e=0;e<this.touches.length;e++)if(this.touches[e]==null){d=e;break}if(d==null)d=this.touches.length;this.touches[d]={id:e,pos:{x:(!this.bPixelDoubling?a.changedTouches[c].pageX:a.changedTouches[c].pageX/2)-this.pos.x,y:(!this.bPixelDoubling?a.changedTouches[c].pageY:a.changedTouches[c].pageY/2)-this.pos.y},
-uniqueID:a.changedTouches[c].identifier};this.touchStart(this.touches[d])}},touchMovedListener:function(a){for(var c=0;c<a.changedTouches.length;c++)for(var d=a.changedTouches[c].identifier,e=0;e<this.touches.length;e++)if(this.touches[e]!=null&&d==this.touches[e].uniqueID){this.touches[e].pos={x:(!this.bPixelDoubling?a.changedTouches[c].pageX:a.changedTouches[c].pageX/2)-this.pos.x,y:(!this.bPixelDoubling?a.changedTouches[c].pageY:a.changedTouches[c].pageY/2)-this.pos.y};this.touchMoved(this.touches[e]);
-break}},touchEndListener:function(a){for(var c=0;c<a.changedTouches.length;c++)for(var d=a.changedTouches[c].identifier,e=0;e<this.touches.length;e++)if(this.touches[e]!=null&&d==this.touches[e].uniqueID){this.touchEnd(this.touches[e]);this.touches[e]=null;break}}});Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Canvas=new Class({Implements:Pixel.Renderer,element:null,pos:{x:0,y:0},width:0,height:0,bPixelDoubling:window.devicePixelRatio>=2,initialize:function(a){this.element=new Element("canvas",{width:this.width,height:this.height,styles:{position:"absolute",top:"0px",left:"0px","-webkit-transform-origin":"0 0 0"}});this.setPos(0,0);this.setSize(50,50);this.setRenderer(this.element,a)},setPos:function(a,c){this.pos.x=a;this.pos.y=c;var d="",d="scale3d("+window.devicePixelRatio+","+window.devicePixelRatio+
-",0) ";d+="translate3d("+this.pos.x+"px, "+this.pos.y+"px,0px)";this.element.setStyle("-webkit-transform",d)},setSize:function(a,c,d){this.width=a;this.height=c;this.element.set({width:this.width,height:this.height});d!=void 0&&this.setRenderer(d)},getWidth:function(){return this.width},getHeight:function(){return this.height}});Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Color=new Class({r:0,g:0,b:0,a:0,h:0,s:0,l:0,v:0,initialize:function(a,c,d,e){this.set(a,c,d,e)},set:function(a,c,d,e){if(a)this.r=a;if(c)this.g=c;if(d)this.b=d;if(e)this.a=e},setHSL:function(a,c,d,e){if(a)this.h=a;if(c)this.s=g;if(d)this.l=b;if(e)this.a=e},setHSV:function(a,c,d,e){if(a)this.h=a;if(c)this.s=g;if(d)this.l=b;if(e)this.a=e},toHSL:function(){var a=Pixel.rgbToHSL(this.r,this.g,this.b);this.setHSL(a.h,a.s,a.l);return a},toHSV:function(){var a=Pixel.rgbToHSV(this.r,this.g,this.b);
-this.setHSV(a.h,a.s,a.v);return a}});Pixel.rgbToHsl=function(a,c,d){a/=255;c/=255;d/=255;var e=Math.max(a,c,d),f=Math.min(a,c,d),h,i=(e+f)/2;if(e==f)h=f=0;else{var j=e-f,f=i>0.5?j/(2-e-f):j/(e+f);switch(e){case a:h=(c-d)/j+(c<d?6:0);break;case c:h=(d-a)/j+2;break;case d:h=(a-c)/j+4}h/=6}return{h:h,s:f,l:i}};
-Pixel.hslToRgb=function(a,c,d){a=Pixel.map(a,0,360,0,1);c=Pixel.map(c,0,255,0,1);d=Pixel.map(d,0,255,0,1);if(c==0)d=c=a=d;else var e=function(a,c,d){d<0&&(d+=1);d>1&&(d-=1);return d<1/6?a+(c-a)*6*d:d<0.5?c:d<2/3?a+(c-a)*(2/3-d)*6:a},f=d<0.5?d*(1+c):d+c-d*c,h=2*d-f,d=e(h,f,a+1/3),c=e(h,f,a),a=e(h,f,a-1/3);return{r:d*255,g:c*255,b:a*255}};
-Pixel.rgbToHsv=function(a,c,d){a/=255;c/=255;d/=255;var e=Math.max(a,c,d),f=Math.min(a,c,d),h,i=e-f;if(e==f)h=0;else{switch(e){case a:h=(c-d)/i+(c<d?6:0);break;case c:h=(d-a)/i+2;break;case d:h=(a-c)/i+4}h/=6}return{h:h,s:e==0?0:i/e,v:e}};
-Pixel.hsvToRgb=function(a,c,d){var a=Pixel.map(a,0,360,0,1),c=Pixel.map(c,0,255,0,1),d=Pixel.map(d,0,255,0,1),e,f,h,i=Math.floor(a*6),j=a*6-i,a=d*(1-c),k=d*(1-j*c),c=d*(1-(1-j)*c);switch(i%6){case 0:e=d;f=c;h=a;break;case 1:e=k;f=d;h=a;break;case 2:e=a;f=d;h=c;break;case 3:e=a;f=k;h=d;break;case 4:e=c;f=a;h=d;break;case 5:e=d,f=a,h=k}return{r:e*255,g:f*255,b:h*255}};Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Font=new Class({ctx:null,text:"",font:"Arial",size:50,alignment:Pixel.TEXT_ALIGN_LEFT,baseline:Pixel.TEXT_BASELINE_TOP,initialize:function(a,c,d){if(Pixel.isSet(a))this.font=a;if(Pixel.isSet(c))this.size=c;if(Pixel.isSet(d))this.alignment=d},setSize:function(a){this.size=a},setFont:function(a){this.font=a},setAlignment:function(a){this.alignment=a},setBaseline:function(a){this.baseline=a},setText:function(a){this.text=a},getSize:function(){return this.size}});Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Image=new Class({Extends:Pixel.Object,image:null,canvas:null,ctx:null,imageData:null,pixels:null,bAllocated:!1,bLoaded:!1,size:{width:0,height:0},initialize:function(a){a!=void 0&&this.load(a)},load:function(a){this.clear();this.image=new Asset.image(a,{onLoad:function(){this.bLoaded=!0;this.setSize(this.image.width,this.image.height)}.bind(this),onError:function(){console.log("Could not load image from '"+a+"'")}})},isLoaded:function(){return this.bLoaded},clear:function(){this.bLoaded=!1;
-this.image=this.imageData=this.pixels=null},setSize:function(a,c){this.parent(a,c);if(this.bAllocated==!1)this.canvas=new Element("canvas"),this.ctx=this.canvas.getContext("2d"),this.imageData=this.ctx.getImageData(0,0,this.getWidth(),this.getHeight());this.canvas.set({width:this.size.width,height:this.size.height})},getImageData:function(){return this.imageData},getPixels:function(){return this.bLoaded?(this.ctx.drawImage(this.image,0,0),this.imageData=this.ctx.getImageData(0,0,this.size.width,this.size.height),
-this.pixels=this.imageData.data):null},setFromPixels:function(a,c,d){this.clear();this.setSize(c,d);this.imageData=this.ctx.getImageData(0,0,this.size.width,this.size.height);this.pixels=this.imageData.data;for(c=a.length;c--;)this.pixels[c]=a[c];this.ctx.putImageData(this.imageData,0,0);this.image=new Element("img");this.image.addEvent("load",function(){this.image.removeEvent("load");this.bLoaded=!0}.bind(this));this.image.src=this.canvas.toDataURL("image/png")},draw:function(a,c,d){a.drawImage(this,
-c,d)}});Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Object=new Class({bInitPressed:!1,bPressed:!1,pos:{x:0,y:0},width:0,height:0,radius:0,shapeMode:Pixel.OBJECT_SHAPE_RECT,tween:null,rect:new Pixel.Rectangle,initialize:function(){},show:function(){},hide:function(){},setPos:function(a,c){if(Pixel.isSet(a))this.pos.x=a;if(Pixel.isSet(c))this.pos.y=c},getPos:function(){return this.pos},setSize:function(a,c){if(Pixel.isSet(a))this.width=a;if(Pixel.isSet(c))this.height=c},getWidth:function(){return this.width},getHeight:function(){return this.height},
-setShapeMode:function(a){this.shapeMode=a},isPressed:function(){return this.bPressed},touchStart:function(a){this.rect.set(this.pos.x,this.pos.y,this.width,this.height);switch(this.shapeMode){case Pixel.OBJECT_SHAPE_RECT:this.bInitPressed=this.rect.isInside(a.pos.x,a.pos.y);break;case Pixel.OBJECT_SHAPE_CIRCLE:this.bInitPressed=Pixel.dist(this.pos.x,this.pos.y,a.pos.x,a.pos.y)<this.radius*2}this.bPressed=this.bInitPressed},touchMoved:function(){if(this.bInitPressed)switch(this.shapeMode){case Pixel.OBJECT_SHAPE_RECT:this.bPressed=
-this.rect.isInside(touch.pos.x,touch.pos.y);break;case Pixel.OBJECT_SHAPE_CIRCLE:this.bPressed=Pixel.dist(this.pos.x,this.post.y,touch.pos.x,touch.pos.y)<this.radius*2}},touchEnd:function(){this.bInitPressed=this.bPressed=!1}});Pixel||(Pixel={},px||(px=Pixel));Pixel.Spritesheet=new Class({sheet:null,initialize:function(){sheet=new Pixel.Image},load:function(a){sheet.load(a)}});Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Renderer=new Class({renderer:null,setRenderer:function(a,c){switch(c){case Pixel.RENDER_MODE_2D:this.renderer=new Pixel.Renderer2D(a);break;case Pixel.RENDER_MODE_WEBGL:Pixel.log("WebGL Renderer not yet implemented!");break;default:Pixel.log("Renderer Type does not exist")}},clear:function(a,c,d,e){this.renderer.clear(a,c,d,e)},setColor:function(a,c,d,e){this.renderer.setColor(a,c,d,e)},fill:function(){this.renderer.fill()},noFill:function(){this.renderer.noFill()},stroke:function(a){this.renderer.stroke(a)},
-noStroke:function(){this.renderer.noStroke()},drawImage:function(a,c,d){this.renderer.drawImage(a,c,d)},beginShape:function(a,c){this.renderer.beginShape(a,c)},addVertex:function(a,c,d){this.renderer.addVertex(a,c,d)},endShape:function(a,c){this.renderer.endShape(a,c)},drawLine:function(a,c,d,e){this.renderer.drawLine(a,c,d,e)},drawRect:function(a,c,d,e){this.renderer.drawRect(a,c,d,e)},drawSquare:function(a,c,d){this.renderer.drawSquare(a,c,d)},drawEllipse:function(){this.renderer.drawEllipse()},
-drawCircle:function(a,c,d){this.renderer.drawCircle(a,c,d)},pushMatrix:function(){this.renderer.pushMatrix()},popMatrix:function(){this.renderer.popMatrix()},translate:function(a,c){this.renderer.translate(a,c)},scale:function(a,c){this.renderer.scale(a,c)},rotate:function(a){this.renderer.rotate(a)},transform:function(a,c,d,e,f,h){this.renderer.transform(a,c,d,e,f,h)},setTransform:function(a,c,d,e,f,h){this.renderer.setTransform(a,c,d,e,f,h)},setFont:function(a,c){this.renderer.setFont(a,c)},setTextAlignment:function(a){this.renderer.setTextAlignment(a)},
-setTextBaseline:function(a){this.renderer.setTextBaseline(a)},getStringWidth:function(a){return this.renderer.getStringWidth(a)},drawText:function(a,c,d){this.renderer.drawText(a,c,d)}});Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Renderer2D=new Class({ctx:null,bFill:!0,bStroke:!1,initialize:function(a){this.ctx=a.getContext("2d")},clear:function(a,c,d,e){this.ctx.clearRect(a,c,d,e)},setColor:function(a,c,d,e){a=Math.round(a);c=Math.round(c);d=Math.round(d);c==void 0?(this.ctx.fillStyle="rgb("+a+","+a+","+a+")",this.ctx.strokeStyle="rgb("+a+","+a+","+a+")"):e==void 0?(this.ctx.fillStyle="rgb("+a+","+c+","+d+")",this.ctx.strokeStyle="rgb("+a+","+c+","+d+")"):(this.ctx.fillStyle="rgba("+a+","+c+","+d+","+e+")",this.ctx.strokeStyle=
-"rgba("+a+","+c+","+d+","+e+")")},fill:function(){this.bFill=!0},noFill:function(){this.bFill=!1},stroke:function(a){this.bStroke=!0;this.ctx.lineWidth=a},noStroke:function(){this.bStroke=!1},drawImage:function(a,c,d){a.isLoaded()&&(c!=void 0&&d!=void 0?this.ctx.drawImage(a.image,c,d):this.ctx.drawImage(a.image,a.getPos().x,a.getPos().y))},beginShape:function(a,c){this.ctx.beginPath();this.ctx.moveTo(a,c)},addVertex:function(a,c,d){this.ctx.lineTo(a,c);d!=void 0&&this.endShape()},endShape:function(){this.ctx.closePath();
-this.ctx.fill()},drawLine:function(a,c,d,e){this.ctx.beginPath();this.ctx.moveTo(a,c);this.ctx.lineTo(d,e);this.ctx.stroke()},drawRect:function(a,c,d,e){this.bFill&&this.ctx.fillRect(a,c,d,e);this.bStroke&&this.ctx.strokeRect(a,c,d,e)},drawSquare:function(a,c,d){this.rectangle(a,c,d,d)},drawEllipse:function(a,c,d,e){ox=d/2*0.5522848;oy=e/2*0.5522848;xe=a+d;ye=c+e;xm=a+d/2;ym=c+e/2;this.ctx.beginPath();this.ctx.moveTo(a,ym);this.ctx.bezierCurveTo(a,ym-oy,xm-ox,c,xm,c);this.ctx.bezierCurveTo(xm+ox,
-c,xe,ym-oy,xe,ym);this.ctx.bezierCurveTo(xe,ym+oy,xm+ox,ye,xm,ye);this.ctx.bezierCurveTo(xm-ox,ye,a,ym+oy,a,ym);this.ctx.closePath();this.bStroke&&this.ctx.stroke();this.bFill&&this.ctx.fill()},drawCircle:function(a,c,d){this.ctx.beginPath();this.ctx.arc(a,c,d,0,Math.PI*2,!1);this.bStroke&&this.ctx.stroke();this.bFill&&this.ctx.fill()},pushMatrix:function(){this.ctx.save()},popMatrix:function(){this.ctx.restore()},translate:function(a,c){this.ctx.translate(a,c)},scale:function(a,c){this.ctx.scale(a,
-c)},rotate:function(a){this.ctx.rotate(a)},transform:function(a,c,d,e,f,h){this.ctx.transform(a,c,d,e,f,h)},setTransform:function(a,c,d,e,f,h){this.ctx.setTransform(a,c,d,e,f,h)},setFont:function(a,c){c==void 0?this.setFont(a.font,a.size):this.ctx.font=c+"pt "+a;this.setTextAlignment(a.alignment);this.setTextBaseline(a.baseline)},setTextAlignment:function(a){this.ctx.textAlign=a},setTextBaseline:function(a){this.ctx.textBaseline=a},bLogged:!1,getStringWidth:function(a){return this.ctx.measureText(a).width},
-drawText:function(a,c,d){this.ctx.fillText(a,c,d)}});Pixel||(Pixel={},px||(px=Pixel));Pixel.RENDER_MODE_2D=0;Pixel.RENDER_MODE_WEBGL=1;Pixel.TEXT_ALIGN_LEFT="left";Pixel.TEXT_ALIGN_CENTER="center";Pixel.TEXT_ALIGN_RIGHT="right";Pixel.TEXT_BASELINE_TOP="top";Pixel.TEXT_BASELINE_HANGING="hanging";Pixel.TEXT_BASELINE_MIDDLE="middle";Pixel.TEXT_BASELINE_BOTTOM="bottom";Pixel.OBJECT_SHAPE_RECT=0;Pixel.OBJECT_SHAPE_CIRCLE=1;Pixel.ORIGIN_TOP_LEFT=0;Pixel.ORIGIN_CENTER_LEFT=1;Pixel.ORIGIN_BOTTOM_LEFT=2;
-Pixel.ORIGIN_TOP_RIGHT=3;Pixel.ORIGIN_CENTER_RIGHT=4;Pixel.ORIGIN_BOTTOM_RIGHT=5;Pixel.ORIGIN_TOP_CENTER=6;Pixel.ORIGIN_BOTTOM_CENTER=7;Pixel.ORIGIN_CENTER=8;Pixel.NO_EASE=TWEEN.Easing.Linear.EaseNone;Pixel.EASE_IN_QUAD=TWEEN.Easing.Quadratic.EaseIn;Pixel.EASE_OUT_QUAD=TWEEN.Easing.Quadratic.EaseOut;Pixel.EASE_IN_OUT_QUAD=TWEEN.Easing.Quadratic.EaseInOut;Pixel.EASE_IN_CUBE=TWEEN.Easing.Cubic.EaseIn;Pixel.EASE_OUT_CUBE=TWEEN.Easing.Cubic.EaseOut;Pixel.EASE_IN_OUT_CUBE=TWEEN.Easing.Cubic.EaseInOut;
-Pixel.EASE_IN_QUART=TWEEN.Easing.Quartic.EaseIn;Pixel.EASE_OUT_QUART=TWEEN.Easing.Quartic.EaseOut;Pixel.EASE_IN_OUT_QUART=TWEEN.Easing.Quartic.EaseInOut;Pixel.EASE_IN_QUINT=TWEEN.Easing.Quintic.EaseIn;Pixel.EASE_OUT_QUINT=TWEEN.Easing.Quintic.EaseOut;Pixel.EASE_IN_OUT_QUINT=TWEEN.Easing.Quintic.EaseInOut;Pixel.EASE_IN_SIN=TWEEN.Easing.Sinusoidal.EaseIn;Pixel.EASE_OUT_SIN=TWEEN.Easing.Sinusoidal.EaseOut;Pixel.EASE_IN_OUT_SIN=TWEEN.Easing.Sinusoidal.EaseInOut;Pixel.EASE_IN_EXPO=TWEEN.Easing.Exponential.EaseIn;
-Pixel.EASE_OUT_EXPO=TWEEN.Easing.Exponential.EaseOut;Pixel.EASE_IN_OUT_EXPO=TWEEN.Easing.Exponential.EaseInOut;Pixel.EASE_IN_CIRC=TWEEN.Easing.Circular.EaseIn;Pixel.EASE_OUT_CIRC=TWEEN.Easing.Circular.EaseOut;Pixel.EASE_IN_OUT_CIRC=TWEEN.Easing.Circular.EaseInOut;Pixel||(Pixel={},px||(px=Pixel));
-Pixel.Rectangle=new Class({x:0,y:0,width:0,height:0,initialize:function(a,c,d,e){this.set(a,c,d,e)},set:function(a,c,d,e){this.setPos(a,c);this.setSize(d,e)},setPos:function(a,c){if(Pixel.isSet(a))this.x=a;if(Pixel.isSet(c))this.y=c},setSize:function(a,c){if(Pixel.isSet(a))this.width=a;if(Pixel.isSet(c))this.height=c},getPos:function(){return{x:this.x,y:this.y}},getSize:function(){return{width:this.width,height:this.height}},isInside:function(a,c){return a>this.x&&a<this.x+this.width&&c>this.y&&c<
-this.y+this.height}});Pixel.radToDeg=function(a){return a*(180/Math.PI)};Pixel.degToRad=function(a){return a*(Math.PI/180)};Pixel.map=function(a,c,d,e,f,h){a=e+(f-e)*((a-c)/(d-c));return h?Pixel.clamp(a):a};Pixel.clamp=function(a,c,d){a=Math.max(a,c);return a=Math.min(a,d)};Pixel.dist=function(a,c,d,e,f){a=Math.sqrt(Math.pow(d-a,2)+Math.pow(e-c,2));return f?a:Math.abs(a)};Pixel.getAngle=function(a,c,d,e){return Math.atan2(e-c,d-a)};Pixel||(Pixel={},px||(px=Pixel));
-Pixel.isSet=function(a){return a!=void 0?a:!1};Pixel.log=function(a){console.log("Pixel: "+a)};window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();
+typeof Pixel=="undefined"?(Pixel={version:"0.5"},typeof px=="undefined"&&(px=Pixel)):console.log("Pixel Namespace Already Exists!");Pixel.BROWSER_TYPE_CHROME="chrome";Pixel.BROWSER_TYPE_SAFARI="safari";Pixel.BROWSER_TYPE_FIREFOX="firefox";Pixel.BROWSER_TYPE_IPHONE="iphone";Pixel.RENDER_MODE_2D=0;Pixel.RENDER_MODE_WEBGL=1;Pixel.TEXT_ALIGN_LEFT="left";Pixel.TEXT_ALIGN_CENTER="center";Pixel.TEXT_ALIGN_RIGHT="right";Pixel.TEXT_BASELINE_TOP="top";Pixel.TEXT_BASELINE_HANGING="hanging";
+Pixel.TEXT_BASELINE_MIDDLE="middle";Pixel.TEXT_BASELINE_BOTTOM="bottom";Pixel.OBJECT_SHAPE_RECT=0;Pixel.OBJECT_SHAPE_CIRCLE=1;Pixel.ORIGIN_TOP_LEFT=0;Pixel.ORIGIN_CENTER_LEFT=1;Pixel.ORIGIN_BOTTOM_LEFT=2;Pixel.ORIGIN_TOP_RIGHT=3;Pixel.ORIGIN_CENTER_RIGHT=4;Pixel.ORIGIN_BOTTOM_RIGHT=5;Pixel.ORIGIN_TOP_CENTER=6;Pixel.ORIGIN_BOTTOM_CENTER=7;Pixel.ORIGIN_CENTER=8;Pixel.isSet=function(a){return a!=void 0?a:!1};Pixel.log=function(a){console.log("PixelJS Log: "+a)};
+Pixel.isTouchDevice=function(){try{return document.createEvent("TouchEvent"),!0}catch(a){return!1}};window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();Pixel.Rectangle=function(a,c,d,e){this.height=this.width=this.y=this.x=0;this.set(a,c,d,e)};
+Pixel.Rectangle.prototype.initialize=function(a,c,d,e){this.set(a,c,d,e)};Pixel.Rectangle.prototype.set=function(a,c,d,e){this.setPos(a,c);this.setSize(d,e)};Pixel.Rectangle.prototype.setPos=function(a,c){if(Pixel.isSet(a))this.x=a;if(Pixel.isSet(c))this.y=c};Pixel.Rectangle.prototype.setSize=function(a,c){this.width=a;this.height=c};Pixel.Rectangle.prototype.getPos=function(){return{x:this.x,y:this.y}};Pixel.Rectangle.prototype.getSize=function(){return{width:this.width,height:this.height}};
+Pixel.Rectangle.prototype.isInside=function(a,c){return a>this.x&&a<this.x+this.width&&c>this.y&&c<this.y+this.height};Pixel.radToDeg=function(a){return a*(180/Math.PI)};Pixel.degToRad=function(a){return a*(Math.PI/180)};Pixel.map=function(a,c,d,e,h,f){a=e+(h-e)*((a-c)/(d-c));return f?Pixel.clamp(a):a};Pixel.clamp=function(a,c,d){a=Math.max(a,c);return a=Math.min(a,d)};Pixel.dist=function(a,c,d,e,h){a=Math.sqrt(Math.pow(d-a,2)+Math.pow(e-c,2));return h?a:Math.abs(a)};
+Pixel.getAngle=function(a,c,d,e){return Math.atan2(e-c,d-a)};Pixel.Renderer=function(){};Pixel.Renderer.prototype.setRenderer=function(a,c){switch(c){case Pixel.RENDER_MODE_2D:this.renderer=new Pixel.Renderer2D(a);break;case Pixel.RENDER_MODE_WEBGL:Pixel.log("WebGL Renderer not yet implemented!")}};Pixel.Renderer.prototype.clear=function(a,c,d,e){this.renderer.clear(a,c,d,e)};Pixel.Renderer.prototype.setColor=function(a,c,d,e){this.renderer.setColor(a,c,d,e)};Pixel.Renderer.prototype.useColor=function(a){this.renderer.useColor(a)};
+Pixel.Renderer.prototype.fill=function(){this.renderer.fill()};Pixel.Renderer.prototype.noFill=function(){this.renderer.noFill()};Pixel.Renderer.prototype.stroke=function(a){this.renderer.stroke(a)};Pixel.Renderer.prototype.noStroke=function(){this.renderer.noStroke()};Pixel.Renderer.prototype.drawImage=function(a,c,d){this.renderer.drawImage(a,c,d)};Pixel.Renderer.prototype.beginShape=function(a,c){this.renderer.beginShape(a,c)};
+Pixel.Renderer.prototype.addVertex=function(a,c,d){this.renderer.addVertex(a,c,d)};Pixel.Renderer.prototype.endShape=function(a,c){this.renderer.endShape(a,c)};Pixel.Renderer.prototype.drawLine=function(a,c,d,e){this.renderer.drawLine(a,c,d,e)};Pixel.Renderer.prototype.dashedLine=function(a,c,d,e,h){this.renderer.dashedLine(a,c,d,e,h)};Pixel.Renderer.prototype.drawRect=function(a,c,d,e){this.renderer.drawRect(a,c,d,e)};
+Pixel.Renderer.prototype.drawSquare=function(a,c,d){this.renderer.drawSquare(a,c,d)};Pixel.Renderer.prototype.drawEllipse=function(){this.renderer.drawEllipse()};Pixel.Renderer.prototype.drawCircle=function(a,c,d){this.renderer.drawCircle(a,c,d)};Pixel.Renderer.prototype.pushMatrix=function(){this.renderer.pushMatrix()};Pixel.Renderer.prototype.popMatrix=function(){this.renderer.popMatrix()};Pixel.Renderer.prototype.translate=function(a,c){this.renderer.translate(a,c)};
+Pixel.Renderer.prototype.scale=function(a,c){this.renderer.scale(a,c)};Pixel.Renderer.prototype.rotate=function(a){this.renderer.rotate(a)};Pixel.Renderer.prototype.transform=function(a,c,d,e,h,f){this.renderer.transform(a,c,d,e,h,f)};Pixel.Renderer.prototype.setTransform=function(a,c,d,e,h,f){this.renderer.setTransform(a,c,d,e,h,f)};Pixel.Renderer.prototype.setFont=function(a,c){this.renderer.setFont(a,c)};Pixel.Renderer.prototype.setTextAlignment=function(a){this.renderer.setTextAlignment(a)};
+Pixel.Renderer.prototype.setTextBaseline=function(a){this.renderer.setTextBaseline(a)};Pixel.Renderer.prototype.getTextWidth=function(a){return this.renderer.getTextWidth(a)};Pixel.Renderer.prototype.drawText=function(a,c,d){c!=void 0?this.renderer.drawText(a,c,d):this.renderer.drawText(a,this.cursorX,this.cursorY)};Pixel.Renderer.prototype.drawTextfield=function(a){this.renderer.drawTextfield(a)};Pixel.Renderer2D=function(a){this.ctx=a.getContext("2d");this.bFill=!0;this.bStroke=!1};
+Pixel.Renderer2D.prototype.clear=function(a,c,d,e){this.ctx.clearRect(a,c,d,e)};Pixel.Renderer2D.prototype.setColor=function(a,c,d,e){a=Math.round(a);c=Math.round(c);d=Math.round(d);c==void 0?(this.ctx.fillStyle="rgb("+a+","+a+","+a+")",this.ctx.strokeStyle="rgb("+a+","+a+","+a+")"):e==void 0?(this.ctx.fillStyle="rgb("+a+","+c+","+d+")",this.ctx.strokeStyle="rgb("+a+","+c+","+d+")"):(this.ctx.fillStyle="rgba("+a+","+c+","+d+","+e+")",this.ctx.strokeStyle="rgba("+a+","+c+","+d+","+e+")")};
+Pixel.Renderer2D.prototype.useColor=function(a){this.ctx.fillStyle="rgba("+a.r+","+a.g+","+a.b+","+a.a+")";this.ctx.strokeStyle="rgba("+a.r+","+a.g+","+a.b+","+a.a+")"};Pixel.Renderer2D.prototype.fill=function(){this.bFill=!0};Pixel.Renderer2D.prototype.noFill=function(){this.bFill=!1};Pixel.Renderer2D.prototype.stroke=function(a){this.bStroke=!0;this.ctx.lineWidth=a};Pixel.Renderer2D.prototype.noStroke=function(){this.bStroke=!1};
+Pixel.Renderer2D.prototype.drawImage=function(a,c,d){a.isLoaded()&&(c!=void 0&&d!=void 0?this.ctx.drawImage(a.image,c,d):this.ctx.drawImage(a.image,a.getPos().x,a.getPos().y))};Pixel.Renderer2D.prototype.beginShape=function(a,c){this.ctx.beginPath();this.ctx.moveTo(a,c)};Pixel.Renderer2D.prototype.addVertex=function(a,c,d){this.ctx.lineTo(a,c);d!=void 0&&this.endShape()};Pixel.Renderer2D.prototype.endShape=function(){this.ctx.closePath();this.ctx.fill()};
+Pixel.Renderer2D.prototype.drawLine=function(a,c,d,e){this.ctx.beginPath();this.ctx.moveTo(a,c);this.ctx.lineTo(d,e);this.ctx.stroke()};
+Pixel.Renderer2D.prototype.dashedLine=function(a,c,d,e,h){var f=function(a,c){return a<=c},i=function(a,c){return a>=c},j=function(a,c){return Math.min(a,c)},k=function(a,c){return Math.max(a,c)},l={thereYet:i,cap:j},i={thereYet:i,cap:j};if(c-e>0)i.thereYet=f,i.cap=k;if(a-d>0)l.thereYet=f,l.cap=k;this.ctx.moveTo(a,c);this.ctx.beginPath();for(var f=a,k=c,j=0,m=!0;!l.thereYet(f,d)||!i.thereYet(k,e);){var n=Math.atan2(e-c,d-a),o=h[j],f=l.cap(d,f+Math.cos(n)*o),k=i.cap(e,k+Math.sin(n)*o);m?this.ctx.lineTo(f,
+k):this.ctx.moveTo(f,k);this.ctx.stroke();j=(j+1)%h.length;m=!m}};Pixel.Renderer2D.prototype.drawRect=function(a,c,d,e){c!=void 0?(this.bFill&&this.ctx.fillRect(a,c,d,e),this.bStroke&&this.ctx.strokeRect(a,c,d,e)):(this.bFill&&this.ctx.fillRect(a.x,a.y,a.width,a.height),this.bStroke&&this.ctx.strokeRect(a.x,a.y,a.width,a.height))};Pixel.Renderer2D.prototype.drawSquare=function(a,c,d){this.rectangle(a,c,d,d)};
+Pixel.Renderer2D.prototype.drawEllipse=function(a,c,d,e){ox=d/2*0.5522848;oy=e/2*0.5522848;xe=a+d;ye=c+e;xm=a+d/2;ym=c+e/2;this.ctx.beginPath();this.ctx.moveTo(a,ym);this.ctx.bezierCurveTo(a,ym-oy,xm-ox,c,xm,c);this.ctx.bezierCurveTo(xm+ox,c,xe,ym-oy,xe,ym);this.ctx.bezierCurveTo(xe,ym+oy,xm+ox,ye,xm,ye);this.ctx.bezierCurveTo(xm-ox,ye,a,ym+oy,a,ym);this.ctx.closePath();this.bStroke&&this.ctx.stroke();this.bFill&&this.ctx.fill()};
+Pixel.Renderer2D.prototype.drawCircle=function(a,c,d){this.ctx.beginPath();this.ctx.arc(a,c,d,0,Math.PI*2,!1);this.bStroke&&this.ctx.stroke();this.bFill&&this.ctx.fill()};Pixel.Renderer2D.prototype.pushMatrix=function(){this.ctx.save()};Pixel.Renderer2D.prototype.popMatrix=function(){this.ctx.restore()};Pixel.Renderer2D.prototype.translate=function(a,c){this.ctx.translate(a,c)};Pixel.Renderer2D.prototype.scale=function(a,c){this.ctx.scale(a,c)};Pixel.Renderer2D.prototype.rotate=function(a){this.ctx.rotate(a)};
+Pixel.Renderer2D.prototype.transform=function(a,c,d,e,h,f){this.ctx.transform(a,c,d,e,h,f)};Pixel.Renderer2D.prototype.setTransform=function(a,c,d,e,h,f){this.ctx.setTransform(a,c,d,e,h,f)};Pixel.Renderer2D.prototype.setFont=function(a,c){c==void 0?this.setFont(a.font,a.size):this.ctx.font=c+"pt "+a;this.setTextAlignment(a.alignment);this.setTextBaseline(a.baseline)};Pixel.Renderer2D.prototype.setTextAlignment=function(a){this.ctx.textAlign=a};
+Pixel.Renderer2D.prototype.setTextBaseline=function(a){this.ctx.textBaseline=a};Pixel.Renderer2D.prototype.getTextWidth=function(a){return this.ctx.measureText(a).width};Pixel.Renderer2D.prototype.drawText=function(a,c,d){c!=void 0?this.ctx.fillText(a,c,d):(console.log("yea"),this.ctx.fillText(a,this.cursorX,this.cursorY))};Pixel.Renderer2D.prototype.drawTextfield=function(a){this.setFont(a.font);this.useColor(a.color);this.drawText(a.text,a.pos.x,a.pos.y)};
+Pixel.Color=function(){this.v=this.l=this.s=this.h=this.b=this.g=this.r=0};Pixel.Color.prototype.set=function(a,c,d,e){if(a!=void 0)this.r=a;if(c!=void 0)this.g=c;if(d!=void 0)this.b=d;this.a=e!=void 0?e:1};Pixel.Color.prototype.setHSL=function(a,c,d,e){if(a!=void 0)this.h=a;if(c!=void 0)this.s=g;if(d!=void 0)this.l=b;this.a=e!=void 0?e:1};Pixel.Color.prototype.setHSV=function(a,c,d,e){if(a!=void 0)this.h=a;if(c!=void 0)this.s=g;if(d!=void 0)this.l=b;if(e!=void 0)this.a=e};
+Pixel.Color.prototype.toHSL=function(){var a=Pixel.rgbToHSL(this.r,this.g,this.b);this.setHSL(a.h,a.s,a.l);return a};Pixel.Color.prototype.toHSV=function(){var a=Pixel.rgbToHSV(this.r,this.g,this.b);this.setHSV(a.h,a.s,a.v);return a};Pixel.rgbToHsl=function(a,c,d){a/=255;c/=255;d/=255;var e=Math.max(a,c,d),h=Math.min(a,c,d),f,i=(e+h)/2;if(e==h)f=h=0;else{var j=e-h,h=i>0.5?j/(2-e-h):j/(e+h);switch(e){case a:f=(c-d)/j+(c<d?6:0);break;case c:f=(d-a)/j+2;break;case d:f=(a-c)/j+4}f/=6}return{h:f,s:h,l:i}};
+Pixel.hslToRgb=function(a,c,d){a=Pixel.map(a,0,360,0,1);c=Pixel.map(c,0,255,0,1);d=Pixel.map(d,0,255,0,1);if(c==0)d=c=a=d;else var e=function(a,c,d){d<0&&(d+=1);d>1&&(d-=1);return d<1/6?a+(c-a)*6*d:d<0.5?c:d<2/3?a+(c-a)*(2/3-d)*6:a},h=d<0.5?d*(1+c):d+c-d*c,f=2*d-h,d=e(f,h,a+1/3),c=e(f,h,a),a=e(f,h,a-1/3);return{r:d*255,g:c*255,b:a*255}};
+Pixel.rgbToHsv=function(a,c,d){a/=255;c/=255;d/=255;var e=Math.max(a,c,d),h=Math.min(a,c,d),f,i=e-h;if(e==h)f=0;else{switch(e){case a:f=(c-d)/i+(c<d?6:0);break;case c:f=(d-a)/i+2;break;case d:f=(a-c)/i+4}f/=6}return{h:f,s:e==0?0:i/e,v:e}};
+Pixel.hsvToRgb=function(a,c,d){var a=Pixel.map(a,0,360,0,1),c=Pixel.map(c,0,255,0,1),d=Pixel.map(d,0,255,0,1),e,h,f,i=Math.floor(a*6),j=a*6-i,a=d*(1-c),k=d*(1-j*c),c=d*(1-(1-j)*c);switch(i%6){case 0:e=d;h=c;f=a;break;case 1:e=k;h=d;f=a;break;case 2:e=a;h=d;f=c;break;case 3:e=a;h=k;f=d;break;case 4:e=c;h=a;f=d;break;case 5:e=d,h=a,f=k}return{r:e*255,g:h*255,b:f*255}};
+Pixel.Canvas=function(a){Pixel.Renderer.call(this);this.canvas=document.createElement("canvas");this.canvas.innerHTML="Your browser does not support HTML5 Canvas.";this.canvas.setAttribute("width",this.width);this.canvas.setAttribute("height",this.height);this.canvas.style.position="absolute";this.canvas.style.top="0px";this.canvas.style.left="0px";this.canvas.webkitTransformOrigin="0 0 0";this.pos={x:0,y:0};cursorY=cursorX=this.height=this.width=0;this.bPixelDoubling=window.devicePixelRatio>=2;this.setPos(0,
+0);this.setSize(50,400);this.setRenderer(this.canvas,a)};Pixel.Canvas.prototype=new Pixel.Renderer;Pixel.Canvas.prototype.setPos=function(a,c){this.pos.x=a;this.pos.y=c;var d="",d="scale3d("+window.devicePixelRatio+","+window.devicePixelRatio+",0) ";d+="translate3d("+this.pos.x+"px, "+this.pos.y+"px,0px)";this.canvas.style.webkitTransform=d};
+Pixel.Canvas.prototype.setSize=function(a,c,d){this.width=a;this.height=c;this.canvas.setAttribute("width",this.width);this.canvas.setAttribute("height",this.height);d!=void 0&&this.setRenderer(d)};Pixel.Canvas.prototype.getWidth=function(){return this.width};Pixel.Canvas.prototype.getHeight=function(){return this.height};Pixel.Canvas.prototype.setCursor=function(a,c){this.cursorX=a;this.cursorY=c};
+Pixel.Object=function(){this.bPressed=this.bInitPressed=!1;this.pos={x:0,y:0};this.radius=this.height=this.width=0;this.shapeMode=Pixel.OBJECT_SHAPE_RECT;this.rect=new Pixel.Rectangle};Pixel.Object.prototype.show=function(){};Pixel.Object.prototype.hide=function(){};Pixel.Object.prototype.setPos=function(a,c){if(Pixel.isSet(a))this.pos.x=a;if(Pixel.isSet(c))this.pos.y=c;this.setRect()};Pixel.Object.prototype.getPos=function(){return this.pos};
+Pixel.Object.prototype.setSize=function(a,c){if(Pixel.isSet(a))this.width=a;if(Pixel.isSet(c))this.height=c;this.setRect()};Pixel.Object.prototype.setRect=function(){this.rect.set(this.pos.x,this.pos.y,this.width,this.height)};Pixel.Object.prototype.getRect=function(){return this.rect};Pixel.Object.prototype.getWidth=function(){return this.width};Pixel.Object.prototype.getHeight=function(){return this.height};Pixel.Object.prototype.setShapeMode=function(a){this.shapeMode=a};
+Pixel.Object.prototype.isPressed=function(){return this.bPressed};Pixel.Object.prototype.touchStart=function(a){this.setRect(this.pos.x,this.pos.y,this.width,this.height);switch(this.shapeMode){case Pixel.OBJECT_SHAPE_RECT:this.bInitPressed=this.rect.isInside(a.pos.x,a.pos.y);break;case Pixel.OBJECT_SHAPE_CIRCLE:this.bInitPressed=Pixel.dist(this.pos.x,this.pos.y,a.pos.x,a.pos.y)<this.radius*2}return this.bPressed=this.bInitPressed};
+Pixel.Object.prototype.touchMoved=function(a){if(this.bInitPressed)switch(this.shapeMode){case Pixel.OBJECT_SHAPE_RECT:this.bPressed=this.rect.isInside(a.pos.x,a.pos.y);break;case Pixel.OBJECT_SHAPE_CIRCLE:this.bPressed=Pixel.dist(this.pos.x,this.post.y,a.pos.x,a.pos.y)<this.radius*2}return this.bPressed};Pixel.Object.prototype.touchEnd=function(){return this.bInitPressed=this.bPressed=!1};Pixel.Image=function(a){Pixel.Object.call(this);a!=void 0&&this.load(a);this.bAllocated=!1};
+Pixel.Image.prototype=new Pixel.Object;Pixel.Image.prototype.load=function(a){this.clear();this.image=new Image;var c=this;this.image.addEventListener("load",function(){c.bLoaded=!0;c.setSize(this.width,this.height)});this.image.addEventListener("error",function(){console.log("Could not load image from '"+url+"'")});this.image.src=a};Pixel.Image.prototype.isLoaded=function(){return this.bLoaded};Pixel.Image.prototype.clear=function(){this.bLoaded=!1;this.image=this.imageData=this.pixels=null};
+Pixel.Image.prototype.setSize=function(a,c){Pixel.Object.prototype.setSize.call(this,a,c);if(this.bAllocated==!1)this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.imageData=this.ctx.getImageData(0,0,this.getWidth(),this.getHeight());this.canvas.setAttribute("width",this.width);this.canvas.setAttribute("height",this.height)};Pixel.Image.prototype.getImageData=function(){return this.imageData};
+Pixel.Image.prototype.getPixels=function(){return this.bLoaded?(this.ctx.drawImage(this.image,0,0),this.imageData=this.ctx.getImageData(0,0,this.size.width,this.size.height),this.pixels=this.imageData.data):null};
+Pixel.Image.prototype.setFromPixels=function(a,c,d){this.clear();this.setSize(c,d);this.imageData=this.ctx.getImageData(0,0,this.size.width,this.size.height);this.pixels=this.imageData.data;for(c=a.length;c--;)this.pixels[c]=a[c];this.ctx.putImageData(this.imageData,0,0);this.image=new Element("img");this.image.addEvent("load",function(){this.image.removeEvent("load");this.bLoaded=!0}.bind(this));this.image.src=this.canvas.toDataURL("image/png")};
+Pixel.Image.prototype.draw=function(a,c,d){a.drawImage(this,c,d)};Pixel.FontSizeCvs=null;Pixel.Font=function(a,c,d,e){this.font=a||"Arial";this.size=c||12;this.alignment=d||Pixel.TEXT_BASELINE_LEFT;this.baseline=e||Pixel.TEXT_BASELINE_TOP;if(Pixel.FontSizeCvs==null)Pixel.FontSizeCvs=new Pixel.Canvas(Pixel.RENDER_MODE_2D)};Pixel.Font.prototype.setSize=function(a){this.size=a};Pixel.Font.prototype.setFont=function(a){this.font=a};Pixel.Font.prototype.setSize=function(a){this.size=a};
+Pixel.Font.prototype.setFont=function(a){this.font=a};Pixel.Font.prototype.setAlignment=function(a){this.alignment=a};Pixel.Font.prototype.setBaseline=function(a){this.baseline=a};Pixel.Font.prototype.getSize=function(){return this.size};Pixel.Font.prototype.getTextWidth=function(a){Pixel.FontSizeCvs.setFont(this);return Pixel.FontSizeCvs.getTextWidth(a)};Pixel.Font.prototype.getTextHeight=function(){return Math.round(this.size*1.5)};
+Pixel.Textfield=function(a,c){Pixel.Object.call(this);this.font=c||new Pixel.Font("Arial",14);this.color=new Pixel.Color(255,255,255,1);this.text=a||"Text not set";this.setText(this.text)};Pixel.Textfield.prototype=new Pixel.Object;Pixel.Textfield.prototype.setFont=function(a,c,d,e){this.font=c!=void 0?new Pixel.Font(a,c,d,e):a};Pixel.Textfield.prototype.setColor=function(a,c,d,e){this.color.set(a,c,d,e)};
+Pixel.Textfield.prototype.setText=function(a){this.text=a;this.width=this.font.getTextWidth(this.text);this.height=this.font.getTextHeight(this.text);this.setRect()};
+Pixel.Textfield.prototype.setRect=function(){switch(this.font.alignment){case Pixel.TEXT_ALIGN_LEFT:switch(this.font.baseline){case Pixel.TEXT_BASELINE_TOP:this.rect.set(this.pos.x,this.pos.y,this.width,this.height);break;case Pixel.TEXT_BASELINE_MIDDLE:this.rect.set(this.pos.x,this.pos.y-this.height/2,this.width,this.height);break;case Pixel.TEXT_BASELINE_BOTTOM:this.rect.set(this.pos.x,this.pos.y-this.height,this.width,this.height)}break;case Pixel.TEXT_ALIGN_CENTER:switch(this.font.baseline){case Pixel.TEXT_BASELINE_TOP:this.rect.set(this.pos.x-
+this.width/2,this.pos.y,this.width,this.height);break;case Pixel.TEXT_BASELINE_MIDDLE:this.rect.set(this.pos.x-this.width/2,this.pos.y-this.height/2,this.width,this.height);break;case Pixel.TEXT_BASELINE_BOTTOM:this.rect.set(this.pos.x-this.width/2,this.pos.y-this.height,this.width,this.height)}break;case Pixel.TEXT_ALIGN_RIGHT:switch(this.font.baseline){case Pixel.TEXT_BASELINE_TOP:this.rect.set(this.pos.x-this.width,this.pos.y,this.width,this.height);break;case Pixel.TEXT_BASELINE_MIDDLE:this.rect.set(this.pos.x-
+this.width,this.pos.y-this.height/2,this.width,this.height);break;case Pixel.TEXT_BASELINE_BOTTOM:this.rect.set(this.pos.x-this.width,this.pos.y-this.height,this.width,this.height)}}};
+Pixel.App=function(a,c){this.bSetup=!1;this.bRunning=!0;this.bIsMobileApp=!1;this.fps=60;this.curFPS=0;this.bShowFPS=!1;this.nFPSSamples=50;this.fpsSamples=[];this.curFpsSample=-1;this.curFps=0;this.fpsFont=new Pixel.Font("Verdana",10,Pixel.TEXT_ALIGN_LEFT);this.prevTime=this.startTime=0;Pixel.Canvas.call(this,a||Pixel.RENDER_MODE_2D);this.prevTime=this.startTime=(new Date).getTime();this.fpsFont=new Pixel.Font("Verdana",10,Pixel.TEXT_ALIGN_LEFT);var d=this;document.body.addEventListener("mousedown",
+function(a){d.mouseDownListener.call(d,a)});document.body.addEventListener("mousemove",function(a){d.mouseMovedListener.call(d,a)});document.body.addEventListener("mouseup",function(a){d.mouseUpListener.call(d,a)});for(var e in c)this[e]=c[e]};Pixel.App.prototype=new Pixel.Canvas;Pixel.App.prototype.start=function(){this.bRunning=!0};Pixel.App.prototype.stop=function(){this.bRunning=!1};
+Pixel.App.prototype.run=function(){if(this.bRunning){if(this.setup!=void 0&&this.bSetup==!1)this.setup(),this.bSetup=!0;this.update();this.draw();this.bShowFPS&&(this.updateFPS(),this.drawFPS());window.requestAnimFrame(this.run.bind(this))}};Pixel.App.prototype.setFPS=function(a){this.fps=a};Pixel.App.prototype.getFPS=function(){return this.fps};Pixel.App.prototype.showFPS=function(){for(var a=0;a<this.fpsSamples.length;a++)this.fpsSamples[a]=0;this.bShowFPS=!0};
+Pixel.App.prototype.hideFPS=function(){this.bShowFPS=!1};Pixel.App.prototype.updateFPS=function(){this.curFpsSample++;if(this.curFpsSample>=this.nFPSSamples)this.curFpsSample=0;var a=this.getElapsedTime();this.fpsSamples[this.curFpsSample]=1E3/(a-this.prevTime);for(var c=0,d=0;d<this.fpsSamples.length;d++)c+=this.fpsSamples[d];c/=this.fpsSamples.length;this.curFps=Math.floor(c);this.prevTime=a};
+Pixel.App.prototype.drawFPS=function(){this.setFont(this.fpsFont);this.setColor(0,0,0);this.drawText("FPS: "+this.curFps.toFixed(2),20,20);this.setColor(255,255,2550);this.drawText("FPS: "+this.curFps.toFixed(2),22,22)};Pixel.App.prototype.getElapsedTime=function(){return(new Date).getTime()-this.startTime};Pixel.App.prototype.touches=[];
+Pixel.App.prototype.touchStartListener=function(a){if(this.touchStart!=void 0)for(var c=0;c<a.changedTouches.length;c++){for(var d=null,e=0;e<this.touches.length;e++)if(this.touches[e]==null){d=e;break}if(d==null)d=this.touches.length;this.touches[d]={id:e,pos:{x:(!this.bPixelDoubling?a.changedTouches[c].pageX:a.changedTouches[c].pageX/2)-this.pos.x,y:(!this.bPixelDoubling?a.changedTouches[c].pageY:a.changedTouches[c].pageY/2)-this.pos.y},uniqueID:a.changedTouches[c].identifier};this.touchStart(this.touches[d])}};
+Pixel.App.prototype.touchMovedListener=function(a){if(this.touchMoved!=void 0)for(var c=0;c<a.changedTouches.length;c++)for(var d=a.changedTouches[c].identifier,e=0;e<this.touches.length;e++)if(this.touches[e]!=null&&d==this.touches[e].uniqueID){this.touches[e].pos={x:(!this.bPixelDoubling?a.changedTouches[c].pageX:a.changedTouches[c].pageX/2)-this.pos.x,y:(!this.bPixelDoubling?a.changedTouches[c].pageY:a.changedTouches[c].pageY/2)-this.pos.y};this.touchMoved(this.touches[e]);break}};
+Pixel.App.prototype.touchEndListener=function(a){if(this.touchEnd!=void 0)for(var c=0;c<a.changedTouches.length;c++)for(var d=a.changedTouches[c].identifier,e=0;e<this.touches.length;e++)if(this.touches[e]!=null&&d==this.touches[e].uniqueID){this.touchEnd(this.touches[e]);this.touches[e]=null;break}};Pixel.App.prototype.bMouseDown=!1;
+Pixel.App.prototype.mouseDownListener=function(a){this.bMouseDown=!0;a={x:a.clientX,y:a.clientY};this.bIsMobileApp?this.touchStart!=void 0&&this.touchStart({id:0,pos:a}):this.mouseDown!=void 0&&this.mouseDown(a.x,pos.y)};Pixel.App.prototype.mouseMovedListener=function(a){this.bMouseDown&&this.mouseDraggedListener(a);a={x:a.clientX,y:a.clientY};this.bIsMobileApp?this.touchMoved!=void 0&&this.touchMoved({id:0,pos:a}):this.mouseMoved!=void 0&&this.mouseMoved(pos.x,pos.y)};
+Pixel.App.prototype.mouseUpListener=function(a){this.bMouseDown=!1;a={x:a.clientX,y:a.clientY};this.bIsMobileApp?this.touchEnd!=void 0&&this.touchEnd({id:0,pos:a}):this.mouseUp!=void 0&&this.mouseUp(pos.x,pos.y)};Pixel.App.prototype.mouseDraggedListener=function(){};
View
87 Build/compressFiles.py
@@ -8,10 +8,44 @@
headers = { "Content-type": "application/x-www-form-urlencoded" }
conn = http.client.HTTPConnection('closure-compiler.appspot.com')
+libs = "../Libs/";
+src = "../src/";
+#------------------------------------------------------------
+#Files to Add, in order
+files = []
-dir = "../src";
+#Libs
+# files.append(libs + "MooTools/mootools-core-1.3.2.js")
+# files.append(libs + "MooTools/mootools-more-1.3.2.1.js")
+# files.append(libs + "Tween.js/Tween.js")
+#Src
+#Pixel
+files.append(src + "Pixel.js")
+
+#Utils
+files.append(src + "Utils/Pixel.Constants.js")
+files.append(src + "Utils/Pixel.Utils.js")
+files.append(src + "Utils/Pixel.Math.js")
+
+#Renderers
+files.append(src + "Graphics/Rendering/Pixel.Renderer.js")
+files.append(src + "Graphics/Rendering/Pixel.Renderer2D.js")
+
+#Graphics
+files.append(src + "Graphics/Pixel.Color.js")
+files.append(src + "Graphics/Pixel.Canvas.js")
+files.append(src + "Graphics/Pixel.Object.js")
+files.append(src + "Graphics/Pixel.Image.js")
+files.append(src + "Graphics/Pixel.Font.js")
+files.append(src + "Graphics/Pixel.Textfield.js")
+
+#App
+files.append(src + "App/Pixel.App.js")
+
+
+#------------------------------------------------------------
#Does the compression
def compressFile(file):
with open(file, 'r' ) as f:
@@ -36,17 +70,48 @@ def compressFile(file):
print("Done!")
+#------------------------------------------------------------
+def addFile(inputFile, combinedFile):
+ with open(inputFile,'r') as file:
+ inputContent = file.read()
+ combinedFile.write(inputContent)
+
+
+
+
+
+
+#Combine Files
+with open("Pixel.js", 'w') as combinedFile:
+ for file in files:
+ addFile(file, combinedFile)
+
+#Compress
+compressFile("Pixel.js")
+
+
+
+
+
-#Combine all JS
-with open("Pixel.js",'w') as combinedFile:
- for root, subFolders, files in os.walk(dir):
- for filename in files:
- if(filename.endswith('.js')):
- inputFile = os.path.join(root, filename)
- inputContent = open(inputFile,'r').read()
- combinedFile.write(inputContent)
+#------------------------------------------------------------
+#Loop through directory, add all js
+def addFiles(dir, combinedFile):
+ #with open(file, 'w') as combinedFile:
+ for root, subFolders, files in os.walk(dir):
+ for filename in files:
+ if(filename.endswith('.js')):
+ inputFile = os.path.join(root, filename)
+ inputContent = open(inputFile,'r').read()
+ combinedFile.write(inputContent)
-#Do the compression
-compressFile("Pixel.js")
+# #Combine all JS
+# with open("Pixel.js",'w') as combinedFile:
+# for root, subFolders, files in os.walk(dir):
+# for filename in files:
+# if(filename.endswith('.js')):
+# inputFile = os.path.join(root, filename)
+# inputContent = open(inputFile,'r').read()
+# combinedFile.write(inputContent)
View
9 Examples/HelloWorld/index.html
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <script src="../../Build/Pixel.js"></script>
+ </head>
+
+ <body>
+
+ </body>
+</html>
View
4,537 Libs/MooTools/mootools-core-1.3.2.js
4,196 additions, 341 deletions not shown
View
175 Libs/MooTools/mootools-more-1.3.2.1.js
@@ -3,19 +3,168 @@
// Or build this file again with packager using: packager build More/Assets
/*
---
-copyrights:
- - [MooTools](http://mootools.net)
-licenses:
- - [MIT License](http://mootools.net/license.txt)
+script: More.js
+
+name: More
+
+description: MooTools More
+
+license: MIT-style license
+
+authors:
+ - Guillermo Rauch
+ - Thomas Aylott
+ - Scott Kyle
+ - Arian Stolwijk
+ - Tim Wienk
+ - Christoph Pojer
+ - Aaron Newton
+ - Jacob Thornton
+
+requires:
+ - Core/MooTools
+
+provides: [MooTools.More]
+
...
*/
-MooTools.More={version:"1.3.2.1",build:"e586bcd2496e9b22acfde32e12f84d49ce09e59d"};var Asset={javascript:function(f,c){if(!c){c={};}var a=new Element("script",{src:f,type:"text/javascript"}),g=c.document||document,b=0,d=c.onload||c.onLoad;
-var e=d?function(){if(++b==1){d.call(this);}}:function(){};delete c.onload;delete c.onLoad;delete c.document;return a.addEvents({load:e,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){e.call(this);
-}}}).set(c).inject(g.head);},css:function(d,a){if(!a){a={};}var b=new Element("link",{rel:"stylesheet",media:"screen",type:"text/css",href:d});var c=a.onload||a.onLoad,e=a.document||document;
-delete a.onload;delete a.onLoad;delete a.document;if(c){b.addEvent("load",c);}return b.set(a).inject(e.head);},image:function(c,b){if(!b){b={};}var d=new Image(),a=document.id(d)||new Element("img");
-["load","abort","error"].each(function(e){var g="on"+e,f="on"+e.capitalize(),h=b[g]||b[f]||function(){};delete b[f];delete b[g];d[g]=function(){if(!d){return;
-}if(!a.parentNode){a.width=d.width;a.height=d.height;}d=d.onload=d.onabort=d.onerror=null;h.delay(1,a,a);a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);
-}return a.set(b);},images:function(c,b){c=Array.from(c);var d=function(){},a=0;b=Object.merge({onComplete:d,onProgress:d,onError:d,properties:{}},b);return new Elements(c.map(function(f,e){return Asset.image(f,Object.append(b.properties,{onload:function(){a++;
-b.onProgress.call(this,a,e,f);if(a==c.length){b.onComplete();}},onerror:function(){a++;b.onError.call(this,a,e,f);if(a==c.length){b.onComplete();}}}));
-}));}};
+
+MooTools.More = {
+ 'version': '1.3.2.1',
+ 'build': 'e586bcd2496e9b22acfde32e12f84d49ce09e59d'
+};
+
+
+/*
+---
+
+script: Assets.js
+
+name: Assets
+
+description: Provides methods to dynamically load JavaScript, CSS, and Image files into the document.
+
+license: MIT-style license
+
+authors:
+ - Valerio Proietti
+
+requires:
+ - Core/Element.Event
+ - /MooTools.More
+
+provides: [Assets]
+
+...
+*/
+
+var Asset = {
+
+ javascript: function(source, properties){
+ if (!properties) properties = {};
+
+ var script = new Element('script', {src: source, type: 'text/javascript'}),
+ doc = properties.document || document,
+ loaded = 0,
+ loadEvent = properties.onload || properties.onLoad;
+
+ var load = loadEvent ? function(){ // make sure we only call the event once
+ if (++loaded == 1) loadEvent.call(this);
+ } : function(){};
+
+ delete properties.onload;
+ delete properties.onLoad;
+ delete properties.document;
+
+ return script.addEvents({
+ load: load,
+ readystatechange: function(){
+ if (['loaded', 'complete'].contains(this.readyState)) load.call(this);
+ }
+ }).set(properties).inject(doc.head);
+ },
+
+ css: function(source, properties){
+ if (!properties) properties = {};
+
+ var link = new Element('link', {
+ rel: 'stylesheet',
+ media: 'screen',
+ type: 'text/css',
+ href: source
+ });
+
+ var load = properties.onload || properties.onLoad,
+ doc = properties.document || document;
+
+ delete properties.onload;
+ delete properties.onLoad;
+ delete properties.document;
+
+ if (load) link.addEvent('load', load);
+ return link.set(properties).inject(doc.head);
+ },
+
+ image: function(source, properties){
+ if (!properties) properties = {};
+
+ var image = new Image(),
+ element = document.id(image) || new Element('img');
+
+ ['load', 'abort', 'error'].each(function(name){
+ var type = 'on' + name,
+ cap = 'on' + name.capitalize(),
+ event = properties[type] || properties[cap] || function(){};
+
+ delete properties[cap];
+ delete properties[type];
+
+ image[type] = function(){
+ if (!image) return;
+ if (!element.parentNode){
+ element.width = image.width;
+ element.height = image.height;
+ }
+ image = image.onload = image.onabort = image.onerror = null;
+ event.delay(1, element, element);
+ element.fireEvent(name, element, 1);
+ };
+ });
+
+ image.src = element.src = source;
+ if (image && image.complete) image.onload.delay(1);
+ return element.set(properties);
+ },
+
+ images: function(sources, options){
+ sources = Array.from(sources);
+
+ var fn = function(){},
+ counter = 0;
+
+ options = Object.merge({
+ onComplete: fn,
+ onProgress: fn,
+ onError: fn,
+ properties: {}
+ }, options);
+
+ return new Elements(sources.map(function(source, index){
+ return Asset.image(source, Object.append(options.properties, {
+ onload: function(){
+ counter++;
+ options.onProgress.call(this, counter, index, source);
+ if (counter == sources.length) options.onComplete();
+ },
+ onerror: function(){
+ counter++;
+ options.onError.call(this, counter, index, source);
+ if (counter == sources.length) options.onComplete();
+ }
+ }));
+ }));
+ }
+
+};
+
View
2  Libs/MooTools/settings.txt
@@ -1,4 +1,6 @@
//-------------------------------------------------------
+//Classes currently required from Mootools.net custom builders
+
//-------------------------------------------------------
//-------------------------------------------------------
//Core Classes Needed
View
569 Libs/Three.js/Three.js
0 additions, 569 deletions not shown
View
590 Src/App/Pixel.App.js
@@ -1,340 +1,344 @@
//-------------------------------------------------------
-//-------------------------------------------------------
-//App Runner
-
-if(!Pixel) {
- var Pixel = {};
- if(!px) var px = Pixel;
-}
-
-Pixel.App = new Class({
- Extends:Pixel.Canvas,
- Implements:Events,
-
- bSetup:false,
- bRunning:true,
-
- browserType: null,
- bIsMobileApp:false,
+//Pixel.App.js
+Pixel.App = function(renderMode, program) {
+ this.bSetup = false;
+ this.bRunning = true;
- fps:60,
- curFPS:0,
- bShowFPS:false,
- nFPSSamples:50,
- fpsSamples:[],
- curFpsSample:-1,
- curFps:0,
- fpsFont:null,
-
- startTime:0,
- prevTime:0,
-
-
- //-------------------------------------------------------
- initialize:function(renderMode, bIsMobileApp) {
- //Default to 2D Renderer
- this.parent(Pixel.RENDER_MODE_2D);
-
- this.startTime = new Date().getTime();
- this.prevTime = this.startTime;
-
- //FPS Font
- this.fpsFont = new Pixel.Font("Verdana", 10, Pixel.TEXT_ALIGN_LEFT);
-
- //Event Listeners
- if(Pixel.getBrowserName() == Pixel.BROWSER_TYPE_IPHONE) {
- $(document.body).addEvent("touchstart", this.touchStartListener.bind(this));
- $(document.body).addEvent("touchmove", this.touchMovedListener.bind(this));
- $(document.body).addEvent("touchend", this.touchEndListener.bind(this));
- } else {
- $(document.body).addEvent("mousedown", this.mouseDownListener.bind(this));
- $(document.body).addEvent("mousemove", this.mouseMovedListener.bind(this));
- $(document.body).addEvent("mouseup", this.mouseUpListener.bind(this));
- }
-
- //Start Tweening
- TWEEN.start();
- },
-
-
- //-------------------------------------------------------
- start: function() {
- this.bRunning = true;
- },
-
-
- //-------------------------------------------------------
- stop: function() {
- this.bRunning = false;
- },
-
-
- //-------------------------------------------------------
- run: function() {
- if(this.bRunning) {
- //Run App Setup if uninitalised
- if(this.setup != undefined && this.bSetup == false) {
- this.setup();
- this.bSetup = true;
- }
-
- this.update();
- this.draw();
-
- if(this.bShowFPS) {
- this.updateFPS();
- this.drawFPS();
- }
-
-
- window.requestAnimFrame(this.run.bind(this));
- }
- },
+ this.bIsMobileApp = false;
- //-------------------------------------------------------
//FPS
- //-------------------------------------------------------
- setFPS: function(fps) {
- this.fps = fps;
- },
+ this.fps = 60;
+ this.curFPS = 0;
+ this.bShowFPS = false;
+ this.nFPSSamples = 50;
+ this.fpsSamples = [];
+ this.curFpsSample = -1;
+ this.curFps = 0;
+ this.fpsFont = new Pixel.Font("Verdana", 10, Pixel.TEXT_ALIGN_LEFT);
+ this.startTime = 0;
+ this.prevTime = 0;
- //-------------------------------------------------------
- getFPS: function() {
- return this.fps;
- },
+ //Default to 2D Renderer
+ Pixel.Canvas.call(this, renderMode || Pixel.RENDER_MODE_2D);
- //-------------------------------------------------------
- showFPS: function() {
- //Clear samples
- for(var i=0;i<this.fpsSamples.length; i++) {
- this.fpsSamples[i] = 0;
- }
-
- this.bShowFPS = true;
- },
+ this.startTime = new Date().getTime();
+ this.prevTime = this.startTime;
- //-------------------------------------------------------
- hideFPS: function() {
- this.bShowFPS = false;
- },
+ //FPS Font
+ this.fpsFont = new Pixel.Font("Verdana", 10, Pixel.TEXT_ALIGN_LEFT);
+ //Event Listeners
- //-------------------------------------------------------
- updateFPS: function() {
- this.curFpsSample++;
- if(this.curFpsSample >= this.nFPSSamples) {
- this.curFpsSample = 0;
+ var self = this;
+ /*
+ if(Pixel.isTouchDevice) {
+ this.canvas.addEventListener("touchstart", function(e) { self.touchStartListener.call(self, e) });
+ document.body.addEventListener("touchmove", function(e) { self.touchMovedListener.call(self, e) });
+ document.body.addEventListener("touchend", function(e) { self.touchEndListener.call(self, e) });
+ } else {
+*/
+ document.body.addEventListener("mousedown", function(e) { self.mouseDownListener.call(self, e) });
+ document.body.addEventListener("mousemove", function(e) { self.mouseMovedListener.call(self, e) });
+ document.body.addEventListener("mouseup", function(e) { self.mouseUpListener.call(self, e) });
+ //}
+
+
+ for(var item in program) {
+ this[item] = program[item];
+ }
+}
+
+Pixel.App.prototype = new Pixel.Canvas();
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.start = function() {
+ this.bRunning = true;
+}
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.stop = function() {
+ this.bRunning = false;
+}
+
+//-------------------------------------------------------
+Pixel.App.prototype.run = function() {
+ if(this.bRunning) {
+ //Run App Setup if uninitalised
+ if(this.setup != undefined && this.bSetup == false) {
+ this.setup();
+ this.bSetup = true;
}
+
+ this.update();
+ this.draw();
- var curTime = this.getElapsedTime();
- this.fpsSamples[this.curFpsSample] = 1000.0/(curTime - this.prevTime);
-
- var avgFps = 0;
- for(var i=0;i<this.fpsSamples.length; i++) {
- avgFps += this.fpsSamples[i];
+ if(this.bShowFPS) {
+ this.updateFPS();
+ this.drawFPS();
}
- avgFps /= this.fpsSamples.length;
-
- this.curFps = Math.floor(avgFps);
- this.prevTime = curTime;
- },
-
- //-------------------------------------------------------
- drawFPS: function() {
- this.setFont(this.fpsFont);
-
- this.setColor(0,0,0);
- this.drawText("FPS: " + this.curFps.toFixed(2), 20, 20);
- this.setColor(255,255,2550);
- this.drawText("FPS: " + this.curFps.toFixed(2), 22, 22);
- },
+ window.requestAnimFrame(this.run.bind(this));
+ //this.run.delay(0,this);
+ }
+}
+
+//-------------------------------------------------------
+//FPS
+//-------------------------------------------------------
+Pixel.App.prototype.setFPS = function(fps) {
+ this.fps = fps;
+}
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.getFPS = function() {
+ return this.fps;
+}
+
+//-------------------------------------------------------
+Pixel.App.prototype.showFPS = function() {
+ //Clear samples
+ for(var i=0;i<this.fpsSamples.length; i++) {
+ this.fpsSamples[i] = 0;
+ }
+ this.bShowFPS = true;
+}
+
+
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.hideFPS = function() {
+ this.bShowFPS = false;
+}
+
+
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.updateFPS = function() {
+ this.curFpsSample++;
+ if(this.curFpsSample >= this.nFPSSamples) {
+ this.curFpsSample = 0;
+ }
- //-------------------------------------------------------
- //Time
- getElapsedTime: function() {
- var curTime = new Date().getTime();
- return curTime - this.startTime;
- },
+ var curTime = this.getElapsedTime();
+ this.fpsSamples[this.curFpsSample] = 1000.0/(curTime - this.prevTime);
+ var avgFps = 0;
+ for(var i=0;i<this.fpsSamples.length; i++) {
+ avgFps += this.fpsSamples[i];
+ }
- //-------------------------------------------------------
- //Event Listeners
- //Events are sent to functions that can be implemented by extending classes
- //If event functions aren't implemented, they're ignored
+ avgFps /= this.fpsSamples.length;
- //-------------------------------------------------------
- //Touch Listener
- touches:[],
+ this.curFps = Math.floor(avgFps);
- //Default functions (called by listeners, extend in App)
+ this.prevTime = curTime;
+}
+
+
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.drawFPS = function() {
+ this.setFont(this.fpsFont);
- //-------------------------------------------------------
- touchStartListener: function(e) {
- if(this.touchStart != undefined) {
- for(var i=0;i < e.changedTouches.length; i++) {
- //Find empty slot for touch
- var emptyTouchPos = null;
- for(var j=0; j<this.touches.length; j++) {
- if(this.touches[j]==null) {
- emptyTouchPos = j;
- break;
- }
- }
-
- //If slot not found, create new item in touches array (javascript way of doing things)
- if(emptyTouchPos == null) emptyTouchPos = this.touches.length;
-
- //Get the touch position, divide by half if pixel Doubling!
- var xPos = !this.bPixelDoubling ? e.changedTouches[i].pageX : e.changedTouches[i].pageX/2;
- var yPos = !this.bPixelDoubling ? e.changedTouches[i].pageY : e.changedTouches[i].pageY/2;
-
- //Set the touch
- this.touches[emptyTouchPos] = {
- id:j,
- pos:{
- x:xPos - this.pos.x,
- y:yPos - this.pos.y
- },
- uniqueID:e.changedTouches[i].identifier
+ this.setColor(0,0,0);
+ this.drawText("FPS: " + this.curFps.toFixed(2), 20, 20);
+ this.setColor(255,255,2550);
+ this.drawText("FPS: " + this.curFps.toFixed(2), 22, 22);
+}
+
+
+
+
+//-------------------------------------------------------
+//Time
+Pixel.App.prototype.getElapsedTime = function() {
+ var curTime = new Date().getTime();
+ return curTime - this.startTime;
+}
+
+
+
+//-------------------------------------------------------
+//Event Listeners
+//Events are sent to functions that can be implemented by extending classes
+//If event functions aren't implemented, they're ignored
+
+//-------------------------------------------------------
+//Touch Listener
+Pixel.App.prototype.touches = [],
+
+//Default functions (called by listeners, extend in App)
+
+//-------------------------------------------------------
+Pixel.App.prototype.touchStartListener = function(e) {
+ if(this.touchStart != undefined) {
+ for(var i=0;i < e.changedTouches.length; i++) {
+ //Find empty slot for touch
+ var emptyTouchPos = null;
+ for(var j=0; j<this.touches.length; j++) {
+ if(this.touches[j]==null) {
+ emptyTouchPos = j;
+ break;
}
-
- //Deploy Event
- this.touchStart(this.touches[emptyTouchPos]);
}
+
+ //If slot not found, create new item in touches array (javascript way of doing things)
+ if(emptyTouchPos == null) emptyTouchPos = this.touches.length;
+
+ //Get the touch position, divide by half if pixel Doubling!
+ var xPos = !this.bPixelDoubling ? e.changedTouches[i].pageX : e.changedTouches[i].pageX/2;
+ var yPos = !this.bPixelDoubling ? e.changedTouches[i].pageY : e.changedTouches[i].pageY/2;
+
+ //Set the touch
+ this.touches[emptyTouchPos] = {
+ id:j,
+ pos:{
+ x:xPos - this.pos.x,
+ y:yPos - this.pos.y
+ },
+ uniqueID:e.changedTouches[i].identifier
+ }
+
+ //Deploy Event
+ this.touchStart(this.touches[emptyTouchPos]);
}
- },
-
-
- //-------------------------------------------------------
- touchMovedListener: function(e) {
- if(this.touchMoved != undefined) {
- //Get Changed touches, these are the ones that moved
- for(var i=0; i<e.changedTouches.length; i++) {
- //Get each touch's unique ID
- var uniqueID = e.changedTouches[i].identifier;
+ }
+}
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.touchMovedListener = function(e) {
+ if(this.touchMoved != undefined) {
+ //Get Changed touches, these are the ones that moved
+ for(var i=0; i<e.changedTouches.length; i++) {
+ //Get each touch's unique ID
+ var uniqueID = e.changedTouches[i].identifier;
+
+ //Find corresponding touch object
+ for(var j=0; j<this.touches.length;j++) {
+ if(this.touches[j] != null && uniqueID == this.touches[j].uniqueID) {
+ //Get the touch position, divide by half if pixel Doubling!
+ var xPos = !this.bPixelDoubling ? e.changedTouches[i].pageX : e.changedTouches[i].pageX/2;
+ var yPos = !this.bPixelDoubling ? e.changedTouches[i].pageY : e.changedTouches[i].pageY/2;
+
- //Find corresponding touch object
- for(var j=0; j<this.touches.length;j++) {
- if(this.touches[j] != null && uniqueID == this.touches[j].uniqueID) {
- //Get the touch position, divide by half if pixel Doubling!
- var xPos = !this.bPixelDoubling ? e.changedTouches[i].pageX : e.changedTouches[i].pageX/2;
- var yPos = !this.bPixelDoubling ? e.changedTouches[i].pageY : e.changedTouches[i].pageY/2;
-
-
- //Update touch pos
- this.touches[j].pos = {
- x:xPos - this.pos.x,
- y:yPos - this.pos.y
- }
-
- //Deploy Event
- this.touchMoved(this.touches[j]);
- break;
+ //Update touch pos
+ this.touches[j].pos = {
+ x:xPos - this.pos.x,
+ y:yPos - this.pos.y
}
+
+ //Deploy Event
+ this.touchMoved(this.touches[j]);
+ break;
}
}
}
- },
-
-
- //-------------------------------------------------------
- touchEndListener: function(e) {
- if(this.touchEnd != undefined) {
- for(var i=0; i<e.changedTouches.length; i++) {
- //Get each touch's unique ID
- var uniqueID = e.changedTouches[i].identifier;
-
- for(var j=0; j<this.touches.length; j++) {
- if(this.touches[j] != null && uniqueID == this.touches[j].uniqueID) {
- this.touchEnd(this.touches[j]);
- this.touches[j] = null;
- break;
- }
+ }
+}
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.touchEndListener = function(e) {
+ if(this.touchEnd != undefined) {
+ for(var i=0; i<e.changedTouches.length; i++) {
+ //Get each touch's unique ID
+ var uniqueID = e.changedTouches[i].identifier;
+
+ for(var j=0; j<this.touches.length; j++) {
+ if(this.touches[j] != null && uniqueID == this.touches[j].uniqueID) {
+ this.touchEnd(this.touches[j]);
+ this.touches[j] = null;
+ break;
}
}
}
- },
-
-
- //-------------------------------------------------------
- //Mouse Listeners
-
- bMouseDown:false,
+ }
+}
+
+
+//-------------------------------------------------------
+//Mouse Listeners
+
+Pixel.App.prototype.bMouseDown = false,
+
+//-------------------------------------------------------
+Pixel.App.prototype.mouseDownListener = function(e) {
+ this.bMouseDown = true;
- //-------------------------------------------------------
- mouseDownListener: function(e) {
- this.bMouseDown = true;
+ //Get Position of Event
+ var position = {
+ x:e.clientX,
+ y:e.clientY
+ }
- //Get Position of Event
- var position = {
- x:e.client.x,
- y:e.client.y
+ if(this.bIsMobileApp) {
+ if(this.touchStart != undefined) {
+ this.touchStart({id:0, pos:position});
}
-
- if(this.bIsMobileApp) {
- if(this.touchStart != undefined) {
- this.touchStart({id:0, pos:position});
- }
- } else {
- if(this.mouseDown != undefined) {
- this.mouseDown(position.x, pos.y);
- }
+ } else {
+ if(this.mouseDown != undefined) {
+ this.mouseDown(position.x, pos.y);
}
- },
+ }
+}
+
+//-------------------------------------------------------
+Pixel.App.prototype.mouseMovedListener = function(e) {
+ if(this.bMouseDown) {
+ this.mouseDraggedListener(e);
+ }
- //-------------------------------------------------------
- mouseMovedListener: function(e) {
- if(this.bMouseDown) {
- this.mouseDraggedListener(e);
- }
+ //Get Position of Event
+ var position = {
+ x:e.clientX,
+ y:e.clientY
+ }
- //Get Position of Event
- var position = {
- x:e.client.x,
- y:e.client.y
+ if(this.bIsMobileApp) {
+ if(this.touchMoved != undefined) {
+ this.touchMoved({id:0, pos:position});
}
-
- if(this.bIsMobileApp) {
- if(this.touchMoved != undefined) {
- this.touchMoved({id:0, pos:position});
- }
- } else {
- if(this.mouseMoved != undefined) {
- this.mouseMoved(pos.x, pos.y);
- }
+ } else {
+ if(this.mouseMoved != undefined) {
+ this.mouseMoved(pos.x, pos.y);
}
- },
-
+ }
+}
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.mouseUpListener = function(e) {
+ this.bMouseDown = false;
- //-------------------------------------------------------
- mouseUpListener: function(e) {
- this.bMouseDown = false;
+ //Get Position of Event
+ var position = {
+ x:e.clientX,
+ y:e.clientY
+ }
- //Get Position of Event
- var position = {
- x:e.client.x,
- y:e.client.y
+ if(this.bIsMobileApp) {
+ if(this.touchEnd != undefined) {
+ this.touchEnd({id:0, pos:position});
}
-
- if(this.bIsMobileApp) {
- if(this.touchEnd != undefined) {
- this.touchEnd({id:0, pos:position});
- }
- } else {
- if(this.mouseUp != undefined) {
- this.mouseUp(pos.x, pos.y);
- }
+ } else {
+ if(this.mouseUp != undefined) {
+ this.mouseUp(pos.x, pos.y);
}
- },
-
-
- //-------------------------------------------------------
- mouseDraggedListener: function(e) {
-
}
+}
+
+
+//-------------------------------------------------------
+Pixel.App.prototype.mouseDraggedListener = function(e) {
-});
+}
View
193 Src/Graphics/Pixel.Canvas.js
@@ -1,105 +1,116 @@
-if(!Pixel) {
- var Pixel = {};
- if(!px) var px = Pixel;
-}
-
+//-------------------------------------------------------
+//Pixel.Canvas.js
+//Canvas Wrapper, implements Renderer functions and adds DOM specific stuff
+//+ generic vars shared between renderers (i.e. Cursor)
-Pixel.Canvas = new Class({
- Implements:Pixel.Renderer,
-
- element:null,
+Pixel.Canvas = function(renderMode) {
+ Pixel.Renderer.call(this);
+
+ //Create Canvas
+ this.canvas = document.createElement('canvas');
+ this.canvas.innerHTML = "Your browser does not support HTML5 Canvas."
+ this.canvas.setAttribute('width', this.width);
+ this.canvas.setAttribute('height', this.height);
+
+ this.canvas.style.position = "absolute";
+ this.canvas.style.top = "0px";
+ this.canvas.style.left = "0px";
+
+ this.canvas.webkitTransformOrigin = "0 0 0";
+
+ /*
+ this.canvas = new Element('canvas', {
+ width:this.width,
+ height:this.height,
+ styles: {
+ position:"absolute",
+ top:"0px",
+ left:"0px",
+ "-webkit-transform-origin":"0 0 0"
+ }
+ });
+ */
- pos:{
+ this.pos = {
x:0,
y:0
- },
+ }
- width:0,
- height:0,
+ this.width = 0;
+ this.height = 0;
//Cursor, useful for text layout
- cursorX:0,
- cursorY:0,
-
- bPixelDoubling:window.devicePixelRatio >= 2,
-
- //-------------------------------------------------------
- initialize:function(renderMode) {
- //Create Canvas
- this.element = new Element('canvas', {
- width:this.width,
- height:this.height,
- styles: {
- position:"absolute",
- top:"0px",
- left:"0px",
- "-webkit-transform-origin":"0 0 0"
- }
- });
-
- //Init Vars
- this.setPos(0,0);
- this.setSize(50,50);
-
- //Set Renderer
- this.setRenderer(this.element, renderMode);
- },
-
-
- //-------------------------------------------------------
- //Position
+ cursorX = 0;
+ cursorY = 0;
- //-------------------------------------------------------
- setPos: function(x,y) {
- this.pos.x = x;
- this.pos.y = y;
-
- //Get Transformation (iPhone4 vs 3G/3GS)
- var transform = "";
- transform ="scale3d(" + window.devicePixelRatio + "," + window.devicePixelRatio +",0) ";
- transform += "translate3d(" + this.pos.x + "px, " + this.pos.y + "px,0px)";
-
- this.element.setStyle("-webkit-transform",transform);
- },
+ //Pixel doubling for iOS
+ this.bPixelDoubling = window.devicePixelRatio >= 2;
+ //Init Vars
+ this.setPos(0,0);
+ this.setSize(50,400);
- //-------------------------------------------------------
- //Size Info
-
- //-------------------------------------------------------
- setSize: function(width,height, renderer) {
- this.width = width;
- this.height = height;
-
- this.element.set({
- width:this.width,
- height:this.height
- });
-
-
-
- if(renderer != undefined) {
- this.setRenderer(renderer);
- }
- },
-
-
- //-------------------------------------------------------
- getWidth: function() {
- return this.width;
- },
+ //Set Renderer
+ this.setRenderer(this.canvas, renderMode);
+}
+
+Pixel.Canvas.prototype = new Pixel.Renderer();
+
+
+//-------------------------------------------------------
+//Position
+
+//-------------------------------------------------------
+Pixel.Canvas.prototype.setPos = function(x,y) {
+ this.pos.x = x;
+ this.pos.y = y;
+
+ //Get Transformation (iPhone4 vs 3G/3GS)
+ var transform = "";
+ transform ="scale3d(" + window.devicePixelRatio + "," + window.devicePixelRatio +",0) ";
+ transform += "translate3d(" + this.pos.x + "px, " + this.pos.y + "px,0px)";
+
+ this.canvas.style.webkitTransform = transform;
+},
+
+
+//-------------------------------------------------------
+//Size Info
+
+//-------------------------------------------------------
+Pixel.Canvas.prototype.setSize = function(width,height, renderer) {
+ this.width = width;
+ this.height = height;
- //-------------------------------------------------------
- getHeight: function() {
- return this.height;
- },
+ this.canvas.setAttribute('width', this.width);
+ this.canvas.setAttribute('height', this.height);
- //-------------------------------------------------------
- //Cursor
- //-------------------------------------------------------
- setCursor: function(x,y) {
- this.cursorX = x;
- this.cursorY = y;
+ if(renderer != undefined) {
+ this.setRenderer(renderer);
}
-});
+}
+
+
+
+//-------------------------------------------------------
+Pixel.Canvas.prototype.getWidth = function() {
+ return this.width;
+}
+
+
+
+//-------------------------------------------------------
+Pixel.Canvas.prototype.getHeight = function() {
+ return this.height;
+}
+
+
+
+//-------------------------------------------------------
+//Cursor
+//-------------------------------------------------------
+Pixel.Canvas.prototype.setCursor = function(x,y) {
+ this.cursorX = x;
+ this.cursorY = y;
+}
View
120 Src/Graphics/Pixel.Color.js
@@ -1,74 +1,64 @@
-if(!Pixel) {
- var Pixel = {};
- if(!px) var px = Pixel;
+//-------------------------------------------------------
+//Pixel.Color.js
+//Color class
+
+Pixel.Color = function(r,g,b,a) {
+ this.r = 0;
+ this.g = 0;
+ this.b = 0;
+
+ this.h = 0;
+ this.s = 0;
+ this.l = 0;
+ this.v = 0;
}
-//-------------------------------------------------------
-//-------------------------------------------------------
-//Color Functions
+
//-------------------------------------------------------
-Pixel.Color = new Class({
- r:0,
- g:0,
- b:0,
- a:0,
-
- h:0,
- s:0,
- l:0,
- v:0,
-
- //-------------------------------------------------------
- initialize:function(r,g,b,a) {
- this.set(r,g,b,a);
- },
-
-
- //-------------------------------------------------------
- set:function(r,g,b,a) {
- if(r != undefined) this.r = r;
- if(g != undefined) this.g = g;
- if(b != undefined) this.b = b;
-
- this.a = a != undefined ? a : 1;
- },
-
-
- //-------------------------------------------------------
- setHSL: function(h,s,l,a) {
- if(h != undefined) this.h = h;
- if(s != undefined) this.s = g;
- if(l != undefined) this.l = b;
-
- this.a = a != undefined ? a : 1;
- },
-
-
- //-------------------------------------------------------
- setHSV: function(h,s,v,a) {
- if(h != undefined) this.h = h;
- if(s != undefined) this.s = g;
- if(v != undefined) this.l = b;
- if(a != undefined) this.a = a;
- },
-
-
- //-------------------------------------------------------
- toHSL: function() {
- var hsl = Pixel.rgbToHSL(this.r, this.g, this.b);
- this.setHSL(hsl.h, hsl.s, hsl.l);
- return hsl;
- },
+Pixel.Color.prototype.set = function(r,g,b,a) {
+ if(r != undefined) this.r = r;
+ if(g != undefined) this.g = g;
+ if(b != undefined) this.b = b;
+ this.a = a != undefined ? a : 1;
+}
+
+
+//-------------------------------------------------------
+Pixel.Color.prototype.setHSL = function(h,s,l,a) {
+ if(h != undefined) this.h = h;
+ if(s != undefined) this.s = g;
+ if(l != undefined) this.l = b;
- //-------------------------------------------------------
- toHSV: function() {
- var hsv = Pixel.rgbToHSV(this.r, this.g, this.b);
- this.setHSV(hsv.h, hsv.s, hsv.v);
- return hsv;
- }
-});
+ this.a = a != undefined ? a : 1;
+}
+
+
+//-------------------------------------------------------
+Pixel.Color.prototype.setHSV = function(h,s,v,a) {
+ if(h != undefined) this.h = h;
+ if(s != undefined) this.s = g;
+ if(v != undefined) this.l = b;
+ if(a != undefined) this.a = a;
+}
+
+
+//-------------------------------------------------------
+Pixel.Color.prototype.toHSL = function() {
+ var hsl = Pixel.rgbToHSL(this.r, this.g, this.b);
+ this.setHSL(hsl.h, hsl.s, hsl.l);
+ return hsl;
+}
+
+
+//-------------------------------------------------------
+Pixel.Color.prototype.toHSV = function() {
+ var hsv = Pixel.rgbToHSV(this.r, this.g, this.b);
+ this.setHSV(hsv.h, hsv.s, hsv.v);
+ return hsv;
+}
+
//-------------------------------------------------------
View
127 Src/Graphics/Pixel.Font.js
@@ -1,67 +1,68 @@
-if(!Pixel) {
- var Pixel = {};
- if(!px) var px = Pixel;
-};
+//-------------------------------------------------------
+//Pixel.Font.js
+//Used for storing font information for convenience
Pixel.FontSizeCvs = null;
-
-Pixel.Font = new Class({
- ctx:null,
-
- font:"Arial",
- size:24,
- alignment: Pixel.TEXT_ALIGN_LEFT,
- baseline: Pixel.TEXT_BASELINE_TOP,
-
- //-------------------------------------------------------
- initialize:function(font, size, alignment, baseline) {
- if(Pixel.isSet(font)) this.font = font;
- if(Pixel.isSet(size)) this.size = size;
- if(Pixel.isSet(alignment)) this.alignment = alignment;
- if(Pixel.isSet(baseline)) this.baseline = baseline;
-
- //Create canvas for getting sizes, if not defined yet
- if(Pixel.FontSizeCvs == null) {
- Pixel.FontSizeCvs = new Pixel.Canvas(Pixel.RENDER_MODE_2D);
- }
- },
-
- //-------------------------------------------------------
- setSize: function(size) {
- this.size = size;
- },
-
-
- //-------------------------------------------------------
- setFont: function(font) {
- this.font = font;
- },
-
- //-------------------------------------------------------
- setAlignment: function(alignment) {
- this.alignment = alignment;
- },
+Pixel.Font = function(font, size, alignment, baseline) {
+ this.font = font || "Arial";
+ this.size = size || 12;
+ this.alignment = alignment || Pixel.TEXT_BASELINE_LEFT;
+ this.baseline = baseline || Pixel.TEXT_BASELINE_TOP;
-
- //-------------------------------------------------------
- setBaseline: function(baseline) {
- this.baseline = baseline;
- },
-
- //-------------------------------------------------------
- getSize: function() {
- return this.size;
- },
-
- //-------------------------------------------------------
- getTextWidth:function(text) {
- Pixel.FontSizeCvs.setFont(this);
- return Pixel.FontSizeCvs.getTextWidth(text);
- },
-
- //-------------------------------------------------------
- getTextHeight: function() {
- return Math.round(this.size * 1.5);
- }
-});
+ //Create canvas for getting sizes, if not defined yet
+ if(Pixel.FontSizeCvs == null) {
+ Pixel.FontSizeCvs = new Pixel.Canvas(Pixel.RENDER_MODE_2D);
+ }
+}
+
+
+//-------------------------------------------------------
+Pixel.Font.prototype.setSize = function(size) {
+ this.size = size;
+}
+
+
+//-------------------------------------------------------
+Pixel.Font.prototype.setFont = function(font) {
+ this.font = font;
+}
+
+
+//-------------------------------------------------------
+Pixel.Font.prototype.setSize = function(size) {
+ this.size = size;
+}
+
+
+//-------------------------------------------------------
+Pixel.Font.prototype.setFont = function(font) {
+ this.font = font;
+}
+
+//-------------------------------------------------------
+Pixel.Font.prototype.setAlignment = function(alignment) {
+ this.alignment = alignment;
+}
+
+
+//-------------------------------------------------------
+Pixel.Font.prototype.setBaseline = function(baseline) {
+ this.baseline = baseline;
+}
+
+//-------------------------------------------------------
+Pixel.Font.prototype.getSize = function() {
+ return this.size;
+}
+
+//-------------------------------------------------------
+Pixel.Font.prototype.getTextWidth = function(text) {
+ Pixel.FontSizeCvs.setFont(this);
+ return Pixel.FontSizeCvs.getTextWidth(text);
+}
+
+//-------------------------------------------------------
+Pixel.Font.prototype.getTextHeight = function() {
+ return Math.round(this.size * 1.5);
+}
View
236 Src/Graphics/Pixel.Image.js
@@ -1,137 +1,125 @@
-if(!Pixel) {
- var Pixel = {};
- if(!px) var px = Pixel;
-}
-
//-------------------------------------------------------
-//-------------------------------------------------------
-//Image Class
-Pixel.Image = new Class({
- Extends:Pixel.Object,
-
- image:null,
-
- canvas:null,
- ctx:null,
-
- imageData:null,
- pixels:null,
-
- bAllocated:false,
- bLoaded:false,
- size: {
- width:0,
- height:0
- },
-
-
- //-------------------------------------------------------
- initialize:function(url) {
- if(url != undefined) {
- this.load(url);
- }
- },
-
-
- //-------------------------------------------------------
- load:function(url) {
- this.clear();
- this.image = new Asset.image(url, {
- onLoad:function() {
- this.bLoaded = true;
-
- //Get Size of Image
- this.setSize(this.image.width, this.image.height);
- }.bind(this),
-
- onError: function() {
- console.log("Could not load image from '" + url + "'");
- }
- });
- },
-
-
- //-------------------------------------------------------
- isLoaded:function() {
- return this.bLoaded;
- },
-
+//Pixel.Image.js
+//Forloading, storing, manipulating, etc
+
+Pixel.Image = function(url) {
+ Pixel.Object.call(this);
- //-------------------------------------------------------
- clear:function() {
- this.bLoaded = false;
- this.pixels = null;
- this.imageData = null;
- this.image = null;
- },
+ if(url != undefined) this.load(url);
+ this.bAllocated = false;
+}
+
+Pixel.Image.prototype = new Pixel.Object();
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.load = function(src) {
+ this.clear();
- //-------------------------------------------------------
- setSize:function(width, height) {
- this.parent(width,height);
-
- if(this.bAllocated == false) {
- //Get Canvas Ref
- this.canvas = new Element('canvas');
- this.ctx = this.canvas.getContext('2d');
- this.imageData = this.ctx.getImageData(0,0,this.getWidth(), this.getHeight());
- }
+ this.image = new Image();
+ var self = this;
+ this.image.addEventListener("load", function() {
+ self.bLoaded = true;
- this.canvas.set({
- width:this.size.width,
- height:this.size.height
- });
- },
-
+ //Get Size of Image
+ self.setSize(this.width, this.height);
+ });
- //-------------------------------------------------------
- getImageData: function() {
- return this.imageData;
- },
+ this.image.addEventListener("error", function() {
+ console.log("Could not load image from '" + url + "'");
+ });
- //-------------------------------------------------------
- getPixels:function() {
- if(this.bLoaded) {
- this.ctx.drawImage(this.image, 0,0);
- this.imageData = this.ctx.getImageData(0,0,this.size.width, this.size.height)
- this.pixels = this.imageData.data;
- return this.pixels;
- }
- return null;
- },
+ this.image.src = src;
+};
+
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.isLoaded = function() {
+ return this.bLoaded;
+};
+
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.clear = function() {
+ this.bLoaded = false;
+ this.pixels = null;
+ this.imageData = null;
+ this.image = null;
+};
+
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.setSize = function(width, height) {
+ Pixel.Object.prototype.setSize.call(this, width,height);
+
+ if(this.bAllocated == false) {
+ //Get Canvas Ref
+ this.canvas = document.createElement('canvas');
+ this.ctx = this.canvas.getContext('2d');
+ this.imageData = this.ctx.getImageData(0,0,this.getWidth(), this.getHeight());
+ }
- //-------------------------------------------------------
- setFromPixels:function(pixels, width, height){
- this.clear();
-
- //Resize the Canvas, get the new image data obj
- this.setSize(width, height);
- this.imageData = this.ctx.getImageData(0,0,this.size.width, this.size.height);
+ this.canvas.setAttribute("width", this.width);
+ this.canvas.setAttribute("height", this.height);
+};
+
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.getImageData = function() {
+ return this.imageData;
+};
+
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.getPixels = function() {
+ if(this.bLoaded) {
+ this.ctx.drawImage(this.image, 0,0);
+ this.imageData = this.ctx.getImageData(0,0,this.size.width, this.size.height)
this.pixels = this.imageData.data;
-
- //Copy pixels into image data
- var i=pixels.length;
- while(i--) this.pixels[i] = pixels[i];
-
- //Draw Data back into the canvas object
- this.ctx.putImageData(this.imageData, 0,0);
-
- //Store info as an IMG, drawing using drawImage() is WAY faster than putImageData()
- this.image = new Element("img");
- this.image.addEvent("load", function() {
- this.image.removeEvent("load");
- this.bLoaded = true;
- }.bind(this));
-
- this.image.src = this.canvas.toDataURL("image/png");
- },
-
-
- //-------------------------------------------------------
- draw:function(pxCanvas, x, y) {
- pxCanvas.drawImage(this, x,y);
+ return this.pixels;
}
-});
+ return null;
+};
+
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.setFromPixels = function(pixels, width, height){
+ this.clear();
+
+ //Resize the Canvas, get the new image data obj
+ this.setSize(width, height);
+ this.imageData = this.ctx.getImageData(0,0,this.size.width, this.size.height);
+ this.pixels = this.imageData.data;
+
+ //Copy pixels into image data
+ var i=pixels.length;
+ while(i--) this.pixels[i] = pixels[i];
+
+ //Draw Data back into the canvas object
+ this.ctx.putImageData(this.imageData, 0,0);
+
+ //Store info as an IMG, drawing using drawImage() is WAY faster than putImageData()
+ this.image = new Element("img");
+ this.image.addEvent("load", function() {
+ this.image.removeEvent("load");
+ this.bLoaded = true;
+ }.bind(this));
+
+ this.image.src = this.canvas.toDataURL("image/png");
+};
+
+
+//-------------------------------------------------------
+Pixel.Image.prototype.draw = function(pxCanvas, x, y) {
+ pxCanvas.drawImage(this, x,y);
+};
View
246 Src/Graphics/Pixel.Object.js
@@ -1,148 +1,142 @@
//-------------------------------------------------------
//-------------------------------------------------------
//Main Object
-if(!Pixel) {
- var Pixel = {};
- if(!px) var px = Pixel;
-}
-Pixel.Object = new Class({
- bInitPressed:false,
- bPressed:false,
- pos: {
+Pixel.Object = function() {
+ this.bInitPressed = false;
+ this.bPressed = false;
+
+ this.pos = {
x:0,
y:0
- },
-
- width:0,
- height:0,
-
- radius:0,
-
- shapeMode: Pixel.OBJECT_SHAPE_RECT,
-
- tween: null,
-
- rect:new Pixel.Rectangle,
-
- //-------------------------------------------------------
- initialize:function() {
- },
-
- //-------------------------------------------------------
- show:function(args) {
-
- },
-
- //-------------------------------------------------------
- hide:function() {
- },
-
- //-------------------------------------------------------
- setPos:function(x,y, bTween) {
- if(Pixel.isSet(x)) this.pos.x = x;
- if(Pixel.isSet(y)) this.pos.y = y;
-
- this.setRect();
- },
-
-
- //-------------------------------------------------------
- getPos: function() {
- return this.pos;
- },
-
-
- //-------------------------------------------------------
- setSize:function(width, height) {
- if(Pixel.isSet(width)) this.width = width;
- if(Pixel.isSet(height)) this.height = height;
-
- this.setRect();
- },
-
- //-------------------------------------------------------
- //Set Rect, for touches, can be overridden for cases like textfields (alignment + baseline issues)
- setRect: function() {
- this.rect.set(this.pos.x, this.pos.y, this.width, this.height);
- },
-
-
- //-------------------------------------------------------
- getRect: function() {
- return this.rect;
- },
-
-
- //-------------------------------------------------------
- getWidth:function() {
- return this.width;
- },
-
+ }
- //-------------------------------------------------------
- getHeight:function() {
- return this.height
- },
+ this.width = 0;
+ this.height = 0;
+ this.radius = 0;
- //-------------------------------------------------------
- setShapeMode: function(shapeMode) {
- this.shapeMode = shapeMode;
- },
+ this.shapeMode = Pixel.OBJECT_SHAPE_RECT;
- //-------------------------------------------------------
- //Event Listeners
+ this.rect = new Pixel.Rectangle();
+}
+
+
+//-------------------------------------------------------
+Pixel.Object.prototype.show = function() {
+},
+
+
+//-------------------------------------------------------
+Pixel.Object.prototype.hide = function() {
+},
+
+
+//-------------------------------------------------------
+Pixel.Object.prototype.setPos = function(x,y) {
+ if(Pixel.isSet(x)) this.pos.x = x;
+ if(Pixel.isSet(y)) this.pos.y = y;
- //-------------------------------------------------------
- isPressed: function() {
- return this.bPressed;
- },
+ this.setRect();
+},
+
+