(function(){this.Processing=function Processing(aElement,aCode){if(typeof aElement=="string"){aElement=document.getElementById(aElement);} var p=buildProcessing(aElement);if(aCode){p.init(aCode);} return p;};var ajax=function(url){var AJAX;if(AJAX=new XMLHttpRequest()){AJAX.open("GET",url,false);AJAX.send(null);return AJAX.responseText;}else{return false;}};var init=function(){var canvas=document.getElementsByTagName('canvas'),datasrc=undefined;for(var i=0;l=i"+(typeof last=="string"?last:name+"(");} var matchClasses=/(?:public |abstract |static )*class (\w+)\s*(?:extends\s*(\w+)\s*)?{\s*((?:.|\n)*?)\b\1\s*\(/g;var matchNoCon=/(?:public |abstract |static )*class (\w+)\s*(?:extends\s*(\w+)\s*)?{\s*((?:.|\n)*?)(Processing)/g;aCode=aCode.replace(matchClasses,ClassReplace);aCode=aCode.replace(matchNoCon,ClassReplace);var matchClass=//,m;while((m=aCode.match(matchClass))){var left=RegExp.leftContext,allRest=RegExp.rightContext,rest=nextBrace(allRest),className=m[1],staticVars=m[2]||"";allRest=allRest.slice(rest.length+1);rest=rest.replace(new RegExp("\\b"+className+"\\(([^\\)]*?)\\)\\s*{","g"),function(all,args){args=args.split(/,\s*?/);if(args[0].match(/^\s*$/)){args.shift();} var fn="if ( arguments.length == "+args.length+" ) {\n";for(var i=0;i=0){aColor=p.color(aValue1,aValue1,aValue1,opacityRange);}else if(typeof aValue1=="number"){var intcolor=0;if(aValue1<0){intcolor=4294967296-(aValue1*-1);}else{intcolor=aValue1;} var ac=Math.floor((intcolor%4294967296)/16777216);var rc=Math.floor((intcolor%16777216)/65536);var gc=Math.floor((intcolor%65536)/256);var bc=intcolor%256;aColor=p.color(rc,gc,bc,ac);}else{aColor=p.color(redRange,greenRange,blueRange,opacityRange);} function HSBtoRGB(h,s,b){h=(h/redRange)*360;s=(s/greenRange)*100;b=(b/blueRange)*100;var br=Math.round(b/100*255);if(s==0){return[br,br,br];}else{var hue=h%360;var f=hue%60;var p=Math.round((b*(100-s))/10000*255);var q=Math.round((b*(6000-s*f))/600000*255);var t=Math.round((b*(6000-s*(60-f)))/600000*255);switch(Math.floor(hue/60)){case 0:return[br,t,p];case 1:return[q,br,p];case 2:return[p,br,t];case 3:return[p,q,br];case 4:return[t,p,br];case 5:return[br,p,q];}}} function getColor(aValue,range){return Math.round(255*(aValue/range));} return aColor;} p.red=function(aColor){return parseInt(verifyChannel(aColor).slice(5));};p.green=function(aColor){return parseInt(verifyChannel(aColor).split(",")[1]);};p.blue=function(aColor){return parseInt(verifyChannel(aColor).split(",")[2]);};p.alpha=function(aColor){return parseInt(parseFloat(verifyChannel(aColor).split(",")[3])*255);};function verifyChannel(aColor){if(aColor.constructor==Array){return aColor;}else{return p.color(aColor);}} p.lerpColor=function lerpColor(c1,c2,amt){var colors1=p.color(c1).split(",");var r1=parseInt(colors1[0].split("(")[1]);var g1=parseInt(colors1[1]);var b1=parseInt(colors1[2]);var a1=parseFloat(colors1[3].split(")")[0]);var colors2=p.color(c2).split(",");var r2=parseInt(colors2[0].split("(")[1]);var g2=parseInt(colors2[1]);var b2=parseInt(colors2[2]);var a2=parseFloat(colors2[3].split(")")[0]);var r=parseInt(p.lerp(r1,r2,amt));var g=parseInt(p.lerp(g1,g2,amt));var b=parseInt(p.lerp(b1,b2,amt));var a=parseFloat(p.lerp(a1,a2,amt));return aColor="rgba("+r+","+g+","+b+","+a+")";} p.DefaultColor=function(aValue1,aValue2,aValue3){var tmpColorMode=curColorMode;curColorMode=p.RGB;var c=p.color(aValue1/255*redRange,aValue2/255*greenRange,aValue3/255*blueRange);curColorMode=tmpColorMode;return c;} p.colorMode=function colorMode(mode,range1,range2,range3,range4){curColorMode=mode;if(arguments.length>=4){redRange=range1;greenRange=range2;blueRange=range3;} if(arguments.length==5){opacityRange=range4;} if(arguments.length==2){p.colorMode(mode,range1,range1,range1,range1);}};p.translate=function translate(x,y){curContext.translate(x,y);};p.scale=function scale(x,y){curContext.scale(x,y||x);};p.rotate=function rotate(aAngle){curContext.rotate(aAngle);};p.pushMatrix=function pushMatrix(){curContext.save();};p.popMatrix=function popMatrix(){curContext.restore();};p.ortho=function ortho(){};p.year=function year(){return(new Date).getYear()+1900;};p.month=function month(){return(new Date).getMonth();};p.day=function day(){return(new Date).getDay();};p.hour=function hour(){return(new Date).getHours();};p.minute=function minute(){return(new Date).getMinutes();};p.second=function second(){return(new Date).getSeconds();};p.millis=function millis(){return(new Date).getTime()-start;};p.noLoop=function noLoop(){doLoop=false;};p.redraw=function redraw(){if(hasBackground){p.background();} p.frameCount++;inDraw=true;p.pushMatrix();p.draw();p.popMatrix();inDraw=false;};p.loop=function loop(){if(loopStarted){return;} looping=setInterval(function(){try{p.focused=document.hasFocus();p.redraw();} catch(e){clearInterval(looping);throw e;}},curMsPerFrame);loopStarted=true;};p.frameRate=function frameRate(aRate){curFrameRate=aRate;curMsPerFrame=1000/curFrameRate;};p.exit=function exit(){clearInterval(looping);};p.cursor=function(mode){document.body.style.cursor=mode;} p.link=function(href,target){window.location=href;};p.beginDraw=function beginDraw(){};p.endDraw=function endDraw(){};p.ajax=ajax;p.Import=function Import(lib){eval(p.ajax(lib));} p.unbinary=function unbinary(binaryString){var binaryPattern=new RegExp("^[0|1]{8}$");var addUp=0;if(isNaN(binaryString)){throw"NaN_Err";}else{if(arguments.length==1||binaryString.length==8){if(binaryPattern.test(binaryString)){for(i=0;i<8;i++){addUp+=(Math.pow(2,i)*parseInt(binaryString.charAt(7-i)));} return addUp+"";}else{throw"notBinary: the value passed into unbinary was not an 8 bit binary number";};}else{throw"longErr";};};return addUp;} p.nfs=function(num,left,right){var str;if(typeof num=="object"){str=new Array();len=num.length;for(var i=0;i0){str="0"+str;count--;} var decimals=(""+Math.abs(num)).length-digits-1;if(decimals==-1&&right>0) str=str+".";if(decimals!=-1) count=right-decimals;else if(decimals==-1&&right>0){count=right;} else count=0;while(count>0){str=str+"0";count--;} str=(negative?"-":" ")+str;} else if(arguments.length==2){str=p.nfs(num,left,0);} return str;} p.RGB2HTML=function RGB2HTML(red,green,blue){var char="0123456789ABCDEF";return String(char.charAt(Math.floor(rgb/16)))+String(char.charAt(rgb-(Math.floor(rgb/16)*16)));} p.decimalToHex=function decimalToHex(d,padding){padding=typeof(padding)==="undefined"||padding===null?padding=8:padding;var hex=Number(d).toString(16);while(hex.length=0;i--){try{switch(str[i]){case"0":num=0;break;case"1":num=1;break;case"2":num=2;break;case"3":num=3;break;case"4":num=4;break;case"5":num=5;break;case"6":num=6;break;case"7":num=7;break;case"8":num=8;break;case"9":num=9;break;case"A":case"a":num=10;break;case"B":case"b":num=11;break;case"C":case"c":num=12;break;case"D":case"d":num=13;break;case"E":case"e":num=14;break;case"F":case"f":num=15;break;default:return 0;break;} value+=num*multiplier;multiplier*=16;}catch(e){;} if(value>2147483647) {value-=4294967296;}} return value;} p.loadStrings=function loadStrings(url){return p.ajax(url).split("\n");};p.nf=function(num,pad){var str=""+num;while(pad-str.length){str="0"+str;} return str;};p.nfp=function nfp(Value,pad,right){var str=String(Value);if(arguments.length<3){if(Value>0){while(str.length0){var strL=str.slice(0,decimalPos);var strR=str.slice(decimalPos+1,str.length);while(strL.length1){Caller!="print"?p.ln=arguments:p.ln=arguments[0];}else{p.ln=arguments[0];} Caller=="print"?p.printed(arguments):p.lnPrinted();}};p.str=function str(aNumber){return aNumber+'';} p.print=function print(){p.println(arguments[0])};p.char=function char(key){return key;};p.sq=function sq(aNumber){return aNumber*aNumber;};p.sqrt=function sqrt(aNumber){return Math.sqrt(aNumber);};p.int=function int(aNumber){return Math.floor(aNumber);};p.min=function min(aNumber,aNumber2){return Math.min(aNumber,aNumber2);};p.max=function max(aNumber,aNumber2){return Math.max(aNumber,aNumber2);};p.floor=function floor(aNumber){return Math.floor(aNumber);};p.float=function float(aNumber){return parseFloat(aNumber);};p.ceil=function ceil(aNumber){return Math.ceil(aNumber);};p.round=function round(aNumber){return Math.round(aNumber);};p.lerp=function lerp(value1,value2,amt){return((value2-value1)*amt)+value1;};p.abs=function abs(aNumber){return Math.abs(aNumber);};p.cos=function cos(aNumber){return Math.cos(aNumber);};p.sin=function sin(aNumber){return Math.sin(aNumber);};p.pow=function pow(aNumber,aExponent){return Math.pow(aNumber,aExponent);};p.sqrt=function sqrt(aNumber){return Math.sqrt(aNumber);};p.atan2=function atan2(aNumber,aNumber2){return Math.atan2(aNumber,aNumber2);};p.radians=function radians(aAngle){return(aAngle/180)*p.PI;};p.dist=function dist(x1,y1,x2,y2){return Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));};p.map=function map(value,istart,istop,ostart,ostop){return ostart+(ostop-ostart)*((value-istart)/(istop-istart));};p.mag=function(a,b,c){if(arguments.length==2){return Math.sqrt(a*a+b*b);}else if(arguments.length==3){return Math.sqrt(a*a+b*b+c*c);};};p.Random=function(){var haveNextNextGaussian=false,nextNextGaussian;this.nextGaussian=function(){if(haveNextNextGaussian){haveNextNextGaussian=false;return nextNextGaussian;}else{var v1,v2,s;do{v1=2*p.random(1)-1;v2=2*p.random(1)-1;s=v1*v1+v2*v2;} while(s>=1||s==0);var multiplier=Math.sqrt(-2*Math.log(s)/s);nextNextGaussian=v2*multiplier;haveNextNextGaussian=true;return v1*multiplier;}};};p.byte=function byte(aNumber){return aNumber||0;};p.norm=function norm(aNumber,low,high){var range=high-low;return((1/range)*aNumber)-((1/range)*low);};p.random=function random(aMin,aMax){return arguments.length==2?aMin+(Math.random()*(aMax-aMin)):Math.random()*aMin;};p.noise=function(x,y,z){return arguments.length>=2?PerlinNoise_2D(x,y,z):PerlinNoise_3D(x,x,z);};function Noise(x,y){var n=x+y*57;n=(n<<13)^n;return Math.abs(1.0-(((n*((n*n*15731)+789221)+1376312589)&0x7fffffff)/1073741824.0));};function SmoothedNoise(x,y){var corners=(Noise(x-1,y-1)+Noise(x+1,y-1)+Noise(x-1,y+1)+Noise(x+1,y+1))/16,sides=(Noise(x-1,y)+Noise(x+1,y)+Noise(x,y-1)+Noise(x,y+1))/8,center=Noise(x,y)/4;return corners+sides+center;};function InterpolatedNoise(x,y){var integer_X=Math.floor(x);var fractional_X=x-integer_X;var integer_Y=Math.floor(y);var fractional_Y=y-integer_Y;var v1=SmoothedNoise(integer_X,integer_Y),v2=SmoothedNoise(integer_X+1,integer_Y),v3=SmoothedNoise(integer_X,integer_Y+1),v4=SmoothedNoise(integer_X+1,integer_Y+1);var i1=Interpolate(v1,v2,fractional_X),i2=Interpolate(v3,v4,fractional_X);return Interpolate(i1,i2,fractional_Y);} function PerlinNoise_2D(x,y){var total=0,p=0.25,n=3;for(var i=0;i<=n;i++){var frequency=Math.pow(2,i);var amplitude=Math.pow(p,i);total+=InterpolatedNoise(x*frequency,y*frequency)*amplitude;} return total;} function Interpolate(a,b,x){var ft=x*p.PI;var f=(1-Math.cos(ft))*.5;return a*(1-f)+b*f;} p.constrain=function constrain(aNumber,aMin,aMax){return Math.min(Math.max(aNumber,aMin),aMax);};p.degrees=function degrees(aAngle){aAngle=(aAngle*180)/p.PI;if(aAngle<0){aAngle=360+aAngle} return aAngle;};p.size=function size(aWidth,aHeight){var fillStyle=curContext.fillStyle,strokeStyle=curContext.strokeStyle;curElement.width=p.width=aWidth;curElement.height=p.height=aHeight;curContext.fillStyle=fillStyle;curContext.strokeStyle=strokeStyle;};p.PVector=function PVector(){return new vectorOps(arguments)};p.PVector.add=PVectorAdd;p.PVector.sub=PVectorSub;p.PVector.mult=PVectorMult;p.PVector.div=PVectorDiv;p.PVector.dist=PVectorDist;p.PVector.angleBetween=PVectorAngle;function PVectorAdd(){var a=arguments;return p.PVector(a[0].x+a[1].x,a[0].y+a[1].y,a[0].z+a[1].z);} function PVectorSub(){var a=arguments;return p.PVector(a[0].x-a[1].x,a[0].y-a[1].y,a[0].z-a[1].z);} function PVectorMult(){if(typeof arguments[1]=='number'){var a=arguments;return p.PVector(a[0].x*a[1],a[0].y*a[1],a[0].z*a[1]);}else if(typeof arguments[1]=='object'){var a=arguments;return p.PVector(a[0].x*a[1].x,a[0].y*a[1].y,a[0].z*a[1].z);}} function PVectorDiv(){if(typeof arguments[1]=='number'){var a=arguments;return p.PVector(a[0].x/a[1],a[0].y/a[1],a[0].z/a[1]);} else if(typeof(arguments[1])=='object'){var a=arguments;return p.PVector(a[0].x/a[1].x,a[0].y/a[1].y,a[0].z/a[1].z);}} function PVectorDist(){var v1=new p.PVector();var v2=new p.PVector();v1=arguments[0];v2=arguments[1];return v1.dist(v2);} function PVectorAngle(v1,v2){return Math.acos(v1.dot(v2)/(v1.mag()*v2.mag()));} function vectorOps(){arguments=arguments[0];this.x=arguments[0]||0;this.y=arguments[1]||0;this.z=arguments[2]||0;this.set=function(){if(arguments.length==1){var vArr=arguments[0];this.set(arguments[0].x||vArr[0],arguments[0].y||vArr[1],arguments[0].z||vArr[2]);}else{this.x=arguments[0];this.y=arguments[1];this.z=arguments[2];};};this.get=function get(){return p.PVector(this.x,this.y,this.z)};this.mag=function mag(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)};this.add=function(){if(arguments.length==3){this.x+=arguments[0];this.y+=arguments[1];this.z+=arguments[2];}else if(arguments.length==1){this.x+=arguments[0].x;this.y+=arguments[0].y;this.z+=arguments[0].z;};};this.sub=function(){if(arguments.length==3){this.x-=arguments[0];this.y-=arguments[1];this.z-=arguments[2];}else if(arguments.length==1){this.x-=arguments[0].x;this.y-=arguments[0].y;this.z-=arguments[0].z;};};this.mult=function(){if(typeof arguments[0]=='number'){this.x*=arguments[0];this.y*=arguments[0];this.z*=arguments[0];}else if(typeof arguments[0]=='object'){this.x*=arguments[0].x;this.y*=arguments[0].y;this.z*=arguments[0].z;};};this.div=function(){if(typeof arguments[0]=='number'){this.x/=arguments[0];this.y/=arguments[0];this.z/=arguments[0];}else if(typeof arguments[0]=='object'){this.x/=arguments[0].x;this.y/=arguments[0].y;this.z/=arguments[0].z;};};this.dist=function(){var v=new p.PVector();v=arguments[0];var dx=this.x-v.x;var dy=this.y-v.y;var dz=this.z-v.z;return Math.sqrt(dx*dx+dy*dy+dz*dz);};this.dot=function dot(){var num;if(arguments.length==3){num=this.x*arguments[0]+this.y*arguments[1]+this.z*arguments[2];}else if(arguments.length==2){var v1=new p.PVector();var v2=new p.PVector();v1=arguments[0];v2=arguments[1];num=v1.dot(v2);}else if(arguments.length==1){var v=new p.PVector();v=arguments[0];num=this.x*v.x+this.y*v.y+this.z*v.z;};return num;};this.cross=function cross(){var crossX,crossY,crossZ;var v=new p.PVector();v=arguments[0];crossX=this.y*v.z-v.y*this.z;crossY=this.z*v.x-v.z*this.x;crossZ=this.x*v.y-v.x*this.y;return p.PVector(crossX,crossY,crossZ);};this.normalize=function normalize(){var m=this.mag();console.log(m);if(m>0){this.div(m)};};this.limit=function limit(high){if(this.mag()>high){this.normalize();this.mult(high);};};this.angleBetween=function(){PVectorAngle.call(this,arguments);};this.array=function array(){var vArray=new Array(3);vArray[0]=this.x;vArray[1]=this.y;vArray[2]=this.z;return vArray;};} p.noStroke=function noStroke(){doStroke=false;};p.noFill=function noFill(){doFill=false;};p.smooth=function smooth(){};p.noSmooth=function noSmooth(){};p.fill=function fill(){doFill=true;curContext.fillStyle=p.color.apply(this,arguments);};p.stroke=function stroke(){doStroke=true;curContext.strokeStyle=p.color.apply(this,arguments);};p.strokeWeight=function strokeWeight(w){curContext.lineWidth=w;};p.Point=function Point(x,y){this.x=x;this.y=y;this.copy=function(){return new Point(x,y);}};p.point=function point(x,y){var oldFill=curContext.fillStyle;curContext.fillStyle=curContext.strokeStyle;curContext.fillRect(Math.round(x),Math.round(y),1,1);curContext.fillStyle=oldFill;};p.beginShape=function beginShape(type){curShape=type;curShapeCount=0;curvePoints=[];};p.endShape=function endShape(close){if(curShapeCount!=0){if(close||doFill){curContext.lineTo(firstX,firstY);} if(doFill){curContext.fill();} if(doStroke){curContext.stroke();} curContext.closePath();curShapeCount=0;pathOpen=false;} if(pathOpen){if(doFill){curContext.fill();} if(doStroke){curContext.stroke();} curContext.closePath();curShapeCount=0;pathOpen=false;}};p.vertex=function vertex(x,y,x2,y2,x3,y3){if(curShapeCount==0&&curShape!=p.POINTS){pathOpen=true;curContext.beginPath();curContext.moveTo(x,y);firstX=x;firstY=y;}else{if(curShape==p.POINTS){p.point(x,y);}else if(arguments.length==2){if(curShape!=p.QUAD_STRIP||curShapeCount!=2){curContext.lineTo(x,y);} if(curShape==p.TRIANGLE_STRIP){if(curShapeCount==2){p.endShape(p.CLOSE);pathOpen=true;curContext.beginPath();curContext.moveTo(prevX,prevY);curContext.lineTo(x,y);curShapeCount=1;} firstX=prevX;firstY=prevY;} if(curShape==p.TRIANGLE_FAN&&curShapeCount==2){p.endShape(p.CLOSE);pathOpen=true;curContext.beginPath();curContext.moveTo(firstX,firstY);curContext.lineTo(x,y);curShapeCount=1;} if(curShape==p.QUAD_STRIP&&curShapeCount==3){curContext.lineTo(prevX,prevY);p.endShape(p.CLOSE);pathOpen=true;curContext.beginPath();curContext.moveTo(prevX,prevY);curContext.lineTo(x,y);curShapeCount=1;} if(curShape==p.QUAD_STRIP){firstX=secondX;firstY=secondY;secondX=prevX;secondY=prevY;}}else if(arguments.length==4){if(curShapeCount>1){curContext.moveTo(prevX,prevY);curContext.quadraticCurveTo(firstX,firstY,x,y);curShapeCount=1;}}else if(arguments.length==6){curContext.bezierCurveTo(x,y,x2,y2,x3,y3);}} prevX=x;prevY=y;curShapeCount++;if(curShape==p.LINES&&curShapeCount==2||(curShape==p.TRIANGLES)&&curShapeCount==3||(curShape==p.QUADS)&&curShapeCount==4){p.endShape(p.CLOSE);}};p.curveVertex=function(x,y,x2,y2){if(curvePoints.length<3){curvePoints.push([x,y]);}else{var b=[],s=1-curTightness;curvePoints.push([x,y]);b[0]=[curvePoints[1][0],curvePoints[1][1]];b[1]=[curvePoints[1][0]+(s*curvePoints[2][0]-s*curvePoints[0][0])/6,curvePoints[1][1]+(s*curvePoints[2][1]-s*curvePoints[0][1])/6];b[2]=[curvePoints[2][0]+(s*curvePoints[1][0]-s*curvePoints[3][0])/6,curvePoints[2][1]+(s*curvePoints[1][1]-s*curvePoints[3][1])/6];b[3]=[curvePoints[2][0],curvePoints[2][1]];if(!pathOpen){p.vertex(b[0][0],b[0][1]);}else{curShapeCount=1;} p.vertex(b[1][0],b[1][1],b[2][0],b[2][1],b[3][0],b[3][1]);curvePoints.shift();}};p.curveTightness=function(tightness){curTightness=tightness;};p.bezierVertex=p.vertex;p.rectMode=function rectMode(aRectMode){curRectMode=aRectMode;};p.imageMode=function(){};p.ellipseMode=function ellipseMode(aEllipseMode){curEllipseMode=aEllipseMode;};p.arc=function arc(x,y,width,height,start,stop){if(width<=0){return;} if(curEllipseMode==p.CORNER){x+=width/2;y+=height/2;} curContext.moveTo(x,y);curContext.beginPath();curContext.arc(x,y,curEllipseMode==p.CENTER_RADIUS?width:width/2,start,stop,false);if(doStroke){curContext.stroke();} curContext.lineTo(x,y);if(doFill){curContext.fill();} curContext.closePath();};p.line=function line(x1,y1,x2,y2){curContext.lineCap="round";curContext.beginPath();curContext.moveTo(x1||0,y1||0);curContext.lineTo(x2||0,y2||0);curContext.stroke();curContext.closePath();};p.bezier=function bezier(x1,y1,x2,y2,x3,y3,x4,y4){curContext.lineCap="butt";curContext.beginPath();curContext.moveTo(x1,y1);curContext.bezierCurveTo(x2,y2,x3,y3,x4,y4);curContext.stroke();curContext.closePath();};p.triangle=function triangle(x1,y1,x2,y2,x3,y3){p.beginShape();p.vertex(x1,y1);p.vertex(x2,y2);p.vertex(x3,y3);p.endShape();};p.quad=function quad(x1,y1,x2,y2,x3,y3,x4,y4){curContext.lineCap="square";p.beginShape();p.vertex(x1,y1);p.vertex(x2,y2);p.vertex(x3,y3);p.vertex(x4,y4);p.endShape();};p.rect=function rect(x,y,width,height){if(!(width+height)){return;} curContext.beginPath();var offsetStart=0;var offsetEnd=0;if(curRectMode==p.CORNERS){width-=x;height-=y;} if(curRectMode==p.RADIUS){width*=2;height*=2;} if(curRectMode==p.CENTER||curRectMode==p.RADIUS){x-=width/2;y-=height/2;} curContext.rect(Math.round(x)-offsetStart,Math.round(y)-offsetStart,Math.round(width)+offsetEnd,Math.round(height)+offsetEnd);if(doFill){curContext.fill();} if(doStroke){curContext.stroke()};curContext.closePath();};p.ellipse=function ellipse(x,y,width,height){x=x||0;y=y||0;if(width<=0&&height<=0){return;} curContext.beginPath();if(curEllipseMode==p.RADIUS){width*=2;height*=2;} var offsetStart=0;if(width==height){curContext.arc(x-offsetStart,y-offsetStart,width/2,0,p.TWO_PI,false);}else{var w=width/2,h=height/2,C=0.5522847498307933;var c_x=C*w,c_y=C*h;curContext.moveTo(x+w,y);curContext.bezierCurveTo(x+w,y-c_y,x+c_x,y-h,x,y-h);curContext.bezierCurveTo(x-c_x,y-h,x-w,y-c_y,x-w,y);curContext.bezierCurveTo(x-w,y+c_y,x-c_x,y+h,x,y+h);curContext.bezierCurveTo(x+c_x,y+h,x+w,y+c_y,x+w,y);} if(doFill){curContext.fill();} if(doStroke){curContext.stroke();} curContext.closePath();};p.save=function save(file){};p.loadImage=function loadImage(file,type,callback){var img=document.createElement('img');img.src=file;img.onload=function(){var h=this.height,w=this.width;var canvas=document.createElement("canvas");canvas.width=w;canvas.height=h;var context=canvas.getContext("2d");context.drawImage(this,0,0);this.data=buildImageObject(context.getImageData(0,0,w,h));this.data.img=img;callback?callback():0;} return img;};p.get=function get(x,y){if(!arguments.length){var c=p.createGraphics(p.width,p.height);c.image(curContext,0,0);return c;} if(!getLoaded){getLoaded=buildImageObject(curContext.getImageData(0,0,p.width,p.height));} return getLoaded.get(x,y);};p.createGraphics=function createGraphics(w,h){var canvas=document.createElement("canvas");var ret=buildProcessing(canvas);ret.size(w,h);ret.canvas=canvas;return ret;};p.set=function set(x,y,obj){if(obj&&obj.img){p.image(obj,x,y);}else{var oldFill=curContext.fillStyle,color=obj;curContext.fillStyle=color;curContext.fillRect(Math.round(x),Math.round(y),1,1);curContext.fillStyle=oldFill;}};p.loadPixels=function(){p.pixels=buildImageObject(curContext.getImageData(0,0,p.width,p.height)).pixels;};p.updatePixels=function(){var colors=/(\d+),(\d+),(\d+),(\d+)/,pixels={};pixels.width=p.width;pixels.height=p.height;pixels.data=[];if(curContext.createImageData){pixels=curContext.createImageData(p.width,p.height);} var data=pixels.data,pos=0;for(var i=0,l=p.pixels.length;i=frames){this.pos=0;}};this.getWidth=function(){return getImage_old(this.images[0]).width;};this.getHeight=function(){return getImage_old(this.images[0]).height;};};function buildImageObject(obj){var pixels=obj.data;var data=p.createImage(obj.width,obj.height);if(data.__defineGetter__&&data.__lookupGetter__&&!data.__lookupGetter__("pixels")){var pixelsDone;data.__defineGetter__("pixels",function(){if(pixelsDone){return pixelsDone;} pixelsDone=[];for(var i=0;i=0){var oldAlpha=curContext.globalAlpha;curContext.globalAlpha=curTint/opacityRange;} if(arguments.length==3){curContext.drawImage(obj,x,y);}else{curContext.drawImage(obj,x,y,w,h);} if(curTint>=0){curContext.globalAlpha=oldAlpha;} if(img._mask){var oldComposite=curContext.globalCompositeOperation;curContext.globalCompositeOperation="darker";p.image(img._mask,x,y);curContext.globalCompositeOperation=oldComposite;}};p.image=function image(img,x,y,w,h){if(img.data||img.canvas){x=x||0;y=y||0;var obj=getImage(img.data||img.canvas);if(curTint>=0){var oldAlpha=curContext.globalAlpha;curContext.globalAlpha=curTint/opacityRange;} if(arguments.length==3){curContext.drawImage(obj,x,y);}else{curContext.drawImage(obj,x,y,w,h);} if(curTint>=0){curContext.globalAlpha=oldAlpha;} if(img._mask){var oldComposite=curContext.globalCompositeOperation;curContext.globalCompositeOperation="darker";p.image(img._mask,x,y);curContext.globalCompositeOperation=oldComposite;}} if(typeof img=='string'){}};p.clear=function clear(x,y,width,height){if(arguments.length==0){curContext.clearRect(0,0,p.width,p.height);}else{curContext.clearRect(x,y,width,height);}} p.tint=function tint(rgb,a){curTint=a;};p.loadFont=function loadFont(name){if(name.indexOf(".svg")==-1){return{name:name,width:function(str){if(curContext.mozMeasureText){return curContext.mozMeasureText(typeof str=="number"?String.fromCharCode(str):str)/curTextSize;}else{return 0;}}};}else{var font=p.loadGlyphs(name);return{name:name,glyph:true,units_per_em:font.units_per_em,horiz_adv_x:1/font.units_per_em*font.horiz_adv_x,ascent:font.ascent,descent:font.descent,width:function(str){var width=0;var len=str.length;for(var i=0;i":return font["greater"];break;case"?":return font["question"];break;case"@":return font["at"];break;case"[":return font["bracketleft"];break;case"\\":return font["backslash"];break;case"]":return font["bracketright"];break;case"^":return font["asciicircum"];break;case"`":return font["grave"];break;case"{":return font["braceleft"];break;case"|":return font["bar"];break;case"}":return font["braceright"];break;case"~":return font["asciitilde"];break;default:return font[chr];break;}}catch(e){;}} p.text=function text(str,x,y){if(!curTextFont.glyph){if(str&&curContext.mozDrawText){curContext.save();curContext.mozTextStyle=curTextSize+"px "+curTextFont.name;curContext.translate(x,y);curContext.mozDrawText(typeof str=="number"?String.fromCharCode(str):str);curContext.restore();}}else{var font=p.glyphTable[curTextFont.name];curContext.save();curContext.translate(x,y+curTextSize);var upem=font["units_per_em"],newScale=1/upem*curTextSize;curContext.scale(newScale,newScale);var len=str.length;for(var i=0;i