-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathglow.0.7.min.js
More file actions
6 lines (6 loc) · 147 KB
/
Copy pathglow.0.7.min.js
File metadata and controls
6 lines (6 loc) · 147 KB
1
2
3
4
5
6
/*This is a combined, compressed file. Look at https://bitbucket.org/davidscherer/glowscript for source code and copyright information.*/(function(){})(),function(a){function c(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,f=!0,g=0,h=0;return b=a.event.fix(c),b.type="mousewheel",b.wheelDelta&&(e=b.wheelDelta/120),b.detail&&(e=-b.detail/3),h=e,c.axis!==undefined&&c.axis===c.HORIZONTAL_AXIS&&(h=0,g=-1*e),c.wheelDeltaY!==undefined&&(h=c.wheelDeltaY/120),c.wheelDeltaX!==undefined&&(g=-1*c.wheelDeltaX/120),d.unshift(b,e,g,h),a.event.handle.apply(this,d)}var b=["DOMMouseScroll","mousewheel"];a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=b.length;a;)this.addEventListener(b[--a],c,!1);else this.onmousewheel=c},teardown:function(){if(this.removeEventListener)for(var a=b.length;a;)this.removeEventListener(b[--a],c,!1);else this.onmousewheel=null}},a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})}(jQuery),function(a){a.color={},a.color.make=function(b,c,d,e){var f={};return f.r=b||0,f.g=c||0,f.b=d||0,f.a=e!=null?e:1,f.add=function(a,b){for(var c=0;c<a.length;++c)f[a.charAt(c)]+=b;return f.normalize()},f.scale=function(a,b){for(var c=0;c<a.length;++c)f[a.charAt(c)]*=b;return f.normalize()},f.toString=function(){return f.a>=1?"rgb("+[f.r,f.g,f.b].join(",")+")":"rgba("+[f.r,f.g,f.b,f.a].join(",")+")"},f.normalize=function(){function a(a,b,c){return b<a?a:b>c?c:b}return f.r=a(0,parseInt(f.r),255),f.g=a(0,parseInt(f.g),255),f.b=a(0,parseInt(f.b),255),f.a=a(0,f.a,1),f},f.clone=function(){return a.color.make(f.r,f.b,f.g,f.a)},f.normalize()},a.color.extract=function(b,c){var d;do{d=b.css(c).toLowerCase();if(d!=""&&d!="transparent")break;b=b.parent()}while(!a.nodeName(b.get(0),"body"));return d=="rgba(0, 0, 0, 0)"&&(d="transparent"),a.color.parse(d)},a.color.parse=function(c){var d,e=a.color.make;if(d=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return e(parseInt(d[1],10),parseInt(d[2],10),parseInt(d[3],10));if(d=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(c))return e(parseInt(d[1],10),parseInt(d[2],10),parseInt(d[3],10),parseFloat(d[4]));if(d=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return e(parseFloat(d[1])*2.55,parseFloat(d[2])*2.55,parseFloat(d[3])*2.55);if(d=/rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(c))return e(parseFloat(d[1])*2.55,parseFloat(d[2])*2.55,parseFloat(d[3])*2.55,parseFloat(d[4]));if(d=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return e(parseInt(d[1],16),parseInt(d[2],16),parseInt(d[3],16));if(d=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return e(parseInt(d[1]+d[1],16),parseInt(d[2]+d[2],16),parseInt(d[3]+d[3],16));var f=a.trim(c).toLowerCase();return f=="transparent"?e(255,255,255,0):(d=b[f]||[0,0,0],e(d[0],d[1],d[2]))};var b={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}}(jQuery),function(a){function b(b,d,e,f){function x(a,b){b=[w].concat(b);for(var c=0;c<a.length;++c)a[c].apply(this,b)}function y(){for(var b=0;b<f.length;++b){var c=f[b];c.init(w),c.options&&a.extend(!0,h,c.options)}}function z(b){var c;a.extend(!0,h,b),h.xaxis.color==null&&(h.xaxis.color=h.grid.color),h.yaxis.color==null&&(h.yaxis.color=h.grid.color),h.xaxis.tickColor==null&&(h.xaxis.tickColor=h.grid.tickColor),h.yaxis.tickColor==null&&(h.yaxis.tickColor=h.grid.tickColor),h.grid.borderColor==null&&(h.grid.borderColor=h.grid.color),h.grid.tickColor==null&&(h.grid.tickColor=a.color.parse(h.grid.color).scale("a",.22).toString());for(c=0;c<Math.max(1,h.xaxes.length);++c)h.xaxes[c]=a.extend(!0,{},h.xaxis,h.xaxes[c]);for(c=0;c<Math.max(1,h.yaxes.length);++c)h.yaxes[c]=a.extend(!0,{},h.yaxis,h.yaxes[c]);h.xaxis.noTicks&&h.xaxis.ticks==null&&(h.xaxis.ticks=h.xaxis.noTicks),h.yaxis.noTicks&&h.yaxis.ticks==null&&(h.yaxis.ticks=h.yaxis.noTicks),h.x2axis&&(h.xaxes[1]=a.extend(!0,{},h.xaxis,h.x2axis),h.xaxes[1].position="top"),h.y2axis&&(h.yaxes[1]=a.extend(!0,{},h.yaxis,h.y2axis),h.yaxes[1].position="right"),h.grid.coloredAreas&&(h.grid.markings=h.grid.coloredAreas),h.grid.coloredAreasColor&&(h.grid.markingsColor=h.grid.coloredAreasColor),h.lines&&a.extend(!0,h.series.lines,h.lines),h.points&&a.extend(!0,h.series.points,h.points),h.bars&&a.extend(!0,h.series.bars,h.bars),h.shadowSize!=null&&(h.series.shadowSize=h.shadowSize);for(c=0;c<h.xaxes.length;++c)G(o,c+1).options=h.xaxes[c];for(c=0;c<h.yaxes.length;++c)G(p,c+1).options=h.yaxes[c];for(var d in v)h.hooks[d]&&h.hooks[d].length&&(v[d]=v[d].concat(h.hooks[d]));x(v.processOptions,[h])}function A(a){g=B(a),H(),I()}function B(b){var c=[];for(var d=0;d<b.length;++d){var e=a.extend(!0,{},h.series);b[d].data!=null?(e.data=b[d].data,delete b[d].data,a.extend(!0,e,b[d]),b[d].data=e.data):e.data=b[d],c.push(e)}return c}function C(a,b){var c=a[b+"axis"];return typeof c=="object"&&(c=c.n),typeof c!="number"&&(c=1),c}function D(){return a.grep(o.concat(p),function(a){return a})}function E(a){var b={},c,d;for(c=0;c<o.length;++c)d=o[c],d&&d.used&&(b["x"+d.n]=d.c2p(a.left));for(c=0;c<p.length;++c)d=p[c],d&&d.used&&(b["y"+d.n]=d.c2p(a.top));return b.x1!==undefined&&(b.x=b.x1),b.y1!==undefined&&(b.y=b.y1),b}function F(a){var b={},c,d,e;for(c=0;c<o.length;++c){d=o[c];if(d&&d.used){e="x"+d.n,a[e]==null&&d.n==1&&(e="x");if(a[e]!=null){b.left=d.p2c(a[e]);break}}}for(c=0;c<p.length;++c){d=p[c];if(d&&d.used){e="y"+d.n,a[e]==null&&d.n==1&&(e="y");if(a[e]!=null){b.top=d.p2c(a[e]);break}}}return b}function G(b,c){return b[c-1]||(b[c-1]={n:c,direction:b==o?"x":"y",options:a.extend(!0,{},b==o?h.xaxis:h.yaxis)}),b[c-1]}function H(){var b,c=g.length,d=[],e=[];for(b=0;b<g.length;++b){var f=g[b].color;f!=null&&(--c,typeof f=="number"?e.push(f):d.push(a.color.parse(g[b].color)))}for(b=0;b<e.length;++b)c=Math.max(c,e[b]+1);var i=[],j=0;b=0;while(i.length<c){var k;h.colors.length==b?k=a.color.make(100,100,100):k=a.color.parse(h.colors[b]);var l=j%2==1?-1:1;k.scale("rgb",1+l*Math.ceil(j/2)*.2),i.push(k),++b,b>=h.colors.length&&(b=0,++j)}var m=0,n;for(b=0;b<g.length;++b){n=g[b],n.color==null?(n.color=i[m].toString(),++m):typeof n.color=="number"&&(n.color=i[n.color].toString());if(n.lines.show==null){var q,r=!0;for(q in n)if(n[q]&&n[q].show){r=!1;break}r&&(n.lines.show=!0)}n.xaxis=G(o,C(n,"x")),n.yaxis=G(p,C(n,"y"))}}function I(){function t(a,b,c){b<a.datamin&&b!=-d&&(a.datamin=b),c>a.datamax&&c!=d&&(a.datamax=c)}var b=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,d=Number.MAX_VALUE,e,f,h,i,j,k,l,m,n,o,p,q,r,s;a.each(D(),function(a,d){d.datamin=b,d.datamax=c,d.used=!1});for(e=0;e<g.length;++e)k=g[e],k.datapoints={points:[]},x(v.processRawData,[k,k.data,k.datapoints]);for(e=0;e<g.length;++e){k=g[e];var u=k.data,w=k.datapoints.format;if(!w){w=[],w.push({x:!0,number:!0,required:!0}),w.push({y:!0,number:!0,required:!0});if(k.bars.show||k.lines.show&&k.lines.fill)w.push({y:!0,number:!0,required:!1,defaultValue:0}),k.bars.horizontal&&(delete w[w.length-1].y,w[w.length-1].x=!0);k.datapoints.format=w}if(k.datapoints.pointsize!=null)continue;k.datapoints.pointsize=w.length,m=k.datapoints.pointsize,l=k.datapoints.points,insertSteps=k.lines.show&&k.lines.steps,k.xaxis.used=k.yaxis.used=!0;for(f=h=0;f<u.length;++f,h+=m){s=u[f];var y=s==null;if(!y)for(i=0;i<m;++i)q=s[i],r=w[i],r&&(r.number&&q!=null&&(q=+q,isNaN(q)?q=null:q==Infinity?q=d:q==-Infinity&&(q=-d)),q==null&&(r.required&&(y=!0),r.defaultValue!=null&&(q=r.defaultValue))),l[h+i]=q;if(y)for(i=0;i<m;++i)q=l[h+i],q!=null&&(r=w[i],r.x&&t(k.xaxis,q,q),r.y&&t(k.yaxis,q,q)),l[h+i]=null;else if(insertSteps&&h>0&&l[h-m]!=null&&l[h-m]!=l[h]&&l[h-m+1]!=l[h+1]){for(i=0;i<m;++i)l[h+m+i]=l[h+i];l[h+1]=l[h-m+1],h+=m}}}for(e=0;e<g.length;++e)k=g[e],x(v.processDatapoints,[k,k.datapoints]);for(e=0;e<g.length;++e){k=g[e],l=k.datapoints.points,m=k.datapoints.pointsize;var z=b,A=b,B=c,C=c;for(f=0;f<l.length;f+=m){if(l[f]==null)continue;for(i=0;i<m;++i){q=l[f+i],r=w[i];if(!r||q==d||q==-d)continue;r.x&&(q<z&&(z=q),q>B&&(B=q)),r.y&&(q<A&&(A=q),q>C&&(C=q))}}if(k.bars.show){var E=k.bars.align=="left"?0:-k.bars.barWidth/2;k.bars.horizontal?(A+=E,C+=E+k.bars.barWidth):(z+=E,B+=E+k.bars.barWidth)}t(k.xaxis,z,B),t(k.yaxis,A,C)}a.each(D(),function(a,d){d.datamin==b&&(d.datamin=null),d.datamax==c&&(d.datamax=null)})}function J(c,d){var e=document.createElement("canvas");return e.className=d,e.width=r,e.height=s,c||a(e).css({position:"absolute",left:0,top:0}),a(e).appendTo(b),e.getContext||(e=window.G_vmlCanvasManager.initElement(e)),e.getContext("2d").save(),e}function K(){r=b.width(),s=b.height();if(r<=0||s<=0)throw"Invalid dimensions for plot, width = "+r+", height = "+s}function L(a){a.width!=r&&(a.width=r),a.height!=s&&(a.height=s);var b=a.getContext("2d");b.restore(),b.save()}function M(){var c,d=b.children("canvas.base"),e=b.children("canvas.overlay");d.length==0||e==0?(b.html(""),b.css({padding:0}),b.css("position")=="static"&&b.css("position","relative"),K(),j=J(!0,"base"),k=J(!1,"overlay"),c=!1):(j=d.get(0),k=e.get(0),c=!0),m=j.getContext("2d"),n=k.getContext("2d"),l=a([k,j]),c&&(b.data("plot").shutdown(),w.resize(),n.clearRect(0,0,r,s),l.unbind(),b.children().not([j,k]).remove()),b.data("plot",w)}function N(){h.grid.hoverable&&(l.mousemove(bl),l.mouseleave(bm)),h.grid.clickable&&l.click(bn),x(v.bindEvents,[l])}function O(){bj&&clearTimeout(bj),l.unbind("mousemove",bl),l.unbind("mouseleave",bm),l.unbind("click",bn),x(v.shutdown,[l])}function P(a){function b(a){return a}var c,d,e=a.options.transform||b,f=a.options.inverseTransform;a.direction=="x"?(c=a.scale=t/Math.abs(e(a.max)-e(a.min)),d=Math.min(e(a.max),e(a.min))):(c=a.scale=u/Math.abs(e(a.max)-e(a.min)),c=-c,d=Math.max(e(a.max),e(a.min))),e==b?a.p2c=function(a){return(a-d)*c}:a.p2c=function(a){return(e(a)-d)*c},f?a.c2p=function(a){return f(d+a/c)}:a.c2p=function(a){return d+a/c}}function Q(c){function l(d,e){return a('<div style="position:absolute;top:-10000px;'+e+'font-size:smaller"><div class="'+c.direction+"Axis "+c.direction+c.n+'Axis">'+d.join("")+"</div></div>").appendTo(b)}var d=c.options,e,f=c.ticks||[],g=[],h,i=d.labelWidth,j=d.labelHeight,k;if(c.direction=="x"){i==null&&(i=Math.floor(r/(f.length>0?f.length:1)));if(j==null){g=[];for(e=0;e<f.length;++e)h=f[e].label,h&&g.push('<div class="tickLabel" style="float:left;width:'+i+'px">'+h+"</div>");g.length>0&&(g.push('<div style="clear:left"></div>'),k=l(g,"width:10000px;"),j=k.height(),k.remove())}}else if(i==null||j==null){for(e=0;e<f.length;++e)h=f[e].label,h&&g.push('<div class="tickLabel">'+h+"</div>");g.length>0&&(k=l(g,""),i==null&&(i=k.children().width()),j==null&&(j=k.find("div.tickLabel").height()),k.remove())}i==null&&(i=0),j==null&&(j=0),c.labelWidth=i,c.labelHeight=j}function R(b){var c=b.labelWidth,d=b.labelHeight,e=b.options.position,f=b.options.tickLength,g=h.grid.axisMargin,i=h.grid.labelMargin,j=b.direction=="x"?o:p,k,l=a.grep(j,function(a){return a&&a.options.position==e&&a.reserveSpace});a.inArray(b,l)==l.length-1&&(g=0),f==null&&(f="full");var m=a.grep(j,function(a){return a&&a.reserveSpace}),n=a.inArray(b,m)==0;!n&&f=="full"&&(f=5),isNaN(+f)||(i+=+f),b.direction=="x"?(d+=i,e=="bottom"?(q.bottom+=d+g,b.box={top:s-q.bottom,height:d}):(b.box={top:q.top+g,height:d},q.top+=d+g)):(c+=i,e=="left"?(b.box={left:q.left+g,width:c},q.left+=c+g):(q.right+=c+g,b.box={left:r-q.right,width:c})),b.position=e,b.tickLength=f,b.box.padding=i,b.innermost=n}function S(a){a.direction=="x"?(a.box.left=q.left,a.box.width=t):(a.box.top=q.top,a.box.height=u)}function T(){var b,c=D();a.each(c,function(a,b){b.show=b.options.show,b.show==null&&(b.show=b.used),b.reserveSpace=b.show||b.options.reserveSpace,U(b)}),allocatedAxes=a.grep(c,function(a){return a.reserveSpace}),q.left=q.right=q.top=q.bottom=0;if(h.grid.show){a.each(allocatedAxes,function(a,b){V(b),W(b),X(b,b.ticks),Q(b)});for(b=allocatedAxes.length-1;b>=0;--b)R(allocatedAxes[b]);var d=h.grid.minBorderMargin;if(d==null){d=0;for(b=0;b<g.length;++b)d=Math.max(d,g[b].points.radius+g[b].points.lineWidth/2)}for(var e in q)q[e]+=h.grid.borderWidth,q[e]=Math.max(d,q[e])}t=r-q.left-q.right,u=s-q.bottom-q.top,a.each(c,function(a,b){P(b)}),h.grid.show&&(a.each(allocatedAxes,function(a,b){S(b)}),ba()),bh()}function U(a){var b=a.options,c=+(b.min!=null?b.min:a.datamin),d=+(b.max!=null?b.max:a.datamax),e=d-c;if(e==0){var f=d==0?1:.01;b.min==null&&(c-=f);if(b.max==null||b.min!=null)d+=f}else{var g=b.autoscaleMargin;g!=null&&(b.min==null&&(c-=e*g,c<0&&a.datamin!=null&&a.datamin>=0&&(c=0)),b.max==null&&(d+=e*g,d>0&&a.datamax!=null&&a.datamax<=0&&(d=0)))}a.min=c,a.max=d}function V(b){var d=b.options,e;typeof d.ticks=="number"&&d.ticks>0?e=d.ticks:e=.3*Math.sqrt(b.direction=="x"?r:s);var f=(b.max-b.min)/e,g,h,i,j,k,l,m;if(d.mode=="time"){var n={second:1e3,minute:6e4,hour:36e5,day:864e5,month:2592e6,year:525949.2*60*1e3},q=[[1,"second"],[2,"second"],[5,"second"],[10,"second"],[30,"second"],[1,"minute"],[2,"minute"],[5,"minute"],[10,"minute"],[30,"minute"],[1,"hour"],[2,"hour"],[4,"hour"],[8,"hour"],[12,"hour"],[1,"day"],[2,"day"],[3,"day"],[.25,"month"],[.5,"month"],[1,"month"],[2,"month"],[3,"month"],[6,"month"],[1,"year"]],t=0;d.minTickSize!=null&&(typeof d.tickSize=="number"?t=d.tickSize:t=d.minTickSize[0]*n[d.minTickSize[1]]);for(var k=0;k<q.length-1;++k)if(f<(q[k][0]*n[q[k][1]]+q[k+1][0]*n[q[k+1][1]])/2&&q[k][0]*n[q[k][1]]>=t)break;g=q[k][0],i=q[k][1],i=="year"&&(l=Math.pow(10,Math.floor(Math.log(f/n.year)/Math.LN10)),m=f/n.year/l,m<1.5?g=1:m<3?g=2:m<7.5?g=5:g=10,g*=l),b.tickSize=d.tickSize||[g,i],h=function(a){var b=[],d=a.tickSize[0],e=a.tickSize[1],f=new Date(a.min),g=d*n[e];e=="second"&&f.setUTCSeconds(c(f.getUTCSeconds(),d)),e=="minute"&&f.setUTCMinutes(c(f.getUTCMinutes(),d)),e=="hour"&&f.setUTCHours(c(f.getUTCHours(),d)),e=="month"&&f.setUTCMonth(c(f.getUTCMonth(),d)),e=="year"&&f.setUTCFullYear(c(f.getUTCFullYear(),d)),f.setUTCMilliseconds(0),g>=n.minute&&f.setUTCSeconds(0),g>=n.hour&&f.setUTCMinutes(0),g>=n.day&&f.setUTCHours(0),g>=n.day*4&&f.setUTCDate(1),g>=n.year&&f.setUTCMonth(0);var h=0,i=Number.NaN,j;do{j=i,i=f.getTime(),b.push(i);if(e=="month")if(d<1){f.setUTCDate(1);var k=f.getTime();f.setUTCMonth(f.getUTCMonth()+1);var l=f.getTime();f.setTime(i+h*n.hour+(l-k)*d),h=f.getUTCHours(),f.setUTCHours(0)}else f.setUTCMonth(f.getUTCMonth()+d);else e=="year"?f.setUTCFullYear(f.getUTCFullYear()+d):f.setTime(i+g)}while(i<a.max&&i!=j);return b},j=function(b,c){var e=new Date(b);if(d.timeformat!=null)return a.plot.formatDate(e,d.timeformat,d.monthNames);var f=c.tickSize[0]*n[c.tickSize[1]],g=c.max-c.min,h=d.twelveHourClock?" %p":"";return f<n.minute?fmt="%h:%M:%S"+h:f<n.day?g<2*n.day?fmt="%h:%M"+h:fmt="%b %d %h:%M"+h:f<n.month?fmt="%b %d":f<n.year?g<n.year?fmt="%b":fmt="%b %y":fmt="%y",a.plot.formatDate(e,fmt,d.monthNames)}}else{var u=d.tickDecimals,v=-Math.floor(Math.log(f)/Math.LN10);u!=null&&v>u&&(v=u),l=Math.pow(10,-v),m=f/l,m<1.5?g=1:m<3?(g=2,m>2.25&&(u==null||v+1<=u)&&(g=2.5,++v)):m<7.5?g=5:g=10,g*=l,d.minTickSize!=null&&g<d.minTickSize&&(g=d.minTickSize),b.tickDecimals=Math.max(0,u!=null?u:v),b.tickSize=d.tickSize||g,h=function(a){var b=[],d=c(a.min,a.tickSize),e=0,f=Number.NaN,g;do g=f,f=d+e*a.tickSize,b.push(f),++e;while(f<a.max&&f!=g);return b},j=function(a,b){return a.toFixed(b.tickDecimals)}}if(d.alignTicksWithAxis!=null){var w=(b.direction=="x"?o:p)[d.alignTicksWithAxis-1];if(w&&w.used&&w!=b){var x=h(b);x.length>0&&(d.min==null&&(b.min=Math.min(b.min,x[0])),d.max==null&&x.length>1&&(b.max=Math.max(b.max,x[x.length-1]))),h=function(a){var b=[],c,d;for(d=0;d<w.ticks.length;++d)c=(w.ticks[d].v-w.min)/(w.max-w.min),c=a.min+c*(a.max-a.min),b.push(c);return b};if(b.mode!="time"&&d.tickDecimals==null){var y=Math.max(0,-Math.floor(Math.log(f)/Math.LN10)+1),z=h(b);z.length>1&&/\..*0$/.test((z[1]-z[0]).toFixed(y))||(b.tickDecimals=y)}}}b.tickGenerator=h,a.isFunction(d.tickFormatter)?b.tickFormatter=function(a,b){return""+d.tickFormatter(a,b)}:b.tickFormatter=j}function W(b){var c=b.options.ticks,d=[];c==null||typeof c=="number"&&c>0?d=b.tickGenerator(b):c&&(a.isFunction(c)?d=c({min:b.min,max:b.max}):d=c);var e,f;b.ticks=[];for(e=0;e<d.length;++e){var g=null,h=d[e];typeof h=="object"?(f=+h[0],h.length>1&&(g=h[1])):f=+h,g==null&&(g=b.tickFormatter(f,b)),isNaN(f)||b.ticks.push({v:f,label:g})}}function X(a,b){a.options.autoscaleMargin&&b.length>0&&(a.options.min==null&&(a.min=Math.min(a.min,b[0].v)),a.options.max==null&&b.length>1&&(a.max=Math.max(a.max,b[b.length-1].v)))}function Y(){m.clearRect(0,0,r,s);var a=h.grid;a.show&&a.backgroundColor&&$(),a.show&&!a.aboveData&&_();for(var b=0;b<g.length;++b)x(v.drawSeries,[m,g[b]]),bb(g[b]);x(v.draw,[m]),a.show&&a.aboveData&&_()}function Z(a,b){var c,d,e,f,g=D();for(i=0;i<g.length;++i){c=g[i];if(c.direction==b){f=b+c.n+"axis",!a[f]&&c.n==1&&(f=b+"axis");if(a[f]){d=a[f].from,e=a[f].to;break}}}a[f]||(c=b=="x"?o[0]:p[0],d=a[b+"1"],e=a[b+"2"]);if(d!=null&&e!=null&&d>e){var h=d;d=e,e=h}return{from:d,to:e,axis:c}}function $(){m.save(),m.translate(q.left,q.top),m.fillStyle=bw(h.grid.backgroundColor,u,0,"rgba(255, 255, 255, 0)"),m.fillRect(0,0,t,u),m.restore()}function _(){var b;m.save(),m.translate(q.left,q.top);var c=h.grid.markings;if(c){if(a.isFunction(c)){var d=w.getAxes();d.xmin=d.xaxis.min,d.xmax=d.xaxis.max,d.ymin=d.yaxis.min,d.ymax=d.yaxis.max,c=c(d)}for(b=0;b<c.length;++b){var e=c[b],f=Z(e,"x"),g=Z(e,"y");f.from==null&&(f.from=f.axis.min),f.to==null&&(f.to=f.axis.max),g.from==null&&(g.from=g.axis.min),g.to==null&&(g.to=g.axis.max);if(f.to<f.axis.min||f.from>f.axis.max||g.to<g.axis.min||g.from>g.axis.max)continue;f.from=Math.max(f.from,f.axis.min),f.to=Math.min(f.to,f.axis.max),g.from=Math.max(g.from,g.axis.min),g.to=Math.min(g.to,g.axis.max);if(f.from==f.to&&g.from==g.to)continue;f.from=f.axis.p2c(f.from),f.to=f.axis.p2c(f.to),g.from=g.axis.p2c(g.from),g.to=g.axis.p2c(g.to),f.from==f.to||g.from==g.to?(m.beginPath(),m.strokeStyle=e.color||h.grid.markingsColor,m.lineWidth=e.lineWidth||h.grid.markingsLineWidth,m.moveTo(f.from,g.from),m.lineTo(f.to,g.to),m.stroke()):(m.fillStyle=e.color||h.grid.markingsColor,m.fillRect(f.from,g.to,f.to-f.from,g.from-g.to))}}var d=D(),i=h.grid.borderWidth;for(var j=0;j<d.length;++j){var k=d[j],l=k.box,n=k.tickLength,o,p,r,s;if(!k.show||k.ticks.length==0)continue;m.strokeStyle=k.options.tickColor||a.color.parse(k.options.color).scale("a",.22).toString(),m.lineWidth=1,k.direction=="x"?(o=0,n=="full"?p=k.position=="top"?0:u:p=l.top-q.top+(k.position=="top"?l.height:0)):(p=0,n=="full"?o=k.position=="left"?0:t:o=l.left-q.left+(k.position=="left"?l.width:0)),k.innermost||(m.beginPath(),r=s=0,k.direction=="x"?r=t:s=u,m.lineWidth==1&&(o=Math.floor(o)+.5,p=Math.floor(p)+.5),m.moveTo(o,p),m.lineTo(o+r,p+s),m.stroke()),m.beginPath();for(b=0;b<k.ticks.length;++b){var v=k.ticks[b].v;r=s=0;if(v<k.min||v>k.max||n=="full"&&i>0&&(v==k.min||v==k.max))continue;k.direction=="x"?(o=k.p2c(v),s=n=="full"?-u:n,k.position=="top"&&(s=-s)):(p=k.p2c(v),r=n=="full"?-t:n,k.position=="left"&&(r=-r)),m.lineWidth==1&&(k.direction=="x"?o=Math.floor(o)+.5:p=Math.floor(p)+.5),m.moveTo(o,p),m.lineTo(o+r,p+s)}m.stroke()}i&&(m.lineWidth=i,m.strokeStyle=h.grid.borderColor,m.strokeRect(-i/2,-i/2,t+i,u+i)),m.restore()}function ba(){b.find(".tickLabels").remove();var a=['<div class="tickLabels" style="font-size:smaller">'],c=D();for(var d=0;d<c.length;++d){var e=c[d],f=e.box;if(!e.show)continue;a.push('<div class="'+e.direction+"Axis "+e.direction+e.n+'Axis" style="color:'+e.options.color+'">');for(var g=0;g<e.ticks.length;++g){var h=e.ticks[g];if(!h.label||h.v<e.min||h.v>e.max)continue;var i={},j;e.direction=="x"?(j="center",i.left=Math.round(q.left+e.p2c(h.v)-e.labelWidth/2),e.position=="bottom"?i.top=f.top+f.padding:i.bottom=s-(f.top+f.height-f.padding)):(i.top=Math.round(q.top+e.p2c(h.v)-e.labelHeight/2),e.position=="left"?(i.right=r-(f.left+f.width-f.padding),j="right"):(i.left=f.left+f.padding,j="left")),i.width=e.labelWidth;var k=["position:absolute","text-align:"+j];for(var l in i)k.push(l+":"+i[l]+"px");a.push('<div class="tickLabel" style="'+k.join(";")+'">'+h.label+"</div>")}a.push("</div>")}a.push("</div>"),b.append(a.join(""))}function bb(a){a.lines.show&&bc(a),a.bars.show&&bf(a),a.points.show&&bd(a)}function bc(a){function b(a,b,c,d,e){var f=a.points,g=a.pointsize,h=null,i=null;m.beginPath();for(var j=g;j<f.length;j+=g){var k=f[j-g],l=f[j-g+1],n=f[j],o=f[j+1];if(k==null||n==null)continue;if(l<=o&&l<e.min){if(o<e.min)continue;k=(e.min-l)/(o-l)*(n-k)+k,l=e.min}else if(o<=l&&o<e.min){if(l<e.min)continue;n=(e.min-l)/(o-l)*(n-k)+k,o=e.min}if(l>=o&&l>e.max){if(o>e.max)continue;k=(e.max-l)/(o-l)*(n-k)+k,l=e.max}else if(o>=l&&o>e.max){if(l>e.max)continue;n=(e.max-l)/(o-l)*(n-k)+k,o=e.max}if(k<=n&&k<d.min){if(n<d.min)continue;l=(d.min-k)/(n-k)*(o-l)+l,k=d.min}else if(n<=k&&n<d.min){if(k<d.min)continue;o=(d.min-k)/(n-k)*(o-l)+l,n=d.min}if(k>=n&&k>d.max){if(n>d.max)continue;l=(d.max-k)/(n-k)*(o-l)+l,k=d.max}else if(n>=k&&n>d.max){if(k>d.max)continue;o=(d.max-k)/(n-k)*(o-l)+l,n=d.max}(k!=h||l!=i)&&m.moveTo(d.p2c(k)+b,e.p2c(l)+c),h=n,i=o,m.lineTo(d.p2c(n)+b,e.p2c(o)+c)}m.stroke()}function c(a,b,c){var d=a.points,e=a.pointsize,f=Math.min(Math.max(0,c.min),c.max),g=0,h,i=!1,j=1,k=0,l=0;for(;;){if(e>0&&g>d.length+e)break;g+=e;var n=d[g-e],o=d[g-e+j],p=d[g],q=d[g+j];if(i){if(e>0&&n!=null&&p==null){l=g,e=-e,j=2;continue}if(e<0&&g==k+e){m.fill(),i=!1,e=-e,j=1,g=k=l+e;continue}}if(n==null||p==null)continue;if(n<=p&&n<b.min){if(p<b.min)continue;o=(b.min-n)/(p-n)*(q-o)+o,n=b.min}else if(p<=n&&p<b.min){if(n<b.min)continue;q=(b.min-n)/(p-n)*(q-o)+o,p=b.min}if(n>=p&&n>b.max){if(p>b.max)continue;o=(b.max-n)/(p-n)*(q-o)+o,n=b.max}else if(p>=n&&p>b.max){if(n>b.max)continue;q=(b.max-n)/(p-n)*(q-o)+o,p=b.max}i||(m.beginPath(),m.moveTo(b.p2c(n),c.p2c(f)),i=!0);if(o>=c.max&&q>=c.max){m.lineTo(b.p2c(n),c.p2c(c.max)),m.lineTo(b.p2c(p),c.p2c(c.max));continue}if(o<=c.min&&q<=c.min){m.lineTo(b.p2c(n),c.p2c(c.min)),m.lineTo(b.p2c(p),c.p2c(c.min));continue}var r=n,s=p;o<=q&&o<c.min&&q>=c.min?(n=(c.min-o)/(q-o)*(p-n)+n,o=c.min):q<=o&&q<c.min&&o>=c.min&&(p=(c.min-o)/(q-o)*(p-n)+n,q=c.min),o>=q&&o>c.max&&q<=c.max?(n=(c.max-o)/(q-o)*(p-n)+n,o=c.max):q>=o&&q>c.max&&o<=c.max&&(p=(c.max-o)/(q-o)*(p-n)+n,q=c.max),n!=r&&m.lineTo(b.p2c(r),c.p2c(o)),m.lineTo(b.p2c(n),c.p2c(o)),m.lineTo(b.p2c(p),c.p2c(q)),p!=s&&(m.lineTo(b.p2c(p),c.p2c(q)),m.lineTo(b.p2c(s),c.p2c(q)))}}m.save(),m.translate(q.left,q.top),m.lineJoin="round";var d=a.lines.lineWidth,e=a.shadowSize;if(d>0&&e>0){m.lineWidth=e,m.strokeStyle="rgba(0,0,0,0.1)";var f=Math.PI/18;b(a.datapoints,Math.sin(f)*(d/2+e/2),Math.cos(f)*(d/2+e/2),a.xaxis,a.yaxis),m.lineWidth=e/2,b(a.datapoints,Math.sin(f)*(d/2+e/4),Math.cos(f)*(d/2+e/4),a.xaxis,a.yaxis)}m.lineWidth=d,m.strokeStyle=a.color;var g=bg(a.lines,a.color,0,u);g&&(m.fillStyle=g,c(a.datapoints,a.xaxis,a.yaxis)),d>0&&b(a.datapoints,0,0,a.xaxis,a.yaxis),m.restore()}function bd(a){function b(a,b,c,d,e,f,g,h){var i=a.points,j=a.pointsize;for(var k=0;k<i.length;k+=j){var l=i[k],n=i[k+1];if(l==null||l<f.min||l>f.max||n<g.min||n>g.max)continue;m.beginPath(),l=f.p2c(l),n=g.p2c(n)+d,h=="circle"?m.arc(l,n,b,0,e?Math.PI:Math.PI*2,!1):h(m,l,n,b,e),m.closePath(),c&&(m.fillStyle=c,m.fill()),m.stroke()}}m.save(),m.translate(q.left,q.top);var c=a.points.lineWidth,d=a.shadowSize,e=a.points.radius,f=a.points.symbol;if(c>0&&d>0){var g=d/2;m.lineWidth=g,m.strokeStyle="rgba(0,0,0,0.1)",b(a.datapoints,e,null,g+g/2,!0,a.xaxis,a.yaxis,f),m.strokeStyle="rgba(0,0,0,0.2)",b(a.datapoints,e,null,g/2,!0,a.xaxis,a.yaxis,f)}m.lineWidth=c,m.strokeStyle=a.color,b(a.datapoints,e,bg(a.points,a.color),0,!1,a.xaxis,a.yaxis,f),m.restore()}function be(a,b,c,d,e,f,g,h,i,j,k,l){var m,n,o,p,q,r,s,t,u;k?(t=r=s=!0,q=!1,m=c,n=a,p=b+d,o=b+e,n<m&&(u=n,n=m,m=u,q=!0,r=!1)):(q=r=s=!0,t=!1,m=a+d,n=a+e,o=c,p=b,p<o&&(u=p,p=o,o=u,t=!0,s=!1));if(n<h.min||m>h.max||p<i.min||o>i.max)return;m<h.min&&(m=h.min,q=!1),n>h.max&&(n=h.max,r=!1),o<i.min&&(o=i.min,t=!1),p>i.max&&(p=i.max,s=!1),m=h.p2c(m),o=i.p2c(o),n=h.p2c(n),p=i.p2c(p),g&&(j.beginPath(),j.moveTo(m,o),j.lineTo(m,p),j.lineTo(n,p),j.lineTo(n,o),j.fillStyle=g(o,p),j.fill()),l>0&&(q||r||s||t)&&(j.beginPath(),j.moveTo(m,o+f),q?j.lineTo(m,p+f):j.moveTo(m,p+f),s?j.lineTo(n,p+f):j.moveTo(n,p+f),r?j.lineTo(n,o+f):j.moveTo(n,o+f),t?j.lineTo(m,o+f):j.moveTo(m,o+f),j.stroke())}function bf(a){function b(b,c,d,e,f,g,h){var i=b.points,j=b.pointsize;for(var k=0;k<i.length;k+=j){if(i[k]==null)continue;be(i[k],i[k+1],i[k+2],c,d,e,f,g,h,m,a.bars.horizontal,a.bars.lineWidth)}}m.save(),m.translate(q.left,q.top),m.lineWidth=a.bars.lineWidth,m.strokeStyle=a.color;var c=a.bars.align=="left"?0:-a.bars.barWidth/2,d=a.bars.fill?function(b,c){return bg(a.bars,a.color,b,c)}:null;b(a.datapoints,c,c+a.bars.barWidth,0,d,a.xaxis,a.yaxis),m.restore()}function bg(b,c,d,e){var f=b.fill;if(!f)return null;if(b.fillColor)return bw(b.fillColor,d,e,c);var g=a.color.parse(c);return g.a=typeof f=="number"?f:.4,g.normalize(),g.toString()}function bh(){b.find(".legend").remove();if(!h.legend.show)return;var c=[],d=!1,e=h.legend.labelFormatter,f,i;for(var j=0;j<g.length;++j){f=g[j],i=f.label;if(!i)continue;j%h.legend.noColumns==0&&(d&&c.push("</tr>"),c.push("<tr>"),d=!0),e&&(i=e(i,f)),c.push('<td class="legendColorBox"><div style="border:1px solid '+h.legend.labelBoxBorderColor+';padding:1px"><div style="width:4px;height:0;border:5px solid '+f.color+';overflow:hidden"></div></div></td><td class="legendLabel">'+i+"</td>")}d&&c.push("</tr>");if(c.length==0)return;var k='<table style="font-size:smaller;color:'+h.grid.color+'">'+c.join("")+"</table>";if(h.legend.container!=null)a(h.legend.container).html(k);else{var l="",m=h.legend.position,n=h.legend.margin;n[0]==null&&(n=[n,n]),m.charAt(0)=="n"?l+="top:"+(n[1]+q.top)+"px;":m.charAt(0)=="s"&&(l+="bottom:"+(n[1]+q.bottom)+"px;"),m.charAt(1)=="e"?l+="right:"+(n[0]+q.right)+"px;":m.charAt(1)=="w"&&(l+="left:"+(n[0]+q.left)+"px;");var o=a('<div class="legend">'+k.replace('style="','style="position:absolute;'+l+";")+"</div>").appendTo(b);if(h.legend.backgroundOpacity!=0){var p=h.legend.backgroundColor;p==null&&(p=h.grid.backgroundColor,p&&typeof p=="string"?p=a.color.parse(p):p=a.color.extract(o,"background-color"),p.a=1,p=p.toString());var r=o.children();a('<div style="position:absolute;width:'+r.width()+"px;height:"+r.height()+"px;"+l+"background-color:"+p+';"> </div>').prependTo(o).css("opacity",h.legend.backgroundOpacity)}}}function bk(a,b,c){var d=h.grid.mouseActiveRadius,e=d*d+1,f=null,i=!1,j,k;for(j=g.length-1;j>=0;--j){if(!c(g[j]))continue;var l=g[j],m=l.xaxis,n=l.yaxis,o=l.datapoints.points,p=l.datapoints.pointsize,q=m.c2p(a),r=n.c2p(b),s=d/m.scale,t=d/n.scale;m.options.inverseTransform&&(s=Number.MAX_VALUE),n.options.inverseTransform&&(t=Number.MAX_VALUE);if(l.lines.show||l.points.show)for(k=0;k<o.length;k+=p){var u=o[k],v=o[k+1];if(u==null)continue;if(u-q>s||u-q<-s||v-r>t||v-r<-t)continue;var w=Math.abs(m.p2c(u)-a),x=Math.abs(n.p2c(v)-b),y=w*w+x*x;y<e&&(e=y,f=[j,k/p])}if(l.bars.show&&!f){var z=l.bars.align=="left"?0:-l.bars.barWidth/2,A=z+l.bars.barWidth;for(k=0;k<o.length;k+=p){var u=o[k],v=o[k+1],B=o[k+2];if(u==null)continue;if(g[j].bars.horizontal?q<=Math.max(B,u)&&q>=Math.min(B,u)&&r>=v+z&&r<=v+A:q>=u+z&&q<=u+A&&r>=Math.min(B,v)&&r<=Math.max(B,v))f=[j,k/p]}}}return f?(j=f[0],k=f[1],p=g[j].datapoints.pointsize,{datapoint:g[j].datapoints.points.slice(k*p,(k+1)*p),dataIndex:k,series:g[j],seriesIndex:j}):null}function bl(a){h.grid.hoverable&&bo("plothover",a,function(a){return a.hoverable!=!1})}function bm(a){h.grid.hoverable&&bo("plothover",a,function(a){return!1})}function bn(a){bo("plotclick",a,function(a){return a.clickable!=!1})}function bo(a,c,d){var e=l.offset(),f=c.pageX-e.left-q.left,g=c.pageY-e.top-q.top,i=E({left:f,top:g});i.pageX=c.pageX,i.pageY=c.pageY;var j=bk(f,g,d);j&&(j.pageX=parseInt(j.series.xaxis.p2c(j.datapoint[0])+e.left+q.left),j.pageY=parseInt(j.series.yaxis.p2c(j.datapoint[1])+e.top+q.top));if(h.grid.autoHighlight){for(var k=0;k<bi.length;++k){var m=bi[k];m.auto==a&&(!j||m.series!=j.series||m.point[0]!=j.datapoint[0]||m.point[1]!=j.datapoint[1])&&bs(m.series,m.point)}j&&br(j.series,j.datapoint,a)}b.trigger(a,[i,j])}function bp(){bj||(bj=setTimeout(bq,30))}function bq(){bj=null,n.save(),n.clearRect(0,0,r,s),n.translate(q.left,q.top);var a,b;for(a=0;a<bi.length;++a)b=bi[a],b.series.bars.show?bv(b.series,b.point):bu(b.series,b.point);n.restore(),x(v.drawOverlay,[n])}function br(a,b,c){typeof a=="number"&&(a=g[a]);if(typeof b=="number"){var d=a.datapoints.pointsize;b=a.datapoints.points.slice(d*b,d*(b+1))}var e=bt(a,b);e==-1?(bi.push({series:a,point:b,auto:c}),bp()):c||(bi[e].auto=!1)}function bs(a,b){a==null&&b==null&&(bi=[],bp()),typeof a=="number"&&(a=g[a]),typeof b=="number"&&(b=a.data[b]);var c=bt(a,b);c!=-1&&(bi.splice(c,1),bp())}function bt(a,b){for(var c=0;c<bi.length;++c){var d=bi[c];if(d.series==a&&d.point[0]==b[0]&&d.point[1]==b[1])return c}return-1}function bu(b,c){var d=c[0],e=c[1],f=b.xaxis,g=b.yaxis;if(d<f.min||d>f.max||e<g.min||e>g.max)return;var h=b.points.radius+b.points.lineWidth/2;n.lineWidth=h,n.strokeStyle=a.color.parse(b.color).scale("a",.5).toString();var i=1.5*h,d=f.p2c(d),e=g.p2c(e);n.beginPath(),b.points.symbol=="circle"?n.arc(d,e,i,0,2*Math.PI,!1):b.points.symbol(n,d,e,i,!1),n.closePath(),n.stroke()}function bv(b,c){n.lineWidth=b.bars.lineWidth,n.strokeStyle=a.color.parse(b.color).scale("a",.5).toString();var d=a.color.parse(b.color).scale("a",.5).toString(),e=b.bars.align=="left"?0:-b.bars.barWidth/2;be(c[0],c[1],c[2]||0,e,e+b.bars.barWidth,0,function(){return d},b.xaxis,b.yaxis,n,b.bars.horizontal,b.bars.lineWidth)}function bw(b,c,d,e){if(typeof b=="string")return b;var f=m.createLinearGradient(0,d,0,c);for(var g=0,h=b.colors.length;g<h;++g){var i=b.colors[g];if(typeof i!="string"){var j=a.color.parse(e);i.brightness!=null&&(j=j.scale("rgb",i.brightness)),i.opacity!=null&&(j.a*=i.opacity),i=j.toString()}f.addColorStop(g/(h-1),i)}return f}var g=[],h={colors:["#edc240","#afd8f8","#cb4b4b","#4da74d","#9440ed"],legend:{show:!0,noColumns:1,labelFormatter:null,labelBoxBorderColor:"#ccc",container:null,position:"ne",margin:5,backgroundColor:null,backgroundOpacity:.85},xaxis:{show:null,position:"bottom",mode:null,color:null,tickColor:null,transform:null,inverseTransform:null,min:null,max:null,autoscaleMargin:null,ticks:null,tickFormatter:null,labelWidth:null,labelHeight:null,reserveSpace:null,tickLength:null,alignTicksWithAxis:null,tickDecimals:null,tickSize:null,minTickSize:null,monthNames:null,timeformat:null,twelveHourClock:!1},yaxis:{autoscaleMargin:.02,position:"left"},xaxes:[],yaxes:[],series:{points:{show:!1,radius:3,lineWidth:2,fill:!0,fillColor:"#ffffff",symbol:"circle"},lines:{lineWidth:2,fill:!1,fillColor:null,steps:!1},bars:{show:!1,lineWidth:2,barWidth:1,fill:!0,fillColor:null,align:"left",horizontal:!1},shadowSize:3},grid:{show:!0,aboveData:!1,color:"#545454",backgroundColor:null,borderColor:null,tickColor:null,labelMargin:5,axisMargin:8,borderWidth:2,minBorderMargin:null,markings:null,markingsColor:"#f4f4f4",markingsLineWidth:2,clickable:!1,hoverable:!1,autoHighlight:!0,mouseActiveRadius:10},hooks:{}},j=null,k=null,l=null,m=null,n=null,o=[],p=[],q={left:0,right:0,top:0,bottom:0},r=0,s=0,t=0,u=0,v={processOptions:[],processRawData:[],processDatapoints:[],drawSeries:[],draw:[],bindEvents:[],drawOverlay:[],shutdown:[]},w=this;w.setData=A,w.setupGrid=T,w.draw=Y,w.getPlaceholder=function(){return b},w.getCanvas=function(){return j},w.getPlotOffset=function(){return q},w.width=function(){return t},w.height=function(){return u},w.offset=function(){var a=l.offset();return a.left+=q.left,a.top+=q.top,a},w.getData=function(){return g},w.getAxes=function(){var b={},c;return a.each(o.concat(p),function(a,c){c&&(
b[c.direction+(c.n!=1?c.n:"")+"axis"]=c)}),b},w.getXAxes=function(){return o},w.getYAxes=function(){return p},w.c2p=E,w.p2c=F,w.getOptions=function(){return h},w.highlight=br,w.unhighlight=bs,w.triggerRedrawOverlay=bp,w.pointOffset=function(a){return{left:parseInt(o[C(a,"x")-1].p2c(+a.x)+q.left),top:parseInt(p[C(a,"y")-1].p2c(+a.y)+q.top)}},w.shutdown=O,w.resize=function(){K(),L(j),L(k)},w.hooks=v,y(w),z(e),M(),A(d),T(),Y(),N();var bi=[],bj=null}function c(a,b){return b*Math.floor(a/b)}a.plot=function(c,d,e){var f=new b(a(c),d,e,a.plot.plugins);return f},a.plot.version="0.7",a.plot.plugins=[],a.plot.formatDate=function(a,b,c){var d=function(a){return a=""+a,a.length==1?"0"+a:a},e=[],f=!1,g=!1,h=a.getUTCHours(),i=h<12;c==null&&(c=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),b.search(/%p|%P/)!=-1&&(h>12?h=h-12:h==0&&(h=12));for(var j=0;j<b.length;++j){var k=b.charAt(j);if(f){switch(k){case"h":k=""+h;break;case"H":k=d(h);break;case"M":k=d(a.getUTCMinutes());break;case"S":k=d(a.getUTCSeconds());break;case"d":k=""+a.getUTCDate();break;case"m":k=""+(a.getUTCMonth()+1);break;case"y":k=""+a.getUTCFullYear();break;case"b":k=""+c[a.getUTCMonth()];break;case"p":k=i?"am":"pm";break;case"P":k=i?"AM":"PM";break;case"0":k="",g=!0}k&&g&&(k=d(k),g=!1),e.push(k),g||(f=!1)}else k=="%"?f=!0:e.push(k)}return e.join("")}}(jQuery),function(a){function c(a){return Math.log(a)/Math.LN10}function d(a,b){b===undefined&&(b=3);if(a===0)return 0;if(b<=0)throw new Error("Significant figures must be greater than zero.");b=Math.floor(b+.5);var d=a>=0?"":"-";a=Math.abs(a);var e=Math.floor(c(a))+1;if(e>b)return a=a.toPrecision(b),d+a.replace("+","");if(e<0){var f=a*pow(10,abs(e)+1);return e-=1,d+f.toFixed(b-1)+"e"+e}return d+a.toFixed(b-e)}function e(a){function c(c){if(b.locked)return;b.x!=-1&&(b.x=-1,a.triggerRedrawOverlay())}function e(c){if(b.locked)return;if(a.getSelection&&a.getSelection()){b.x=-1;return}var d=a.offset();b.x=Math.max(0,Math.min(c.pageX-d.left,a.width())),b.y=Math.max(0,Math.min(c.pageY-d.top,a.height())),a.triggerRedrawOverlay()}var b={x:-1,y:-1,locked:!1};a.setCrosshair=function(c){if(!c)b.x=-1;else{var d=a.p2c(c);b.x=Math.max(0,Math.min(d.left,a.width())),b.y=Math.max(0,Math.min(d.top,a.height()))}a.triggerRedrawOverlay()},a.clearCrosshair=a.setCrosshair,a.lockCrosshair=function(c){c&&a.setCrosshair(c),b.locked=!0},a.unlockCrosshair=function(){b.locked=!1},a.hooks.bindEvents.push(function(a,b){if(!a.getOptions().crosshair.mode)return;b.mouseout(c),b.mousemove(e)}),a.hooks.drawOverlay.push(function(a,c){var e=a.getOptions().crosshair;if(!e.mode)return;var f=a.getPlotOffset();c.save(),c.translate(f.left,f.top);if(b.x!=-1){var g=a.c2p({left:b.x,top:b.y});text=d(g.x,3)+","+d(g.y,3);var h=13;c.fillStyle=e.color,c.font=h+"px Verdana";var i=c.measureText(text).width,j=0,k=0;b.y<h+3?(i+=14,k=h,b.x<=a.width()-(i+5)&&(j+=14)):k=-5,b.x>a.width()-(i+5)?(c.textAlign="right",j+=-3):(c.textAlign="left",j+=3),c.fillText(text,b.x+j,b.y+k),c.strokeStyle=e.color,c.lineWidth=e.lineWidth,c.lineJoin="round",c.beginPath(),e.mode.indexOf("x")!=-1&&(c.moveTo(b.x,0),c.lineTo(b.x,a.height())),e.mode.indexOf("y")!=-1&&(c.moveTo(0,b.y),c.lineTo(a.width(),b.y)),c.stroke()}c.restore()}),a.hooks.shutdown.push(function(a,b){b.unbind("mouseout",c),b.unbind("mousemove",e)})}var b={crosshair:{mode:null,color:"rgba(0, 0, 0, 0.5)",lineWidth:1}};a.plot.plugins.push({init:e,options:b,name:"crosshair_GS",version:"1.0"})}(jQuery),typeof Float32Array!="undefined"?glMatrixArrayType=Float32Array:typeof WebGLFloatArray!="undefined"?glMatrixArrayType=WebGLFloatArray:glMatrixArrayType=Array;var vec3={};vec3.create=function(a){var b=new glMatrixArrayType(3);return a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2]),b},vec3.set=function(a,b){return b[0]=a[0],b[1]=a[1],b[2]=a[2],b},vec3.add=function(a,b,c){return!c||a==c?(a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a):(c[0]=a[0]+b[0],c[1]=a[1]+b[1],c[2]=a[2]+b[2],c)},vec3.subtract=function(a,b,c){return!c||a==c?(a[0]-=b[0],a[1]-=b[1],a[2]-=b[2],a):(c[0]=a[0]-b[0],c[1]=a[1]-b[1],c[2]=a[2]-b[2],c)},vec3.negate=function(a,b){return b||(b=a),b[0]=-a[0],b[1]=-a[1],b[2]=-a[2],b},vec3.scale=function(a,b,c){return!c||a==c?(a[0]*=b,a[1]*=b,a[2]*=b,a):(c[0]=a[0]*b,c[1]=a[1]*b,c[2]=a[2]*b,c)},vec3.normalize=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],f=Math.sqrt(c*c+d*d+e*e);return f?f==1?(b[0]=c,b[1]=d,b[2]=e,b):(f=1/f,b[0]=c*f,b[1]=d*f,b[2]=e*f,b):(b[0]=0,b[1]=0,b[2]=0,b)},vec3.cross=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=b[0],h=b[1],i=b[2];return c[0]=e*i-f*h,c[1]=f*g-d*i,c[2]=d*h-e*g,c},vec3.length=function(a){var b=a[0],c=a[1],d=a[2];return Math.sqrt(b*b+c*c+d*d)},vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3.direction=function(a,b,c){c||(c=a);var d=a[0]-b[0],e=a[1]-b[1],f=a[2]-b[2],g=Math.sqrt(d*d+e*e+f*f);return g?(g=1/g,c[0]=d*g,c[1]=e*g,c[2]=f*g,c):(c[0]=0,c[1]=0,c[2]=0,c)},vec3.lerp=function(a,b,c,d){return d||(d=a),d[0]=a[0]+c*(b[0]-a[0]),d[1]=a[1]+c*(b[1]-a[1]),d[2]=a[2]+c*(b[2]-a[2]),d},vec3.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+"]"};var mat3={};mat3.create=function(a){var b=new glMatrixArrayType(9);return a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8]),b},mat3.set=function(a,b){return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b},mat3.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=1,a[5]=0,a[6]=0,a[7]=0,a[8]=1,a},mat3.transpose=function(a,b){if(!b||a==b){var c=a[1],d=a[2],e=a[5];return a[1]=a[3],a[2]=a[6],a[3]=c,a[5]=a[7],a[6]=d,a[7]=e,a}return b[0]=a[0],b[1]=a[3],b[2]=a[6],b[3]=a[1],b[4]=a[4],b[5]=a[7],b[6]=a[2],b[7]=a[5],b[8]=a[8],b},mat3.toMat4=function(a,b){return b||(b=mat4.create()),b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=0,b[4]=a[3],b[5]=a[4],b[6]=a[5],b[7]=0,b[8]=a[6],b[9]=a[7],b[10]=a[8],b[11]=0,b[12]=0,b[13]=0,b[14]=0,b[15]=1,b},mat3.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+"]"};var mat4={};mat4.create=function(a){var b=new glMatrixArrayType(16);return a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]),b},mat4.set=function(a,b){return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15],b},mat4.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1,a},mat4.transpose=function(a,b){if(!b||a==b){var c=a[1],d=a[2],e=a[3],f=a[6],g=a[7],h=a[11];return a[1]=a[4],a[2]=a[8],a[3]=a[12],a[4]=c,a[6]=a[9],a[7]=a[13],a[8]=d,a[9]=f,a[11]=a[14],a[12]=e,a[13]=g,a[14]=h,a}return b[0]=a[0],b[1]=a[4],b[2]=a[8],b[3]=a[12],b[4]=a[1],b[5]=a[5],b[6]=a[9],b[7]=a[13],b[8]=a[2],b[9]=a[6],b[10]=a[10],b[11]=a[14],b[12]=a[3],b[13]=a[7],b[14]=a[11],b[15]=a[15],b},mat4.determinant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],i=a[7],j=a[8],k=a[9],l=a[10],m=a[11],n=a[12],o=a[13],p=a[14],q=a[15];return n*k*h*e-j*o*h*e-n*g*l*e+f*o*l*e+j*g*p*e-f*k*p*e-n*k*d*i+j*o*d*i+n*c*l*i-b*o*l*i-j*c*p*i+b*k*p*i+n*g*d*m-f*o*d*m-n*c*h*m+b*o*h*m+f*c*p*m-b*g*p*m-j*g*d*q+f*k*d*q+j*c*h*q-b*k*h*q-f*c*l*q+b*g*l*q},mat4.inverse=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],f=a[3],g=a[4],h=a[5],i=a[6],j=a[7],k=a[8],l=a[9],m=a[10],n=a[11],o=a[12],p=a[13],q=a[14],r=a[15],s=c*h-d*g,t=c*i-e*g,u=c*j-f*g,v=d*i-e*h,w=d*j-f*h,x=e*j-f*i,y=k*p-l*o,z=k*q-m*o,A=k*r-n*o,B=l*q-m*p,C=l*r-n*p,D=m*r-n*q,E=1/(s*D-t*C+u*B+v*A-w*z+x*y);return b[0]=(h*D-i*C+j*B)*E,b[1]=(-d*D+e*C-f*B)*E,b[2]=(p*x-q*w+r*v)*E,b[3]=(-l*x+m*w-n*v)*E,b[4]=(-g*D+i*A-j*z)*E,b[5]=(c*D-e*A+f*z)*E,b[6]=(-o*x+q*u-r*t)*E,b[7]=(k*x-m*u+n*t)*E,b[8]=(g*C-h*A+j*y)*E,b[9]=(-c*C+d*A-f*y)*E,b[10]=(o*w-p*u+r*s)*E,b[11]=(-k*w+l*u-n*s)*E,b[12]=(-g*B+h*z-i*y)*E,b[13]=(c*B-d*z+e*y)*E,b[14]=(-o*v+p*t-q*s)*E,b[15]=(k*v-l*t+m*s)*E,b},mat4.toRotationMat=function(a,b){return b||(b=mat4.create()),b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=0,b[13]=0,b[14]=0,b[15]=1,b},mat4.toMat3=function(a,b){return b||(b=mat3.create()),b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[4],b[4]=a[5],b[5]=a[6],b[6]=a[8],b[7]=a[9],b[8]=a[10],b},mat4.toInverseMat3=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[4],g=a[5],h=a[6],i=a[8],j=a[9],k=a[10],l=k*g-h*j,m=-k*f+h*i,n=j*f-g*i,o=c*l+d*m+e*n;if(!o)return null;var p=1/o;return b||(b=mat3.create()),b[0]=l*p,b[1]=(-k*d+e*j)*p,b[2]=(h*d-e*g)*p,b[3]=m*p,b[4]=(k*c-e*i)*p,b[5]=(-h*c+e*f)*p,b[6]=n*p,b[7]=(-j*c+d*i)*p,b[8]=(g*c-d*f)*p,b},mat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[5],j=a[6],k=a[7],l=a[8],m=a[9],n=a[10],o=a[11],p=a[12],q=a[13],r=a[14],s=a[15],t=b[0],u=b[1],v=b[2],w=b[3],x=b[4],y=b[5],z=b[6],A=b[7],B=b[8],C=b[9],D=b[10],E=b[11],F=b[12],G=b[13],H=b[14],I=b[15];return c[0]=t*d+u*h+v*l+w*p,c[1]=t*e+u*i+v*m+w*q,c[2]=t*f+u*j+v*n+w*r,c[3]=t*g+u*k+v*o+w*s,c[4]=x*d+y*h+z*l+A*p,c[5]=x*e+y*i+z*m+A*q,c[6]=x*f+y*j+z*n+A*r,c[7]=x*g+y*k+z*o+A*s,c[8]=B*d+C*h+D*l+E*p,c[9]=B*e+C*i+D*m+E*q,c[10]=B*f+C*j+D*n+E*r,c[11]=B*g+C*k+D*o+E*s,c[12]=F*d+G*h+H*l+I*p,c[13]=F*e+G*i+H*m+I*q,c[14]=F*f+G*j+H*n+I*r,c[15]=F*g+G*k+H*o+I*s,c},mat4.multiplyVec3=function(a,b,c){c||(c=b);var d=b[0],e=b[1],f=b[2];return c[0]=a[0]*d+a[4]*e+a[8]*f+a[12],c[1]=a[1]*d+a[5]*e+a[9]*f+a[13],c[2]=a[2]*d+a[6]*e+a[10]*f+a[14],c},mat4.multiplyVec4=function(a,b,c){c||(c=b);var d=b[0],e=b[1],f=b[2],g=b[3];return c[0]=a[0]*d+a[4]*e+a[8]*f+a[12]*g,c[1]=a[1]*d+a[5]*e+a[9]*f+a[13]*g,c[2]=a[2]*d+a[6]*e+a[10]*f+a[14]*g,c[3]=a[3]*d+a[7]*e+a[11]*f+a[15]*g,c},mat4.translate=function(a,b,c){var d=b[0],e=b[1],f=b[2];if(!c||a==c)return a[12]=a[0]*d+a[4]*e+a[8]*f+a[12],a[13]=a[1]*d+a[5]*e+a[9]*f+a[13],a[14]=a[2]*d+a[6]*e+a[10]*f+a[14],a[15]=a[3]*d+a[7]*e+a[11]*f+a[15],a;var g=a[0],h=a[1],i=a[2],j=a[3],k=a[4],l=a[5],m=a[6],n=a[7],o=a[8],p=a[9],q=a[10],r=a[11];return c[0]=g,c[1]=h,c[2]=i,c[3]=j,c[4]=k,c[5]=l,c[6]=m,c[7]=n,c[8]=o,c[9]=p,c[10]=q,c[11]=r,c[12]=g*d+k*e+o*f+a[12],c[13]=h*d+l*e+p*f+a[13],c[14]=i*d+m*e+q*f+a[14],c[15]=j*d+n*e+r*f+a[15],c},mat4.scale=function(a,b,c){var d=b[0],e=b[1],f=b[2];return!c||a==c?(a[0]*=d,a[1]*=d,a[2]*=d,a[3]*=d,a[4]*=e,a[5]*=e,a[6]*=e,a[7]*=e,a[8]*=f,a[9]*=f,a[10]*=f,a[11]*=f,a):(c[0]=a[0]*d,c[1]=a[1]*d,c[2]=a[2]*d,c[3]=a[3]*d,c[4]=a[4]*e,c[5]=a[5]*e,c[6]=a[6]*e,c[7]=a[7]*e,c[8]=a[8]*f,c[9]=a[9]*f,c[10]=a[10]*f,c[11]=a[11]*f,c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15],c)},mat4.rotate=function(a,b,c,d){var e=c[0],f=c[1],g=c[2],h=Math.sqrt(e*e+f*f+g*g);if(!h)return null;h!=1&&(h=1/h,e*=h,f*=h,g*=h);var i=Math.sin(b),j=Math.cos(b),k=1-j,l=a[0],m=a[1],n=a[2],o=a[3],p=a[4],q=a[5],r=a[6],s=a[7],t=a[8],u=a[9],v=a[10],w=a[11],x=e*e*k+j,y=f*e*k+g*i,z=g*e*k-f*i,A=e*f*k-g*i,B=f*f*k+j,C=g*f*k+e*i,D=e*g*k+f*i,E=f*g*k-e*i,F=g*g*k+j;return d?a!=d&&(d[12]=a[12],d[13]=a[13],d[14]=a[14],d[15]=a[15]):d=a,d[0]=l*x+p*y+t*z,d[1]=m*x+q*y+u*z,d[2]=n*x+r*y+v*z,d[3]=o*x+s*y+w*z,d[4]=l*A+p*B+t*C,d[5]=m*A+q*B+u*C,d[6]=n*A+r*B+v*C,d[7]=o*A+s*B+w*C,d[8]=l*D+p*E+t*F,d[9]=m*D+q*E+u*F,d[10]=n*D+r*E+v*F,d[11]=o*D+s*E+w*F,d},mat4.rotateX=function(a,b,c){var d=Math.sin(b),e=Math.cos(b),f=a[4],g=a[5],h=a[6],i=a[7],j=a[8],k=a[9],l=a[10],m=a[11];return c?a!=c&&(c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=a[3],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a,c[4]=f*e+j*d,c[5]=g*e+k*d,c[6]=h*e+l*d,c[7]=i*e+m*d,c[8]=f*-d+j*e,c[9]=g*-d+k*e,c[10]=h*-d+l*e,c[11]=i*-d+m*e,c},mat4.rotateY=function(a,b,c){var d=Math.sin(b),e=Math.cos(b),f=a[0],g=a[1],h=a[2],i=a[3],j=a[8],k=a[9],l=a[10],m=a[11];return c?a!=c&&(c[4]=a[4],c[5]=a[5],c[6]=a[6],c[7]=a[7],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a,c[0]=f*e+j*-d,c[1]=g*e+k*-d,c[2]=h*e+l*-d,c[3]=i*e+m*-d,c[8]=f*d+j*e,c[9]=g*d+k*e,c[10]=h*d+l*e,c[11]=i*d+m*e,c},mat4.rotateZ=function(a,b,c){var d=Math.sin(b),e=Math.cos(b),f=a[0],g=a[1],h=a[2],i=a[3],j=a[4],k=a[5],l=a[6],m=a[7];return c?a!=c&&(c[8]=a[8],c[9]=a[9],c[10]=a[10],c[11]=a[11],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a,c[0]=f*e+j*d,c[1]=g*e+k*d,c[2]=h*e+l*d,c[3]=i*e+m*d,c[4]=f*-d+j*e,c[5]=g*-d+k*e,c[6]=h*-d+l*e,c[7]=i*-d+m*e,c},mat4.frustum=function(a,b,c,d,e,f,g){g||(g=mat4.create());var h=b-a,i=d-c,j=f-e;return g[0]=e*2/h,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=e*2/i,g[6]=0,g[7]=0,g[8]=(b+a)/h,g[9]=(d+c)/i,g[10]=-(f+e)/j,g[11]=-1,g[12]=0,g[13]=0,g[14]=-(f*e*2)/j,g[15]=0,g},mat4.perspective=function(a,b,c,d,e){var f=c*Math.tan(a*Math.PI/360),g=f*b;return mat4.frustum(-g,g,-f,f,c,d,e)},mat4.ortho=function(a,b,c,d,e,f,g){g||(g=mat4.create());var h=b-a,i=d-c,j=f-e;return g[0]=2/h,g[1]=0,g[2]=0,g[3]=0,g[4]=0,g[5]=2/i,g[6]=0,g[7]=0,g[8]=0,g[9]=0,g[10]=-2/j,g[11]=0,g[12]=-(a+b)/h,g[13]=-(d+c)/i,g[14]=-(f+e)/j,g[15]=1,g},mat4.lookAt=function(a,b,c,d){d||(d=mat4.create());var e=a[0],f=a[1],g=a[2],h=c[0],i=c[1],j=c[2],k=b[0],l=b[1],m=b[2];if(e==k&&f==l&&g==m)return mat4.identity(d);var n,o,p,q,r,s,t,u,v,w;return n=e-b[0],o=f-b[1],p=g-b[2],w=1/Math.sqrt(n*n+o*o+p*p),n*=w,o*=w,p*=w,q=i*p-j*o,r=j*n-h*p,s=h*o-i*n,w=Math.sqrt(q*q+r*r+s*s),w?(w=1/w,q*=w,r*=w,s*=w):(q=0,r=0,s=0),t=o*s-p*r,u=p*q-n*s,v=n*r-o*q,w=Math.sqrt(t*t+u*u+v*v),w?(w=1/w,t*=w,u*=w,v*=w):(t=0,u=0,v=0),d[0]=q,d[1]=t,d[2]=n,d[3]=0,d[4]=r,d[5]=u,d[6]=o,d[7]=0,d[8]=s,d[9]=v,d[10]=p,d[11]=0,d[12]=-(q*e+r*f+s*g),d[13]=-(t*e+u*f+v*g),d[14]=-(n*e+o*f+p*g),d[15]=1,d},mat4.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+"]"},quat4={},quat4.create=function(a){var b=new glMatrixArrayType(4);return a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]),b},quat4.set=function(a,b){return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b},quat4.calculateW=function(a,b){var c=a[0],d=a[1],e=a[2];return!b||a==b?(a[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e)),a):(b[0]=c,b[1]=d,b[2]=e,b[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e)),b)},quat4.inverse=function(a,b){return!b||a==b?(a[0]*=-1,a[1]*=-1,a[2]*=-1,a):(b[0]=-a[0],b[1]=-a[1],b[2]=-a[2],b[3]=a[3],b)},quat4.length=function(a){var b=a[0],c=a[1],d=a[2],e=a[3];return Math.sqrt(b*b+c*c+d*d+e*e)},quat4.normalize=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],f=a[3],g=Math.sqrt(c*c+d*d+e*e+f*f);return g==0?(b[0]=0,b[1]=0,b[2]=0,b[3]=0,b):(g=1/g,b[0]=c*g,b[1]=d*g,b[2]=e*g,b[3]=f*g,b)},quat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],f=a[2],g=a[3],h=b[0],i=b[1],j=b[2],k=b[3];return c[0]=d*k+g*h+e*j-f*i,c[1]=e*k+g*i+f*h-d*j,c[2]=f*k+g*j+d*i-e*h,c[3]=g*k-d*h-e*i-f*j,c},quat4.multiplyVec3=function(a,b,c){c||(c=b);var d=b[0],e=b[1],f=b[2],g=a[0],h=a[1],i=a[2],j=a[3],k=j*d+h*f-i*e,l=j*e+i*d-g*f,m=j*f+g*e-h*d,n=-g*d-h*e-i*f;return c[0]=k*j+n*-g+l*-i-m*-h,c[1]=l*j+n*-h+m*-g-k*-i,c[2]=m*j+n*-i+k*-h-l*-g,c},quat4.toMat3=function(a,b){b||(b=mat3.create());var c=a[0],d=a[1],e=a[2],f=a[3],g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return b[0]=1-(m+o),b[1]=k-r,b[2]=l+q,b[3]=k+r,b[4]=1-(j+o),b[5]=n-p,b[6]=l-q,b[7]=n+p,b[8]=1-(j+m),b},quat4.toMat4=function(a,b){b||(b=mat4.create());var c=a[0],d=a[1],e=a[2],f=a[3],g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return b[0]=1-(m+o),b[1]=k-r,b[2]=l+q,b[3]=0,b[4]=k+r,b[5]=1-(j+o),b[6]=n-p,b[7]=0,b[8]=l-q,b[9]=n+p,b[10]=1-(j+m),b[11]=0,b[12]=0,b[13]=0,b[14]=0,b[15]=1,b},quat4.slerp=function(a,b,c,d){d||(d=a);var e=a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3];if(Math.abs(e)>=1)return d!=a&&(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3]),d;var f=Math.acos(e),g=Math.sqrt(1-e*e);if(Math.abs(g)<.001)return d[0]=a[0]*.5+b[0]*.5,d[1]=a[1]*.5+b[1]*.5,d[2]=a[2]*.5+b[2]*.5,d[3]=a[3]*.5+b[3]*.5,d;var h=Math.sin((1-c)*f)/g,i=Math.sin(c*f)/g;return d[0]=a[0]*h+b[0]*i,d[1]=a[1]*h+b[1]*i,d[2]=a[2]*h+b[2]*i,d[3]=a[3]*h+b[3]*i,d},quat4.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"},WebGLUtils=function(){var a=function(a){return'<table style="background-color: #8CE; width: 100%; height: 100%;"><tr><td align="center"><div style="display: table-cell; vertical-align: middle;"><div style="">'+a+"</div>"+"</div>"+"</td></tr></table>"},b='This page requires a browser that supports WebGL.<br/><a href="http://get.webgl.org" target="_blank">Click here to upgrade your browser.</a>',c='It doesn\'t appear your computer can support WebGL.<br/><a href="http://get.webgl.org/troubleshooting/" target="_blank">Click here for more information.</a>',d=function(d,f){function g(b){var c=d.parentNode;c&&(c.innerHTML=a(b))}if(!window.WebGLRenderingContext)return g(b),null;var h=e(d,f);return h||g(c),h},e=function(a,b){var c=["webgl","experimental-webgl","webkit-3d","moz-webgl"],d=null;for(var e=0;e<c.length;++e){try{d=a.getContext(c[e],b)}catch(f){}if(d)break}return d};return{create3DContext:e,setupWebGL:d}}(),window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a,b){window.setTimeout(a,1e3/60)}}(),function(){function d(b){for(var d in b)a[d]=b[d],c[d]=b[d]}"use strict";var a={version:"0.7"},b={declare:function(a,c){$.each(c,function(c,d){function g(){throw new Error("Property '"+c+"' is read-only.")}if(d===null||d.value===undefined&&!d.get)d={value:d};d.name=c;var e=d.internal||c.substr(0,2)==="__";d.enumerable===undefined&&(d.enumerable=!e);if(d.type===undefined&&!d.get&&!e){var f=typeof d.value;f==="number"?d.type=b.check_number:f==="string"?d.type=b.check_string:d.value instanceof attributeVector?d.type=b.check_attributeVector:d.value instanceof vec&&(d.type=b.check_vec)}if(d.readonly&&d.set||d.onchanged&&d.set||d.value!==undefined&&d.get)throw new Error("Erroneous property definition '"+c+"'.");if(d.get)Object.defineProperty(a,c,{enumerable:d.enumerable,get:d.get,set:d.set||g});else if(!d.type&&!d.onchanged)Object.defineProperty(a,c,{enumerable:d.enumerable,writable:!d.readonly,value:d.value});else{var e="__"+c,h={enumerable:d.enumerable,get:function(){return this[e]}};d.set?h.set=d.set:d.onchanged&&d.type?h.set=function(a){var b=this[e];this[e]=d.type.call(this,a,d),d.onchanged.call(this,b)}:d.onchanged?h.set=function(a){var b=this[e];this[e]=a,d.onchanged.call(this,b)}:d.type&&(h.set=function(a){this[e]=d.type.call(this,a,d)}),Object.defineProperty(a,e,{enumerable:!1,writable:!0,value:d.value}),Object.defineProperty(a,c,h)}})},nullable_attributeVector:function(a,c){return a===null?null:b.check_attributeVector.call(this,a,c)},check_attributeVector:function(a,b){if(a instanceof vec)return new attributeVector(this,a.x,a.y,a.z);throw new Error("Property '"+b.name+"' must be a vec.")},check_vec:function(a,b){if(!a instanceof vec)throw new Error("Property '"+b.name+"' must be a vec.");return a},check_number:function(a,b){return a},check_string:function(a,b){return a}},c=window,e={glowscript:a,property:b,Export:d};d(e)}(),function(){function a(b,c,d){if(!(this instanceof a))return arguments.length==1&&b.x!==undefined?new a(b.x,b.y,b.z):new a(b,c,d);this.x=b,this.y=c,this.z=d;if(arguments.length!==3)throw new Error("vec() requires 3 arguments: x, y, and z.")}function b(a,b,c,d){this.__parent=a,this.__x=b,this.__y=c,this.__z=d,a&&a.__change()}"use strict",b.prototype=new a(0,0,0),b.prototype.constructor=b,Object.defineProperty(b.prototype,"__x",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(b.prototype,"x",{enumerable:!0,get:function(){return this.__x},set:function(a){this.__x=a,this.__parent.__change()}}),Object.defineProperty(b.prototype,"__y",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(b.prototype,"y",{enumerable:!0,get:function(){return this.__y},set:function(a){this.__y=a,this.__parent.__change()}}),Object.defineProperty(b.prototype,"__z",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(b.prototype,"z",{enumerable:!0,get:function(){return this.__z},set:function(a){this.__z=a,this.__parent.__change()}}),a.prototype.toString=function(){var a=[this.x,this.y,this.z],b=[],c,d,e,f,g;for(var h=0;h<3;h++){var c=a[h];if(c==0){b.push("0");continue}Math.abs(c)<1e-4?c=c.toExponential(5):c=c.toPrecision(6),e=c.indexOf(".");if(e>=0){g=c.indexOf("e"),g<0&&(g=c.length),f=g;for(;;){f--;if(c.charAt(f)=="0")continue;if(f==e){b.push(c.slice(0,e).concat(c.slice(g,c.length)));break}g==c.length?b.push(c.slice(0,f+1)):b.push(c.slice(0,f+1).concat(c.slice(g,c.length)));break}}else b.push(c)}return"< "+b[0]+", "+b[1]+", "+b[2]+" >"},a.prototype.add=function(b){return new a(this.x+b.x,this.y+b.y,this.z+b.z)},a.prototype.sub=function(b){return new a(this.x-b.x,this.y-b.y,this.z-b.z)},a.prototype.multiply=function(b){return new a(this.x*b,this.y*b,this.z*b)},a.prototype.divide=function(b){return new a(this.x/b,this.y/b,this.z/b)},a.prototype.mag=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},a.prototype.mag2=function(){return this.x*this.x+this.y*this.y+this.z*this.z},a.prototype.norm=function(){var b=this.mag();return b==0?new a(0,0,0):new a(this.x/b,this.y/b,this.z/b)},a.prototype.dot=function(a){return this.x*a.x+this.y*a.y+this.z*a.z},a.prototype.equals=function(a){return this.x==a.x&&this.y==a.y&&this.z==a.z},a.prototype.proj=function(a){var b=norm(a);return b.multiply(this.dot(b))},a.prototype.comp=function(a){return this.dot(norm(a))},a.prototype.cross=function(b){return new a(this.y*b.z-this.z*b.y,this.z*b.x-this.x*b.z,this.x*b.y-this.y*b.x)},a.prototype.diff_angle=function(a){return Math.acos(this.norm().dot(a.norm()))},a.prototype.rotate=function(b){if(b.angle===undefined)throw new Error("To rotate a vector you must specify { angle:.. }");var c=b.angle,d;b.axis===undefined?d=new a(0,0,1):d=b.axis;var e=this.diff_angle(d);if(e==0)return new a(this.x,this.y,this.z);var d=d.norm(),f=d.multiply(d.dot(this)),g=d.cross(this),h=g.mag();g=g.norm();var i=g.cross(d),j=i.multiply(h*Math.cos(c)).add(g.multiply(h*Math.sin(c)));return f.add(j)},a.random=function(){return new a(-1+2*Math.random(),-1+2*Math.random(),-1+2*Math.random())},String.prototype["+"]=function(a){return this+a},Number.prototype["+"]=function(a){return this+a},Number.prototype["-"]=function(a){return this-a},Number.prototype["*"]=function(a){return a["*r"](this)},Number.prototype["*r"]=function(a){return a*this},Number.prototype["/"]=function(a){return this/a},Number.prototype["-u"]=function(){return-this},a.prototype["+"]=a.prototype.add,a.prototype["-"]=a.prototype.sub,a.prototype["*"]=a.prototype.multiply,a.prototype["*r"]=a.prototype.multiply,a.prototype["/"]=function(a){return this.divide(a)},a.prototype["-u"]=function(){return new a(-this.x,-this.y,-this.z)};var c={vec:a,attributeVector:b};Export(c)}(),function(){function a(a){return a.mag()}function b(a){return a.mag2()}function c(a){return a.norm()}"use strict";var d={mag:a,mag2:b,norm:c};Export(d)}(),function(){function a(){this.vertices=[],this.normals=[],this.tcoords=[],this.bumpaxis=[],this.indices=[]}"use strict",$.extend(a.prototype,{merge:function c(a){var b=this.vertices.length/3;for(var c=0;c<a.vertices.length;c++)this.vertices.push(a.vertices[c]);for(var c=0;c<a.normals.length;c++)this.normals.push(a.normals[c]);for(var c=0;c<a.tcoords.length;c++)this.normals.push(a.tcoords[c]);for(var c=0;c<a.indices.length;c++)this.indices.push(b+a.indices[c])},transformed:function d(b){var c=mat3.toMat4(mat3.transpose(mat4.toInverseMat3(b))),d=new a;d.indices=this.indices;for(var e=0;e<this.vertices.length;e+=3){var f=[this.vertices[e],this.vertices[e+1],this.vertices[e+2]],g=[this.normals[e],this.normals[e+1],this.normals[e+2],0];mat4.multiplyVec3(b,f),mat4.multiplyVec4(c,g),d.vertices.push(f[0],f[1],f[2]),d.normals.push(g[0],g[1],g[2])}return d}}),$.extend(a,{makeCube:function(){var b=new a,c=.5;return b.vertices.push(+c,+c,+c,+c,-c,+c,+c,-c,-c,+c,+c,-c,-c,+c,-c,-c,-c,-c,-c,-c,+c,-c,+c,+c,-c,-c,+c,-c,-c,-c,+c,-c,-c,+c,-c,+c,-c,+c,-c,-c,+c,+c,+c,+c,+c,+c,+c,-c,-c,+c,+c,-c,-c,+c,+c,-c,+c,+c,+c,+c,+c,+c,-c,+c,-c,-c,-c,-c,-c,-c,+c,-c),b.normals.push(1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1),b.tcoords.push(0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1),b.bumpaxis.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0),b.indices.push(0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23),b},makeQuad:function(){var b=new a;return b.vertices.push(-1,-1,0,1,-1,0,1,1,0,-1,1,0),b.normals.push(0,0,1,0,0,1,0,0,1,0,0,1),b.tcoords.push(0,0,1,0,1,1,0,1),b.bumpaxis.push(1,0,0,1,0,0,1,0,0,1,0,0),b.indices.push(0,1,2,0,2,3),b},makeCylinder:function(b){var c=50,d=2*Math.PI/c,e=Math.sin(d),f=Math.cos(d),g=0,h=-b,i,j,k=new a;k.vertices=[0,0,0,1,0,0],k.normals=[-1,0,0,1,0,0],k.tcoords=[.5,.5,.5,.5],k.bumpaxis=[0,0,-1,0,0,-1],k.indices=[];for(var l=2;l<=2+4*c;l+=4)k.vertices.push(0,g,h,0,g,h,1,g,h,1,g,h),k.normals.push(-1,0,0,0,g,h,1,0,0,0,g,h),k.tcoords.push(.5*(1+h/b),.5+.5*g/b,1-(l-2)/c/4,0,.5*(1-h/b),.5+.5*g/b,1-(l-2)/c/4,1),k.bumpaxis.push(1,0,0,1,0,0,1,0,0,1,0,0),l!=2+4*c&&k.indices.push(0,l,l+4,l+1,l+3,l+7,l+1,l+7,l+5,1,l+6,l+2),i=g*f+h*e,j=h*f-g*e,g=i,h=j;return k},makeSphere:function(b,c){var d=c,e=c,f=Math.PI/d,g=2*Math.PI/e,h=Math.sin(f),i=Math.cos(f),j=Math.sin(g),k=Math.cos(g),l=new a,m,n,o,p,q,r,s,t,u,v,w,x;m=b,o=0,q=0;for(w=0;w<d;w++){n=m*i-q*h,p=0,v=r=q*i+m*h;for(x=0;x<=e;x+=1)l.vertices.push(m,o,-q),l.normals.push(m/b,o/b,-q/b),l.tcoords.push(1-x/e,1-w/d),l.bumpaxis.push(0,q/b,o/b),u=w*(e+1),x!=e&&l.indices.push(u+x,u+x+1,u+x+e+2,u+x,u+x+e+2,u+x+e+1),s=o*k+q*j,t=q*k-o*j,o=s,q=t;m=n,o=0,q=v;if(w==d-1){q=b;for(x=0;x<=e;x+=1)l.vertices.push(-b,0,0),l.normals.push(-1,0,0),l.tcoords.push(1-x/e,0),l.bumpaxis.push(0,q/b,o/b),s=o*k+q*j,t=q*k-o*j,o=s,q=t}}return l},makeCone:function(b){var c=100,d=2*Math.PI/c,e=Math.sin(d),f=Math.cos(d),g=1/Math.sqrt(2),h=0,i=-b,j,k,l=new a;l.vertices.push(0,0,0),l.normals.push(-1,0,0),l.tcoords.push(.5,.5),l.bumpaxis.push(0,0,1);for(var m=1;m<=1+3*c;m+=3)j=h*f+i*e,k=i*f-h*e,l.vertices.push(0,h,i,0,h,i,1,0,0),l.normals.push(-1,0,0,g,g*h,g*i,g,g*(h+j)/2,g*(i+k)/2),l.tcoords.push(.5*(1+i/b),.5*(1+h/b),1-(m-1)/c/3,0,1-(m-1)/c/3,1),l.bumpaxis.push(0,0,1,0,0,1,0,-i,h),m!=1+3*c&&l.indices.push(0,m,m+3,m+1,m+2,m+4),h=j,i=k;return l},makePyramid:function(){var b=new a;return b.vertices.push(0,.5,.5,0,.5,-0.5,0,-0.5,-0.5,0,-0.5,.5,0,.5,-0.5,0,.5,.5,1,0,0,0,-0.5,-0.5,0,.5,-0.5,1,0,0,0,-0.5,.5,0,-0.5,-0.5,1,0,0,0,.5,.5,0,-0.5,.5,1,0,0),b.normals.push(-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,2,0,1,2,0,1,2,0,1,0,-2,1,0,-2,1,0,-2,1,-2,0,1,-2,0,1,-2,0,1,0,2,1,0,2,1,0,2),b.tcoords.push(1,1,0,1,0,0,1,0,0,0,.25,0,.125,1,1,0,.75,0,.875,1,.5,0,.75,0,.625,1,.25,0,.5,0,.375,1),b.bumpaxis.push(0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,-1,0,0,-1,0,0,-1,0,-1,0,0,-1,0,0,-1,0),b.indices.push(0,1,2,0,2,3,4,5,6,7,8,9,10,11,12,13,14,15),b},makeCurveSegment:function(b){var c=8,d=2*Math.PI/c,e=Math.sin(d),f=Math.cos(d),g=0,h=b,i,j,k=new a;for(var l=0;l<=2*c;l+=2)k.vertices.push(0,g,h,0,0,g,h,1),k.normals.push(0,g,h,0,g,h),k.tcoords.push(0,0,0,0),k.bumpaxis.push(0,0,0,0,0,0),l!=2*c&&k.indices.push(l,l+1,l+3,l,l+3,l+2),i=g*f+h*e,j=h*f-g*e,g=i,h=j;var m=k.vertices.length/4,n=a.makeSphere(b,c);for(var l=0;l<n.vertices.length;l+=3)k.vertices.push(n.vertices[l],n.vertices[l+1],n.vertices[l+2],1);for(var l=0;l<n.normals.length;l++)k.normals.push(n.normals[l]),k.tcoords.push(n.tcoords[l]),k.bumpaxis.push(n.bumpaxis[l]);for(var l=0;l<n.indices.length;l++)k.indices.push(n.indices[l]+m);return k}});var b={Mesh:a};Export(b)}(),function(){function a(c){if(!(this instanceof a))return new a(c);c||(c={}),a.all.push(this),a.selected=this;for(var d in c)this[d]=c[d];this.events=$("<div/>"),this.wrapper=$("<div/>"),this.title=$("<div/>"),this.caption=$("<div/>"),this.__canvas_element=document.createElement("canvas"),this.__overlay_element=document.createElement("canvas"),this.elements=$([this.__canvas_element,this.__overlay_element]),this.__overlay_objects={objects:[],__changed:!1},this.__visiblePrimitives={},this.lights=[{direction:vec(.21821789,.4364357,.8728715),color:vec(.8,.8,.8)},{direction:vec(-0.872872,-0.218218,-0.436436),color:vec(.3,.3,.3)}],this.trails=[],this.arrows=[],this.camera=orbital_camera(this),this.mouse=new b(this),this.textures={},this.textures_requested={},this.__changed={},this.visible=!0,this.waitfor_textures=!1}function b(a){this.canvas=a}"use strict",property.declare(a.prototype,{__activate:function(){this.__activated=!0,this.__activate=function(){};var b=a.container;this.title.css("white-space","pre").appendTo(b),this.wrapper.addClass("glowscript-canvas-wrapper").appendTo(b),this.caption.css("white-space","pre").appendTo(b),this.wrapper.css("position","relative");var c=this.__canvas_element;c.style.position="absolute";var d=this.__overlay_element;d.style.position="relative",d.style.backgroundColor="transparent",this.__change_size(),this.wrapper.append(c),this.wrapper.append(d),this.__renderer=new WebGLRenderer(this,c,d),this.camera.__activate&&this.camera.__activate(),this.__handleEvents()},__change_size:function(){this.__activated&&(this.__canvas_element.setAttribute("width",this.width),this.__overlay_element.setAttribute("width",this.width),this.__canvas_element.setAttribute("height",this.height),this.__overlay_element.setAttribute("height",this.height))},__handleEvents:function(){var a=this,b=a.elements,c=!1;b.bind("click",function(b){a.mouse.__update(b),b.which==1&&!a.camera.mouse_locked&&a.trigger("click",b)}),b.bind("mousedown",function(b){return b.which==1&&!a.camera.mouse_locked&&(c=!0,a.mouse.__update(b),a.trigger("mousedown",b)),b.preventDefault(),b.stopPropagation(),!1}),b.bind("mouseenter mouseleave",function(b){a.mouse.__update(b),a.trigger(b.type,b)}),$(document).bind("mousemove",function(b){a.mouse.__update(b),a.trigger("mousemove",b)}),$(document).bind("mouseup",function(b){a.mouse.__update(b),b.which==1&&c&&(c=!1,a.trigger("mouseup",b))});var d={shift:16,ctrl:17,alt:18};$(document).bind("keydown keyup",function(b){for(var c in d)if(d[c]==b.which){a.mouse[c]=b.type=="keydown";break}})},__change:function(){},waitfor:function(a,b){return a=="textures"&&(this.waitfor_textures=!0),this.events.waitfor(a,b)},pause:function(a,b){if(arguments.length>1)this.__prompt==undefined&&(this.__prompt=label({align:"right",pixel_pos:!0,height:14,color:color.black,background:color.white,opacity:1,box:!1})),this.__prompt.pos=vec(this.__width,this.__height-12,0),this.__prompt.text=a,this.__prompt.visible=!0,this.events.pause(this.__prompt,b);else{this.__draw==undefined&&(this.__draw=draw());var c=this.width-5,d=this.height-20;this.__draw.points=[vec(c,d,0),vec(c-30,d-13,0),vec(c-30,d+15,0),vec(c,d,0)],this.__draw.opacity=1,this.__draw.color=color.black,this.__draw.fillcolor=color.white,this.__draw.visible=!0,this.events.pause(this.__draw,a)}},bind:function(a,b){return this.events.bind(a,b)},unbind:function(a,b){return this.events.unbind(a,b)},one:function(a,b){return this.events.one(a,b)},trigger:function(a,b){var c=new $.Event(a,b);c.stopPropagation(),c.preventDefault(),this.events.trigger(c)},background:new attributeVector(null,0,0,0),ambient:new attributeVector(null,.2,.2,.2),center:new attributeVector(null,0,0,0),forward:new attributeVector(null,0,0,-1),up:new attributeVector(null,0,1,0),__last_forward:null,__last_range:null,__activated:!1,userzoom:!0,userspin:!0,fov:60*Math.PI/180,autoscale:{value:!0,onchanged:function(a){a&&!this.autoscale&&Autoscale.compute_autoscale(this)}},width:{value:640,onchanged:function(){this.__change_size()}},height:{value:400,onchanged:function(){this.__change_size()}},range:{value:10,onchanged:function(){this.__autoscale=!1}},objects:{get:function(){var a=[];for(var b in this.__visiblePrimitives)a.push(this.__visiblePrimitives[b]);return a}}}),property.declare(a,{selected:{get:function(){return window.__context.canvas_selected||null},set:function(a){window.__context.canvas_selected=a}},all:{get:function(){var a=window.__context.canvas_all;return a===undefined&&(a=window.__context.canvas_all=[]),a}},container:{get:function(){return window.__context.glowscript_container||null},set:function(a){window.__context.glowscript_container=$(a)}}}),property.declare(b.prototype,{canvas:null,pos:null,ray:null,__pickx:null,__picky:null,pick:function(){return this.canvas.__renderer.render(1)},project:function(a){if(a.normal===undefined)throw new Error("scene.mouse.project() must specify a normal in {normal:..}");var b=a.normal,c;a.d===
undefined&&a.point===undefined?c=b.dot(this.canvas.__center):a.d!==undefined?c=a.d:a.point!==undefined&&(c=b.dot(a.point));var d=b.dot(this.canvas.camera.pos)-c,e=b.dot(this.ray);if(e==0)return null;var f=-d/e;return this.canvas.camera.pos.add(this.ray.multiply(f))},alt:!1,ctrl:!1,shift:!1,__update:function(a){var b=this.canvas,c;b.__width>b.__height?c=2*b.__range/b.__height:c=2*b.__range/b.__width;var d=$(b.__canvas_element).offset();this.__pickx=a.pageX-d.left,this.__picky=b.__height-(a.pageY-d.top);var e=(this.__pickx-b.__width/2)*c,f=(this.__picky-b.__height/2)*c,g=b.__forward.norm().cross(b.__up).norm(),h=g.cross(b.__forward.norm());this.pos=b.__center.add(g.multiply(e).add(h.multiply(f))),this.ray=this.pos.sub(b.camera.pos).norm()}});var c={canvas:a};Export(c)}(),function(){function a(b,c){if(this instanceof a)this.canvas=b,this.follower=null;else return new a(b,c)}"use strict",property.declare(a.prototype,{pos:{get:function(){var a=this.canvas;return a.center.sub(a.forward.norm().multiply(a.range/Math.tan(a.fov/2)))}},mouse_locked:{value:!1,type:null},follow:function(a){this.follower=a},__activate:function(){var a=this.canvas,b=this,c=!1,d=null,e=null,f=null,g=null,h=!1,i=!1,j=!1,k=!1,l=function(b,c){var d=Math.exp(-c*.05);a.range=a.range*d};$(document).bind("contextmenu",function(a){return!c}),a.elements.mousewheel(function(b,c){return a.userzoom&&l(b,c),!1}),a.elements.mousedown(function(f){f.which==1&&(h=!0),f.which==3&&(i=!0),j=a.userspin&&(f.which==3||f.which==1&&a.mouse.ctrl&&!a.mouse.alt),k=a.userzoom&&(f.which==2||f.which==1&&a.mouse.alt&&!a.mouse.ctrl||h&&i);if(j||k)return b.mouse_locked=!0,c=!0,d=f.pageX,e=f.pageY,f.preventDefault(),f.stopPropagation(),!1}),$(document).mousemove(function(b){if(k){var c=e-b.pageY;e=b.pageY,l(b,.1*c)}else if(j){var h=b.pageX-d,c=b.pageY-e;d=b.pageX,e=b.pageY,f+=h*.01,g+=c*.01,g<-1.4&&(g=-1.4),g>1.4&&(g=1.4);var i=a.range/Math.tan(a.fov/2);a.forward=a.forward.rotate({angle:-0.01*h,axis:a.up});var m=a.up.diff_angle(a.forward.multiply(-1)),n=.01*c;n>=m||n<=m-Math.PI||(a.__forward=a.__forward.rotate({angle:-n,axis:a.__forward.cross(a.__up)}))}}),$(document).mouseup(function(a){a.which==1&&(h=!1),a.which==3&&(i=!1),a.which==3&&c&&setTimeout(function(){c=!1},0);if(j||k)return j=k=!1,b.mouse_locked=!1,!1})}});var b={orbital_camera:a};Export(b)}(),function(){function a(){}"use strict",$.extend(a.prototype,{xmin:null,ymin:null,zmin:null,xmax:null,ymax:null,zmax:null,zx_camera:0,zy_camera:0,last_zx_camera:-1,last_zy_camera:-1,find_autocenter:!1,point_extent:function(a,b){this.xmin=Math.min(b.x,this.xmin),this.ymin=Math.min(b.y,this.ymin),this.zmin=Math.min(b.z,this.zmin),this.xmax=Math.max(b.x,this.xmax),this.ymax=Math.max(b.y,this.ymax),this.zmax=Math.max(b.z,this.zmax),a.__xmin=Math.min(b.x,a.__xmin),a.__ymin=Math.min(b.y,a.__ymin),a.__zmin=Math.min(b.z,a.__zmin),a.__xmax=Math.max(b.x,a.__xmax),a.__ymax=Math.max(b.y,a.__ymax),a.__zmax=Math.max(b.z,a.__zmax)}});var b={Autoscale:{compute_autocenter:function c(b){var c=b.__extent;c||(c=b.__extent=new a),c.find_autocenter=!0,c.xmin=null,c.ymin=null,c.zmin=null,c.xmax=null,c.ymax=null,c.zmax=null,c.zx_camera=0,c.zy_camera=0;var d=1/Math.tan(b.__fov/2);c.__cot_hfov=d,c.__centerx=b.center.x,c.__centery=b.center.y,c.__centerz=b.center.z;var e=!1,f;for(var g in b.__visiblePrimitives)f=b.__visiblePrimitives[g],e=!0,b.__changed[f.__id]?f.__get_extent(c):(c.xmin=Math.min(c.xmin,f.__xmin),c.ymin=Math.min(c.ymin,f.__ymin),c.zmin=Math.min(c.zmin,f.__zmin),c.xmax=Math.max(c.xmax,f.__xmax),c.ymax=Math.max(c.ymax,f.__ymax),c.zmax=Math.max(c.zmax,f.__zmax));e&&(b.center=vec((c.xmin+c.xmax)/2,(c.ymin+c.ymax)/2,(c.zmin+c.zmax)/2)),c.find_autocenter=!1},compute_autoscale:function d(b){var c=b.__extent;c||(c=b.__extent=new a);var d=b.center.x,e=b.center.y,f=b.center.z,g=b.__visiblePrimitives;c.zx_camera=0,c.zy_camera=0;var h=1/Math.tan(b.__fov/2);c.__cot_hfov=h,c.__centerx=b.center.x,c.__centery=b.center.y,c.__centerz=b.center.z;var i=!1,j;for(var k in g){j=g[k],i=!0;if(b.__changed[j.__id]||j.__zx_camera==null||j.__zy_camera==null){j.__get_extent(c);var l=Math.max(Math.abs(j.__xmin-d),Math.abs(j.__xmax-d)),m=Math.max(Math.abs(j.__ymin-e),Math.abs(j.__ymax-e)),n=Math.max(Math.abs(j.__zmin-f),Math.abs(j.__zmax-f));j.__zx_camera=l*h+n,j.__zy_camera=m*h+n}c.zx_camera=Math.max(c.zx_camera,j.__zx_camera),c.zy_camera=Math.max(c.zy_camera,j.__zy_camera)}if(i)if(c.zx_camera>c.last_zx_camera||c.zx_camera<c.last_zx_camera/3||c.zy_camera>c.last_zy_camera||c.zy_camera<c.last_zy_camera/3){var o=c.zx_camera*b.__height/b.__width;o>c.zy_camera?b.__width>=b.__height?b.__range=1.1*(b.__height/b.__width)*c.zx_camera/h:b.__range=1.1*c.zx_camera/h:b.__width>=b.__height?b.__range=1.1*c.zy_camera/h:b.__range=1.1*(b.__width/b.__height)*c.zy_camera/h,c.last_zx_camera=c.zx_camera,c.last_zy_camera=c.zy_camera}},find_extent:function e(a,b){var c=a.__size,d=c.__x,e=c.__y,f=c.__z,g=a.__pos,h=g.__x,i=g.__y,j=g.__z,k=a.__hasPosAtCenter,l;k?l=Math.sqrt(d*d+e*e+f*f)/2:l=Math.sqrt(d*d+e*e/4+f*f/4);if(!b.find_autocenter){var m=h-b.__centerx,n=i-b.__centery,o=j-b.__centerz,p=(Math.abs(m)+l)*b.__cot_hfov+Math.abs(o)+l,q=(Math.abs(n)+l)*b.__cot_hfov+Math.abs(o)+l;if(p<b.zx_camera&&q<b.zy_camera){a.__zx_camera=null,a.__zy_camera=null;return}}var r=a.__axis.norm(),s=a.__up.norm();k&&(g=g.sub(r.multiply(d/2)));var t=r.multiply(d),u=r.cross(s).norm();u.dot(u)<1e-10&&(u=r.cross(vec(1,0,0)).norm(),u.dot(u)<1e-10&&(u=r.cross(vec(0,1,0)).norm()));var v=u.cross(r),w=g.add(v.multiply(-e/2).add(u.multiply(-f/2))),x=w.add(v.multiply(e)),y=w.add(u.multiply(f)),z=x.add(u.multiply(f)),A=w.add(t),B=x.add(t),C=y.add(t),D=z.add(t);b.point_extent(a,w),b.point_extent(a,x),b.point_extent(a,y),b.point_extent(a,z),b.point_extent(a,A),b.point_extent(a,B),b.point_extent(a,C),b.point_extent(a,D)}}};Export(b)}(),function(){function o(o,p,q){function I(a){G[a]=s.createTexture(),s.bindTexture(s.TEXTURE_2D,G[a]),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,E,F,0,s.RGBA,s.UNSIGNED_BYTE,null),s.bindTexture(s.TEXTURE_2D,null)}function M(a,b,c){function d(a,b,c){var d=c.createShader(b);c.shaderSource(d,a),c.compileShader(d);if(!c.getShaderParameter(d,c.COMPILE_STATUS))throw alert(c.getShaderInfoLog(d)),new Error("Shader compile error");return d}var e=d(b,c.VERTEX_SHADER,c),f=d(a,c.FRAGMENT_SHADER,c),g=c.createProgram();c.attachShader(g,e),c.attachShader(g,f),c.linkProgram(g);if(!c.getProgramParameter(g,c.LINK_STATUS))throw alert(c.getProgramInfoLog(g)),new Error("Shader link error");var h=c.getProgramParameter(g,c.ACTIVE_UNIFORMS);g.uniforms={};for(var i=0;i<h;i++){var j=c.getActiveUniform(g,i),k=j.name;k.substring(k.length-3)=="[0]"&&(k=k.substring(0,k.length-3)),g.uniforms[k]=c.getUniformLocation(g,k)}var l=c.getProgramParameter(g,c.ACTIVE_ATTRIBUTES);g.attributes={};for(var i=0;i<l;i++){var j=c.getActiveAttrib(g,i);g.attributes[j.name]=c.getAttribLocation(g,j.name)}return g}function N(a){this.elementType=s.TRIANGLES,this.mesh=a,this.vertices=new Float32Array(a.vertices),this.normals=new Float32Array(a.normals),this.tcoords=new Float32Array(a.tcoords),this.bumpaxis=new Float32Array(a.bumpaxis),this.indices=new Uint16Array(a.indices),this.indexCount=this.indices.length,this.posBuffer=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,this.posBuffer),s.bufferData(s.ARRAY_BUFFER,this.vertices,s.STATIC_DRAW),this.normalBuffer=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,this.normalBuffer),s.bufferData(s.ARRAY_BUFFER,this.normals,s.STATIC_DRAW),this.textureBuffer=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,this.textureBuffer),s.bufferData(s.ARRAY_BUFFER,this.tcoords,s.STATIC_DRAW),this.bumpaxisBuffer=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,this.bumpaxisBuffer),s.bufferData(s.ARRAY_BUFFER,this.bumpaxis,s.STATIC_DRAW),this.indexBuffer=s.createBuffer(),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this.indexBuffer),s.bufferData(s.ELEMENT_ARRAY_BUFFER,this.indices,s.STATIC_DRAW)}function T(a,b,c){var d,e,f;c?(d=b.__tex.bumpmap,f=b.__tex.bumpmap_ref,e=b.__tex.bumpmap_t0):(d=b.__tex.file,f=b.__tex.texture_ref,e=b.__tex.texture_t0);var g=(new Date).getTime();g=g-e,d in o.textures?f.reference=o.textures[d]:(o.textures[d]=f.reference=s.createTexture(),s.bindTexture(s.TEXTURE_2D,f.reference),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!0),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,a),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR_MIPMAP_NEAREST),s.generateMipmap(s.TEXTURE_2D),s.bindTexture(s.TEXTURE_2D,null));if(d in o.textures_requested){var h=o.textures_requested[d];while(h.length>0){var i=h.pop();i[1]?i[0].__tex.bumpmap_ref.reference=f.reference:i[0].__tex.texture_ref.reference=f.reference,i[0].__change()}}}function Y(){window.requestAnimFrame(Y,p);var a=(new Date).getTime()*.001,b=a-X;X=a,o.trigger("redraw",{dt:b});var c=(new Date).getTime()*.001;r.render(!1);var a=(new Date).getTime()*.001,b=a-W;W=a,V=V*.95+(a-c)*1e3*.05,U=U*.95+1/(b+.001)*.05,$("#fps").text(U.toFixed(1)+" fps; "+V.toFixed(1)+" ms render"),o.trigger("draw_complete",{dt:b}),o.__last_forward=o.__forward,o.__last_range=o.__range}var r=this,s=WebGLUtils.setupWebGL(p);if(!s)throw new Error("Can't create canvas: WebGL not supported");o.overlay_context=q.getContext("2d");var t=null,u=null,v=null,w=null,x=null,y=null,z=null,A=null,B=null,C=null,D=1,E=D*o.__width,F=D*o.__height,G={C0:null,D0:null,D1:null,D2:null,C1:null,C2:null,C3:null,FINAL:null,EXTENT_TEXTURE:null},H={C0:s.TEXTURE2,D0:s.TEXTURE3,D1:s.TEXTURE4,D2:s.TEXTURE5,C1:s.TEXTURE6,C2:s.TEXTURE7,C3:s.TEXTURE8,FINAL:s.TEXTURE0,EXTENT_TEXTURE:s.TEXTURE9};for(var J in G)I(J);var K=s.createFramebuffer();s.bindFramebuffer(s.FRAMEBUFFER,K);var L=s.createRenderbuffer();s.bindRenderbuffer(s.RENDERBUFFER,L),s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_COMPONENT16,E,F),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,L),s.bindRenderbuffer(s.RENDERBUFFER,null),s.bindFramebuffer(s.FRAMEBUFFER,null);var O={box:new N(Mesh.makeCube()),pyramid:new N(Mesh.makePyramid()),cylinder:new N(Mesh.makeCylinder(.5)),cone:new N(Mesh.makeCone(.5)),sphere:new N(Mesh.makeSphere(.5,30)),quad:new N(Mesh.makeQuad())},P=this.models={curve:new N(Mesh.makeCurveSegment(1))},Q=0;P.compound=function(a){var b=new N(a);return b.id_object={},O[Q++]=b,b},P.compound.Mesh=Mesh;for(var R in O)P[R]=O[R];this.screenshot=function(a){o.waitfor("draw_complete",function(b){var c=new Image;c.src=p.toDataURL(),a(b,c)})},this.reset=function(){for(var a in P)P[a].id_object={}};var S={target:vec3.create([0,0,0]),up:vec3.create([0,1,0]),fovy:60,angleX:0,angleY:0,distance:1};this.reset(),this.initTexture=function(a,b,c){c?b.__tex.bumpmap=a:b.__tex.file=a;if(a in o.textures){c?b.__tex.bumpmap_ref.reference=o.textures[a]:b.__tex.texture_ref.reference=o.textures[a];return}if(a in o.textures_requested){o.textures_requested[a].push([b,c]);return}o.textures_requested[a]=[[b,c]];var d=(new Date).getTime();c?b.__tex.bumpmap_t0=d:b.__tex.texture_t0=d;var e=new Image;e.src=a,e.onload=function(){T(e,b,c)}};var U=0,V=0,W=(new Date).getTime()*.001,X=(new Date).getTime()*.001;this.render=function(q){function bj(a,b,c){bh=a,s.useProgram(a),s.enableVertexAttribArray(a.attributes.position),s.enableVertexAttribArray(a.attributes.normal),s.uniformMatrix4fv(a.uniforms.viewMatrix,!1,T),s.uniformMatrix4fv(a.uniforms.projMatrix,!1,R),s.enableVertexAttribArray(a.attributes.texcoord),s.enableVertexAttribArray(a.attributes.bumpaxis),s.uniform3fv(a.uniforms.center,S.target),s.uniform2fv(a.uniforms.canvas_size,bi),s.uniform1i(a.uniforms.light_count,X),s.uniform4fv(a.uniforms.light_pos,V),s.uniform3fv(a.uniforms.light_color,W),s.uniform3fv(a.uniforms.light_ambient,_),s.uniform1i(a.uniforms.texmap,0),s.uniform1i(a.uniforms.bumpmap,1),s.uniform1i(a.uniforms.minormode,b),s.uniform1i(a.uniforms.depthreference,c),s.uniform1i(a.uniforms.C0,2),s.uniform1i(a.uniforms.D0,3),s.uniform1i(a.uniforms.D1,4),s.uniform1i(a.uniforms.D2,5),s.uniform1i(a.uniforms.C1,6),s.uniform1i(a.uniforms.C2,7),s.uniform1i(a.uniforms.C3,8),s.uniform1i(a.uniforms.FINAL,0)}function bk(g,i,j,k){if(q==d)for(var l in k){var p=k[l];if(p==i)continue;s.activeTexture(H[p]),s.bindTexture(s.TEXTURE_2D,G[p])}i===null?s.bindFramebuffer(s.FRAMEBUFFER,null):(s.bindFramebuffer(s.FRAMEBUFFER,K),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,G[i],0)),s.viewport(0,0,E,F),s.enable(s.DEPTH_TEST),q==b||g>e?s.clearColor(0,0,0,0):q==c?s.clearColor(0,0,0,1):s.clearColor(o.__background.x,o.__background.y,o.__background.z,1),q==c?(s.depthFunc(s.GREATER),s.clearDepth(0)):(s.depthFunc(s.LEQUAL),s.clearDepth(1)),s.clear(s.COLOR_BUFFER_BIT|s.DEPTH_BUFFER_BIT);var r=P.curve,A=r.id_object,D=r.elementType,I=!0;for(var J in A){if(g>e)break;if(I){q==a||q==d&&g==e?(u==null&&(u=M(shaders.opaque_render_fragment,shaders.curve_render_vertex,s)),bj(u,0,0)):q==b&&(y==null&&(y=M(shaders.pick_fragment,shaders.curve_render_vertex,s)),bj(y,0,0)),s.bindBuffer(s.ARRAY_BUFFER,r.posBuffer),s.vertexAttribPointer(bh.attributes.position,4,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,r.normalBuffer),s.vertexAttribPointer(bh.attributes.normal,3,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,r.textureBuffer),s.vertexAttribPointer(bh.attributes.texcoord,2,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,r.bumpaxisBuffer),s.vertexAttribPointer(bh.attributes.bumpaxis,3,s.FLOAT,!1,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,r.indexBuffer),q==c&&(D=s.POINTS);if(q==b)var L=new Array(4);I=!1}var N=A[J],Q=N.__prevsegment;if(!N.visible||!N.__curve.visible)continue;if(q==b){var R=N.__falsecolor;for(var l=0;l<4;l++)L[l]=Q[8+l],L[l+4]=Q[12+l],Q[12+l]=Q[8+l]=R[l]}s.uniform4fv(bh.uniforms.segmentData,Q),s.drawElements(D,r.indexCount,s.UNSIGNED_SHORT,0);if(q==b)for(var l=0;l<8;l++)Q[8+l]=L[l]}for(var S in O){if(S=="quad")continue;var r=O[S];g>=m&&(r=O.quad);var A;g>f?A=bc[S].id_object:A=r.id_object;var I=!0,D=r.elementType;for(var J in A){var T=A[J],Q=T.__data;if(Q[19]<1)if(g==e||g==f)continue;if(I){f<=g&&g<=h?(w==null&&(w=M(shaders.peel_depth_fragment,shaders.pick_vertex,s)),bj(w,g,j)):g==m?(B==null&&(B=M(shaders.merge_fragment,shaders.merge_vertex,s)),bj(B,0,0)):g==n?(C==null&&(C=M(shaders.final_fragment,shaders.merge_vertex,s)),bj(C,0,0)):g>e?(v==null&&(v=M(shaders.peel_color_fragment,shaders.render_vertex,s)),bj(v,g,j)):q==a||q==d?(t==null&&(t=M(shaders.opaque_render_fragment,shaders.render_vertex,s)),bj(t,g,j)):q==b?(x==null&&(x=M(shaders.pick_fragment,shaders.pick_vertex,s)),bj(x,g,j)):q==c&&(z==null&&(z=M(shaders.pick_fragment,shaders.extent_vertex,s)),bj(z,g,j)),s.bindBuffer(s.ARRAY_BUFFER,r.posBuffer),s.vertexAttribPointer(bh.attributes.position,3,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,r.normalBuffer),s.vertexAttribPointer(bh.attributes.normal,3,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,r.textureBuffer),s.vertexAttribPointer(bh.attributes.texcoord,2,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,r.bumpaxisBuffer),s.vertexAttribPointer(bh.attributes.bumpaxis,3,s.FLOAT,!1,0,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,r.indexBuffer),q==c&&(D=s.POINTS);if(q==b)var L=new Array(4);I=!1}if(g<m){if((q==a||q==d)&&T.__tex.file!==null)if(T.__tex.texture_ref.reference!==null)s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,T.__tex.texture_ref.reference);else continue;if((q==a||q==d)&&T.__tex.bumpmap!==null)if(T.__tex.bumpmap_ref.reference!==null)s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,T.__tex.bumpmap_ref.reference);else if(T.__tex.texture_ref.reference===null)continue}else g==n&&(s.activeTexture(H.FINAL),s.bindTexture(s.TEXTURE_2D,G.FINAL));if(q==b){var R=T.__falsecolor;for(var l=0;l<4;l++)L[l]=Q[16+l],Q[16+l]=R[l]}s.uniform4fv(bh.uniforms.objectData,Q),s.drawElements(D,r.indexCount,s.UNSIGNED_SHORT,0);if(q==b)for(var l=0;l<4;l++)Q[16+l]=L[l];if(g>=m)break}}}if(q==a){var r=o.objects;if(o.waitfor_textures){for(var A in r){var D=r[A];if(D.__tex===undefined)continue;if(!D.ready)return}o.waitfor_textures=!1,o.trigger("textures",null)}}if(!o.visible){if(q==a)return;return null}o.autoscale&&Autoscale.compute_autoscale(o),o.camera.follower!==null&&(o.__center=typeof o.camera.follower!="function"?o.camera.follower.pos:o.camera.follower());if(q==a){for(var I in o.arrows){var J=o.arrows[I];if(!J.run)continue;if(J.obj!==undefined)if(J.obj.pos!==undefined)J.arrow.pos=J.obj.pos;else continue;if(J.last_pos!==null&&L.equals(J.last_pos))continue;J.arrow.visible||(J.arrow.visible=!0),J.arrow.axis_and_length=J.obj[J.attr].multiply(J.scale)}for(var I in o.trails){var L,J=o.trails[I];if(!J.run)continue;if(typeof J.obj!="function"){if(J.obj!==undefined)if(J.obj.pos!==undefined)L=J.obj.pos;else continue}else L=J.obj();if(J.last_pos!==null&&L.equals(J.last_pos))continue;if(J.pps>0){var N=(new Date).getTime();J.last_time===null&&(J.last_time=N);if(N-J.last_time>1e3/J.pps)J.last_time=N;else if(N!=J.last_time)continue}if(J.retain>0&&J.elements==J.retain)if(J.type=="curve")J.curve.shift(),J.curve.push(L);else{for(var I=0;I<J.retain-1;I++)J.spheres[I].pos=J.spheres[I+1].pos;J.spheres[J.retain-1].pos=L}else J.type=="curve"?J.curve.push(L):(J.options.pos=L,J.spheres.push(sphere(J.options))),J.elements+=1;J.last_pos=vec(L)}}S.target=vec3.create([o.__center.x,o.__center.y,o.__center.z]),S.up=vec3.create([o.__up.x,o.__up.y,o.__up.z]),S.fovy=o.__fov*180/Math.PI;var Q=vec(o.__forward.x,0,o.__forward.z).norm();S.angleX=Math.atan2(Q.x,-Q.z),S.angleY=Math.PI/2-Math.acos(-o.__forward.norm().y),p.clientWidth>=p.clientHeight?S.distance=o.__range/Math.tan(o.__fov/2):S.distance=o.__range*(p.clientHeight/p.clientWidth)/Math.tan(o.__fov/2),S.pos=mat4.multiplyVec3(mat4.rotateX(mat4.rotateY(mat4.identity(mat4.create()),-S.angleX),-S.angleY),vec3.create([0,0,S.distance])),S.pos=vec3.create([o.__center.x+S.pos[0],o.__center.y+S.pos[1],o.__center.z+S.pos[2]]),S.zNear=S.distance/100,S.zFar=S.distance*10;var R=mat4.perspective(S.fovy,p.clientWidth/p.clientHeight,S.zNear,S.zFar),T=mat4.lookAt(S.pos,S.target,S.up),U=8,V=new Float32Array(U*4),W=new Float32Array(U*3),X=Math.min(o.lights.length,U);for(var I=0;I<X;I++){var Y=o.lights[I];if(Y.direction===undefined)var Z=[Y.pos.x,Y.pos.y,Y.pos.z,1];else var Z=[Y.direction.x,Y.direction.y,Y.direction.z,0];Y.transformed=Z,mat4.multiplyVec4(T,Z);for(var $=0;$<4;$++)V[I*4+$]=Z[$];W[I*3]=Y.color.x,W[I*3+1]=Y.color.y,W[I*3+2]=Y.color.z}var _=new Float32Array(3);_[0]=o.ambient.x,_[1]=o.ambient.y,_[2]=o.ambient.z;if(q==a&&o.__overlay_objects.objects.length>0&&(o.__overlay_objects.__changed||!o.__forward.equals(o.__last_forward)||o.__range!=o.__last_range)){o.__overlay_objects.__changed=!1;var ba=o.overlay_context;ba.clearRect(0,0,o.__width,o.__height);for(var I=0;I<o.__overlay_objects.objects.length;I++){var D=o.__overlay_objects.objects[I];if(!D.visible)continue;D.__update(ba,S)}}for(var bb in o.__changed)o.__changed[bb].__update();o.__changed={};var bc={};for(var bd in O)bc[bd]={},bc[bd].id_object={};if(q==a)for(var bd in O){var be=O[bd],bf=be.id_object;for(var bb in bf){var D=bf[bb],bg=D.__data;bg[19]<1&&(bc[bd].id_object[bb]=D,q=d)}}var bh,bi=new Float32Array(2);bi[0]=E,bi[1]=F;if(q==a)bk(q,null,0,[]);else if(q==b)bk(q,"C0",0,[]);else if(q==c)bk(q,"EXTENT_TEXTURE",0,[]);else if(q==d){var bl=["C0","C1"];bk(e,"C0",0,[]),bk(f,"D0",-1,[]),bk(i,"C1",0,["D0"]),bk(g,"D1",0,["D0"]),bk(j,"C2",0,["D0","D1"]),bl.push("C2"),bk(h,"D2",1,["D0","D1"]),bk(k,"C3",0,["D0","D2"]),bl.push("C3"),bk(g,"D1",2,["D0","D2"]),bk(l,"D2",0,["D0","D1"]),bl.push("D2"),bk(m,null,0,bl)}if(q==c){var bm=new Uint8Array(4);s.readPixels(0,0,1,1,s.RGBA,s.UNSIGNED_BYTE,bm);var bn=(256*bm[1]+bm[2])/65536,bo=bm[0];bo>128&&(bo=-(bo-128),bn=-bn);var bp;return bn==0&&bo==0?bp=0:bp=Math.exp(bn+bo),o.title.text(bm[0]+" "+bm[1]+" "+bm[2]+" "+bm[3]+" : "+o.mouse.__pickx+" "+o.mouse.__picky),o.caption.text("extent="+bp.toExponential(3)),null}if(q==b){var bm=new Uint8Array(4);s.readPixels(o.mouse.__pickx,o.mouse.__picky,1,1,s.RGBA,s.UNSIGNED_BYTE,bm);var bb=16777216*bm[0]+65536*bm[1]+256*bm[2]+bm[3],D=o.__visiblePrimitives[bb];if(D===undefined){var D=P.curve.id_object[bb];if(D===undefined)return null}if(D.__curve!==undefined){if(!D.__curve.pickable)return null;var bq=D.__curve.points,br=bq.length;for(var I=0;I<br;I++)if(bq[I]===D)return D=D.__curve,D.pick=I,D;return null}return D.pickable?D:null}},this.reset(),Y()}"use strict";var a=0,b=1,c=2,d=3,e=4,f=5,g=6,h=7,i=8,j=9,k=10,l=11,m=12,n=13,p={WebGLRenderer:o};Export(p)}(),function(){function a(a){return Math.log(a)/Math.LN10}function e(e,f){if(f.ticks.length==0){var g=f.tickSize,h=f.min,i=f.max,j=Math.floor((i-h)/g+.5)+1,k,l;for(var m=0;m<j;m++){l=abs(h+m*g);if(k===undefined||l>k&&l!=0)k=l}d=Math.floor(a(k))+1;var n=Math.floor(a(g))+1;n>3?(b=!0,c=n):n>0?(b=!1,c=0):n<0?(b=!0,c=n,d>=0&&(b=!1,c=-n+1)):(b=!1,c=1)}if(e==0)return"0";if(b){var o,p,q=e*pow(10,-c+1);return o=0,p=c-1,d>c&&(q*=.1,o+=1,p+=1),q.toFixed(o)+"e"+p}return e.toFixed(c)}function f(b){if(!(this instanceof f))return new f(b);b===undefined&&(b={}),this.graph_options={series:{shadowSize:0},crosshair:{mode:"xy",color:"rgba(0,0,0,1)"}},this.__width=640,this.__height=200,this.__xmin=this.__xmax=this.__ymin=this.__ymax=null,b.width!==undefined&&(this.__width=b.width,delete b.width),b.height!==undefined&&(this.__height=b.height,delete b.height),this.graph_options.xaxis={min:null,max:null,tickFormatter:e},this.graph_options.yaxis={min:null,max:null,tickFormatter:e},b.xmin!==undefined&&(this.__xmin=this.graph_options.xaxis.min=b.xmin,delete b.xmin),b.xmax!==undefined&&(this.__xmax=this.graph_options.xaxis.max=b.xmax,delete b.xmax),b.ymin!==undefined&&(this.__ymin=this.graph_options.yaxis.min=b.ymin,delete b.ymin),b.ymax!==undefined&&(this.__ymax=this.graph_options.yaxis.max=b.ymax,delete b.ymax),this.__logx=this.__logy=!1,b.logx!==undefined&&(this.__logx=graph_options.logx,delete b.logx),b.logy!==undefined&&(this.__logy=graph_options.logy,delete b.logy),this.__logx&&(this.graph_options.xaxis.transform=function(b){return a(b)},this.graph_options.xaxis.inverseTransform=function(a){return pow(10,a)}),this.__logy&&(this.graph_options.yaxis.transform=function(b){return a(b)},this.graph_options.yaxis.inverseTransform=function(a){return pow(10,a)});var c="",d=0;for(var g in b)d+=1,c+=g+", ";if(c.length>0)throw d==1?new Error(c.slice(0,c.length-2)+" is not an attribute of a graph"):new Error("These are not attributes of a graph: "+c.slice(0,c.length-2));f.selected=this,this.wrapper=$("<div/>"),this.wrapper.addClass("glowscript-graph").css("width",this.__width).css("height",this.__height).appendTo(canvas.container),this.graph_series=[],this.__update()}function h(a){a===undefined?a={data:[]}:a.data===undefined&&(a.data=[]),a.graph!==undefined?(this.__graph=a.graph,delete a.graph):(this.__graph=f.selected,this.__graph||(this.__graph=f())),this.__type="line",a.type!==undefined&&(this.__type=a.type,delete a.type);var b=g[this.__type];if(!b)throw new Error("Unknown series type: "+this.__type);this.options={},this.options.data=a.data,delete a.data,this.options[b]={show:!0,align:"center",horizontal:!1,barWidth:1},a.horizontal!==undefined&&(this.__horizontal=this.options[b].horizontal=a.horizontal,delete a.horizontal),a.delta!==undefined&&(this.__delta=this.options[b].barWidth=a.delta,delete a.delta),a.width!==undefined&&(this.__width=this.options[b].lineWidth=a.width,delete a.width),a.radius!==undefined&&(this.__radius=this.options[b].radius=a.radius,delete a.radius),a.dot!==undefined&&(this.__dot=a.dot,delete a.dot),a.dot_color!==undefined&&(this.__dot_color=a.dot_color,delete a.dot_color),a.dot_radius!==undefined&&(this.__dot_radius=a.dot_radius,delete a.dot_radius),a.color!==undefined&&(this.__color=a.color,this.options.color=color.to_html(a.color),delete a.color),a.label!==undefined&&(this.__label=this.options.label=a.label,delete a.label),this.options.data.length>0&&(this.__graph.changed=!0),this.__visible=!0,a.visible!==undefined&&(this.__visible=a.visible,delete a.visible);var c="",d=0;for(var e in a)d+=1,c+=e+", ";if(c.length>0)throw d==1?new Error(c.slice(0,c.length-2)+" is not an attribute of a series"):new Error("These are not attributes of a series: "+c.slice(0,c.length-2));this.__graph.add_to_graph(this),this.plot=function(a){this.__graph.changed=!0;if(typeof arguments[0]=="number")this.options.data.push([arguments[0],arguments[1]]);else if(typeof arguments[0][0]=="number"){var b;for(var c=0;c<arguments.length;c++)b=arguments[c],this.options.data.push(b)}else{if(arguments.length!=1)throw new Error("must be plot(x,y) or plot([x,y]) or plot([x,y], ...) or plot([ [x,y], ... ])");var b;for(var c=0;c<a.length;c++)b=a[c],this.options.data.push(b)}}}function i(a){return new h(a)}"use strict";var b=!1,c=0,d=0;property.declare(f,{selected:{get:function(){return window.__context.graph_selected||null},set:function(a){window.__context.graph_selected=a}}}),property.declare(f.prototype,{__update:function(){var a=this;window.requestAnimFrame(function(){a.__update.call(a)},this.wrapper.get(0));if(!this.changed)return;var b=[];for(var c=0;c<this.graph_series.length;c++){var d=this.graph_series[c];if(d.__visible){b.push(d.options);if(d.__dot&&d.__type=="line"&&d.options.data.length>0){var e={points:{show:!0}};d.__dot_radius!==null?e.points.radius=d.__dot_radius:e.points.radius=d.__width+1,d.__dot_color!==null?e.color=color.to_html(d.__dot_color):e.color=color.to_html(d.__color),e.data=[d.options.data[d.options.data.length-1]],b.push(e)}}}this.changed=!1;if(b.length==0)return;var f=$.plot(this.wrapper,b,this.graph_options);f.draw()},add_to_graph:function(a){this.graph_series.push(a)},changed:!1}),Object.defineProperty(f.prototype,"__width",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"width",{enumerable:!0,get:function(){return this.__width},set:function(a){this.__width=a,this.wrapper.css("width",a);var b=$.plot(this.wrapper,[],this.options);b.resize(),b.setupGrid(),this.changed=!0}}),Object.defineProperty(f.prototype,"__height",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"height",{enumerable:!0,get:function(){return this.__height},set:function(a){this.__height=a,this.wrapper.css("height",a);var b=$.plot(this.wrapper,[],this.options);b.resize(),b.setupGrid(),this.changed=!0}}),Object.defineProperty(f.prototype,"__xmin",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"xmin",{enumerable:!0,get:function(){return this.__xmin},set:function(a){this.__xmin=this.options.xaxis.min=a,this.changed=!0}}),Object.defineProperty(f.prototype,"__xmax",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"xmax",{enumerable:!0,get:function(){return this.__xmax},set:function(a){this.__xmax=this.options.xaxis.max=a,this.changed=!0}}),Object.defineProperty(f.prototype,"__ymin",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"ymin",{enumerable:!0,get:function(){return this.__ymin},set:function(a){this.__ymin=this.options.yaxis.min=a,this.changed=!0}}),Object.defineProperty(f.prototype,"__ymax",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"ymax",{enumerable:!0,get:function(){return this.__ymax},set:function(a){this.__ymax=this.options.yaxis.max=a,this.changed=!0}}),Object.defineProperty(f.prototype,"__logx",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"logx",{enumerable:!0,get:function(){return this.__logx},set:function(b){if(this.__logx==b)return;b?(this.options.xaxis.transform=function(b){return a(b)},this.options.xaxis.inverseTransform=function(a){return pow(10,a)}):(delete this.options.xaxis.transform,delete this.options.xaxis.inverseTransform),this.__logx=b,this.changed=!0}}),Object.defineProperty(f.prototype,"__logy",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(f.prototype,"logy",{enumerable:!0,get:function(){return this.__logy},set:function(b){if(this.__logy==b)return;b?(this.options.yaxis.transform=function(b){return a(b)},this.options.yaxis.inverseTransform=function(a){return pow(10,a)}):(delete this.options.yaxis.transform,delete this.options.yaxis.inverseTransform),this.__logy=b,this.changed=!0}});var g={line:"lines",scatter:"points",bar:"bars",__proto__:null};Object.defineProperty(h.prototype,"__graph",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(h.prototype,"graph",{enumerable:!0,get:function(){return this.__graph},set:function(a){this.__graph.changed=!0,this.__graph.graph_series.splice(this.__graph.graph_series.indexOf(this),1),this.__graph=a,this.__graph.add_to_graph(this),this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__type",{enumerable:!1,writable:!0,value:"line"}),Object.defineProperty(h.prototype,"type",{enumerable:!0,get:function(){return this.__type},set:function(a){var b=this.__type;if(a==b)return;var c=g[b],d=g[a];if(!d)throw new Error("Unknown series type: "+a);this.options[d]=this.options[c],delete this.options[c],this.__type=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__color",{enumerable:!1,writable:!0,value:vec(0,0,0)}),Object.defineProperty(h.prototype,"color",{enumerable:!0,get:function(){return this.__color},set:function(a){if(this.__color.equals(a))return;this.__color=a,this.options.color=color.to_html(a),this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__label",{enumerable:!1,writable:!0,value:null}),Object.defineProperty(h.prototype,"label",{enumerable:!0,get:function(){return this.options.label===undefined?"":this.options.label},set:function(a){if(this.options.label==a)return;this.options.label=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__delta",{enumerable:!1,writable:!0,value:1}),Object.defineProperty(h.prototype,"delta",{enumerable:!0,get:function(){return this.__delta},set:function(a){if(this.__delta==a)return;this.__delta=a;var b=g[this.__type];this.options[b].barWidth=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__width",{enumerable:!1,writable:!0,value:1}),Object.defineProperty(h.prototype,"width",{enumerable:!0,get:function(){return this.__width},set:function(a){if(this.__width==a)return;this.__width=a;var b=g[this.__type];this.options[b].lineWidth=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__radius",{enumerable:!1,writable:!0,value:3}),Object.defineProperty(h.prototype,"radius",{enumerable:!0,get:function(){return this.__radius},set:function(a){if(this.__radius==a)return;this.__radius=a;var b=g[this.__type];this.options[b].radius=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__horizontal",{enumerable:!1,writable:!0,value:!1}),Object.defineProperty(h.prototype,"horizontal",{enumerable:!0,get:function(){return this.__delta},set:function(a){if(this.__horizontal==a)return;this.__horizontal=a;var b=g[this.__type];this.options[b].horizontal=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__dot",{enumerable:!1,writable:!0,value:!1}),Object.defineProperty(h.prototype,"dot",{enumerable:!0,get:function(){return this.__dot},set:function(a){if(this.__dot==a)return;this.__dot=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__dot_color",{enumerable:!1,writable:!0,value:null}),Object.defineProperty(h.prototype,"dot_color",{enumerable:!0,get:function(){return this.__dot_color},set:function(a){if(this.__dot_color.equals(a))return;this.__dot_color=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__dot_radius",{enumerable:!1,writable:!0,value:null}),Object.defineProperty(h.prototype,"dot_radius",{enumerable:!0,get:function(){return this.__dot_radius},set:function(a){if(this.__dot_radius==a)return;this.__dot_radius=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__visible",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(h.prototype,"visible",{enumerable:!0,get:function(){return this.__visible},set:function(a){if(this.__visible==a)return;this.__visible=a,this.__graph.changed=!0}}),Object.defineProperty(h.prototype,"__data",{enumerable:!1,writable:!0,value:0}),Object.defineProperty(h.prototype,"data",{enumerable:!0,get:function(){return this.options.data},set:function(a){this.options.data=[],this.plot(a)}});var j={graph:f,series:i};Export(j)}(),function(){"use strict";var a={red:vec(1,0,0),green:vec(0,1,0),blue:vec(0,0,1),yellow:vec(1,1,0),orange:vec(1,.6,0),cyan:vec(0,1,1),magenta:vec(1,0,1),white:vec(1,1,1),black:vec(0,0,0),gray:function(a){return vec(a,a,a)},hsv_to_rgb:function(a){var b=a.x,c=a.y,d=a.z;if(c==0)return vec(d,d,d);var e=Math.floor(6*b),f=6*b-e,g=d*(1-c),h=d*(1-c*f),i=d*(1-c*(1-f)),e=e%6;switch(e){case 0:return vec(d,i,g);case 1:return vec(h,d,g);case 2:return vec(g,d,i);case 3:return vec(g,h,d);case 4
:return vec(i,g,d);case 5:return vec(d,g,h)}},rgb_to_hsv:function(a){var b=a.x,c=a.y,d=a.z,e=Math.max(b,c,d),f=Math.min(b,c,d),g=e;if(f==e)return vec(0,0,g);var h=(e-f)/e,i=(e-b)/(e-f),j=(e-c)/(e-f),k=(e-d)/(e-f),l;return b==e?l=k-j:c==e?l=2+i-k:l=4+j-i,l=l/6,l<0&&l++,vec(l,h,g)},to_html:function(a){var b=Math.floor(255*a.x),c=Math.floor(255*a.y),d=Math.floor(255*a.z);return"rgb("+b+","+c+","+d+")"},to_html_rgba:function(a,b){var c=Math.floor(255*a.x),d=Math.floor(255*a.y),e=Math.floor(255*a.z);return"rgba("+c+","+d+","+e+","+b+")"}},b={color:a};Export(b)}(),function(){function subclass(a,b){a.prototype=new b({visible:!1,canvas:null}),a.prototype.constructor=a}function id_to_falsecolor(a){var b=0,c=0,d=0;return a>=16777216&&(b=Math.floor(a/16777216),a-=b*16777216),a>=65536&&(c=Math.floor(a/65536),a-=c*65536),a>=256&&(d=Math.floor(a/256),a-=d*256),[b/255,c/255,d/255,a/255]}function init(a,b){b.canvas!==undefined?(a.canvas=b.canvas,delete b.canvas):a.canvas=canvas.selected,a.canvas&&(a.canvas.__activate(),a.__model=a.canvas.__renderer.models[a.constructor.name]);for(var c in b)a[c]=b[c];b.visible===undefined&&a.canvas!==null&&(a.visible=!0)}function initObject(a,b,c){if(a instanceof b)c===undefined&&(c={}),a.__tex={file:null,bumpmap:null,texture_ref:{reference:null},bumpmap_ref:{reference:null},left:!1,right:!1,sides:!1,flipx:!1,flipy:!1,turn:0,flags:0},c.pos===undefined&&(a.pos=a.pos),c.color===undefined&&(a.color=a.color),c.axis===undefined&&(a.axis=a.axis),c.up===undefined&&(a.up=a.up),c.size===undefined&&(a.size=a.size),init(a,c);else return new b(c)}function setup_texture(a,b,c){a.slice(0,1)==":"&&(a="images/"+a.slice(1)),b.canvas.__renderer.initTexture(a,b,c)}function Primitive(){}function box(a){return initObject(this,box,a)}function cylinder(a){return initObject(this,cylinder,a)}function cone(a){return initObject(this,cone,a)}function pyramid(a){return initObject(this,pyramid,a)}function sphere(a){return initObject(this,sphere,a)}function arrow(a){return initObject(this,arrow,a)}function curve(a){if(!(this instanceof curve))return new curve(a);a=a||{};if(a.texture!==undefined)throw new Error("Textures are not available for curve objects.");this.points=[],this.color=this.color,init(this,a),this.radius||(this.radius=.001*this.canvas.__range)}function point(a){if(!(this instanceof point))return new point(a);a instanceof vec&&(a={pos:a});for(var b in a)this[b]=a[b];if(this.pos===undefined)throw new Error("Must specify pos for a point on a curve")}function helix(a){return initObject(this,helix,a)}function ring(a){return initObject(this,ring,a)}function distant_light(a){if(!(this instanceof distant_light))return new distant_light(a);if(a.direction===undefined)throw new Error("Must specify the distant_light direction as {direction:..}");init(this,a),this.canvas.lights.push(this)}function local_light(a){if(!(this instanceof local_light))return new local_light(a);if(a.pos===undefined)throw new Error("Must specify the local_light position as {pos:..}");init(this,a),this.canvas.lights.push(this)}function draw(a){if(this instanceof draw)a=a||{},this.points=[],init(this,a),this.canvas.__overlay_objects.objects.push(this);else return new draw(a)}function label(a){if(this instanceof label)a=a||{},this.pos=this.pos,this.color=this.color,init(this,a),this.canvas.__overlay_objects.objects.push(this);else return new label(a)}function compound(a,b){if(!(this instanceof compound))return new compound(a,b);var c=b.visible===undefined?!0:b.visible;b.visible=!1,init(this,compound,b);var d=this.__model,e=new d.Mesh;for(var f=0;f<a.length;f++){var g=a[f];g.visible=!1,e.merge(g.getTransformedMesh())}this.__model=d(e),this.visible=c;var h=function(a){return this instanceof h?(this.__id=null,initObject(this,h,a)):new h(a)};h.prototype=this,h.prototype.constructor=h,this.clone=h}function attach_trail(a,b){if(!(this instanceof attach_trail))return new attach_trail(a,b);b===undefined&&(b={}),b.canvas===undefined&&(b.canvas=canvas.selected,typeof a!="function"&&(b.canvas=a.canvas));if(b.type===undefined)this.type="curve";else switch(b.type){case"curve":this.type=b.type,delete b.type;break;case"spheres":this.type=b.type,delete b.type,b.pickable=!1;break;default:throw new Error("attach_trail type must be 'curve' or 'spheres'")}this.retain=-1,b.retain!==undefined&&(this.retain=b.retain,delete b.retain),this.pps=0,b.pps!==undefined&&(this.pps=b.pps,delete b.pps);var c;this.obj=a,typeof a!="function"?(b.color===undefined&&(b.color=a.color),b.radius===undefined?c=.05*a.size.y:(c=b.radius,delete b.radius)):b.radius===undefined?c=.001*b.canvas.range:(c=b.radius,delete b.radius),this.type=="curve"?b.radius=c:b.size=vec(2*c,2*c,2*c),b.pickable=!1,this.options=b;var d=b.canvas;this.type=="curve"?this.curve=curve(this.options):this.spheres=[],this.last_pos=null,this.last_time=null,this.run=!0,this.elements=0,d.trails.push(this),this.start=function(){this.run=!0,this.type==="curve"&&(this.curve=curve(this.options))},this.stop=function(){this.run=!1},this.clear=function(){if(this.type=="curve")this.curve.clear();else{var a=this.spheres;for(var b=0;b<a.length;b++)a[b].visible=!1;this.spheres=[]}}}function attach_arrow(a,b,c){if(!(this instanceof attach_arrow))return new attach_arrow(a,b,c);c===undefined&&(c={}),c.canvas===undefined&&(c.canvas=a.canvas),this.obj=a,this.attr=b,this.scale=1,c.scale!==undefined&&(this.scale=c.scale,delete c.scale),c.color===undefined&&(c.color=a.color),this.options=c;var d=c.canvas;this.arrow=arrow(this.options),this.arrow.visible=!1,this.arrow.pickable=!1,this.last_pos=null,this.run=!0,d.arrows.push(this),this.start=function(){this.arrow.visible=this.run=!0},this.stop=function(){this.arrow.visible=this.run=!1}}"use strict";var nextVisibleId=1,textures={flower:":flower_texture.jpg",granite:":granite_texture.jpg",gravel:":gravel_texture.jpg",metal:":metal_texture.jpg",rock:":rock_texture.jpg",rough:":rough_texture.jpg",rug:":rug_texture.jpg",stones:":stones_texture.jpg",stucco:":stucco_texture.jpg",wood:":wood_texture.jpg",wood_old:":wood_old_texture.jpg"},bumpmaps={gravel:":gravel_bumpmap.jpg",rock:":rock_bumpmap.jpg",stones:":stones_bumpmap.jpg",stucco:":stucco_bumpmap.jpg",wood_old:":wood_old_bumpmap.jpg"};property.declare(Primitive.prototype,{__id:null,__hasPosAtCenter:!1,__zx_camera:null,__zy_camera:null,__xmin:null,__ymin:null,__zmin:null,__xmax:null,__ymax:null,__zmax:null,pos:new attributeVector(null,0,0,0),color:new attributeVector(null,1,1,1),axis:new attributeVector(null,1,0,0),size:new attributeVector(null,1,1,1),up:new attributeVector(null,0,1,0),opacity:{value:1,onchanged:function(){this.__change()}},shininess:{value:.6,onchanged:function(){this.__change()}},emissive:{value:!1,onchanged:function(){this.__change()}},pickable:{value:!0,onchanged:function(){this.__change()}},ready:{get:function(){return this.__tex.file===null||this.__tex.texture_ref.reference!==null&&this.__tex.bumpmap===null||this.__tex.bumpmap_ref.reference!==null}},texture:{get:function(){return{file:this.__tex.file,bumpmap:this.__tex.bumpmap,left:this.__tex.left,right:this.__tex.right,sides:this.__tex.sides,flipx:this.__tex.flipx,flipy:this.__tex.flipy,turn:this.__tex.turn}},set:function(a){this.__tex={file:null,bumpmap:null,texture_ref:{reference:null},bumpmap_ref:{reference:null},left:!1,right:!1,sides:!1,flipx:!1,flipy:!1,turn:0,flags:0};if(a!==null)if(typeof a=="string")this.__tex.left=this.__tex.right=this.__tex.sides=!0,setup_texture(a,this,!1);else{if(a.file!==undefined&&typeof a.file=="string")setup_texture(a.file,this,!1);else throw new Error("You must specify a file name for a texture.");if(a.bumpmap!==undefined&&a.bumpmap!==null){if(typeof a.bumpmap!="string")throw new Error("You must specify a file name for a bumpmap.");setup_texture(a.bumpmap,this,!0)}a.flipx!==undefined&&(this.__tex.flipx=a.flipx),a.flipy!==undefined&&(this.__tex.flipy=a.flipy),a.turn!==undefined&&(this.__tex.turn=Math.round(a.turn));if(a.place!==undefined){typeof a.place=="string"&&(a.place=[a.place]);for(var b=0;b<a.place.length;b++)switch(a.place[b]){case"left":this.__tex.left=!0;break;case"right":this.__tex.right=!0;break;case"sides":this.__tex.sides=!0;break;case"ends":this.__tex.left=this.__tex.right=!0;break;case"all":this.__tex.left=this.__tex.right=this.__tex.sides=!0}}else this.__tex.left=this.__tex.right=this.__tex.sides=!0}this.__tex.flags=0,this.__tex.file!==null&&(this.__tex.flags+=1),this.__tex.bumpmap!==null&&(this.__tex.flags+=2),this.__tex.left&&(this.__tex.flags+=4),this.__tex.right&&(this.__tex.flags+=8),this.__tex.sides&&(this.__tex.flags+=16),this.__tex.flipx&&(this.__tex.flags+=32),this.__tex.flipy&&(this.__tex.flags+=64);var c=this.__tex.turn%4;c<0&&(c+=4),this.__tex.flags+=128*c,this.__change()}},visible:{get:function(){return this.__id!=null},set:function(a){if(a==(this.__id!=null))return;if(a)this.__id=nextVisibleId,nextVisibleId++,this.canvas.__visiblePrimitives[this.__id]=this,this.__falsecolor=id_to_falsecolor(this.__id),this.canvas.__changed[this.__id]=this;else{delete this.canvas.__visiblePrimitives[this.__id],delete this.canvas.__changed[this.__id],this.__model&&delete this.__model.id_object[this.__id];if(this.__components)for(var b=0;b<this.__components.length;b++)delete this.__components[b].__model.id_object[this.__components[b].__id];this.__id=null}}},__change:function(){this.__id&&(this.canvas.__changed[this.__id]=this)},__get_extent:function(a){Autoscale.find_extent(this,a)},__update:function(){var a=this.__pos,b=this.__size,c=this.__color,d=this.__axis,e=this.__up,f=this.__data;f||(this.__data=f=new Float32Array(20)),this.__model.id_object[this.__id]=this,f[0]=a.__x,f[1]=a.__y,f[2]=a.__z,f[3]=this.__shininess,f[4]=d.__x,f[5]=d.__y,f[6]=d.__z,f[7]=this.__emissive?1:0,f[8]=e.__x,f[9]=e.__y,f[10]=e.__z,f[11]=this.__tex.flags,f[12]=b.__x,f[13]=b.__y,f[14]=b.__z,f[16]=c.__x,f[17]=c.__y,f[18]=c.__z,f[19]=this.__opacity},rotate:function(a){if(a.angle===undefined)throw new Error("object.rotate() requires {angle:...}");var b=a.angle,c,d;a.axis===undefined?c=this.__axis:c=a.axis,a.origin===undefined?d=this.__pos:d=a.origin;var e=c.norm(),f=this.__up.norm(),g=e.cross(f).norm();g.dot(g)<1e-10&&(g=e.cross(vec(1,0,0)),g.dot(g)<1e-10&&(g=cross(e,vec(0,1,0))),f=g.cross(e)),this.pos=d.add(this.__pos.sub(d).rotate({angle:b,axis:c})),this.axis=this.__axis.rotate({angle:b,axis:c}),this.up=f.rotate({angle:b,axis:e})},getTransformedMesh:function(){var a=this.axis.norm(),b=a.cross(this.up.norm());b.mag2()<1e-10&&(b=a.cross(vec(1,0,0)),b.mag2()<1e-10&&(b=a.cross(vec(0,1,0)))),b=b.norm();var c=b.cross(a).norm();a=a.multiply(this.size.x),c=c.multiply(this.size.y),b=b.multiply(this.size.z);var d=this.pos,e=[a.x,a.y,a.z,0,c.x,c.y,c.z,0,b.x,b.y,b.z,0,d.x,d.y,d.z,1];return this.__model.mesh.transformed(e)}}),subclass(box,Primitive),box.prototype.__hasPosAtCenter=!0,subclass(cylinder,Primitive),subclass(cone,cylinder),subclass(pyramid,box),subclass(sphere,Primitive),sphere.prototype.__hasPosAtCenter=!0,subclass(arrow,Primitive),property.declare(arrow.prototype,{__primitiveCount:2,shaftwidth:0,headwidth:0,headlength:0,axis_and_length:{get:function(){return this.__axis.norm().multiply(this.__size.x)},set:function(a){this.axis=a,this.__size.x=a.mag()}},__update:function(){var a=this.__pos,b=this.__color,c=this.__axis,d=this.__size,e=this.__up,f=d.__x,g=c.norm(),h=this.__shaftwidth||f*.1,i=this.__headwidth||h*2,j=this.__headlength||h*3;if(h<f*.02){var k=f*.02/h;this.__shaftwidth||(h*=k),this.__headwidth||(i*=k),this.__headlength||(j*=k)}if(j>f*.5){var k=f*.5/j;this.__shaftwidth||(h*=k),this.__headwidth||(i*=k),this.__headlength||(j*=k)}var l=this.__components;if(!l){l=this.__components=[box({canvas:this.canvas,visible:0}),pyramid({canvas:this.canvas,visible:0})];for(var m=0;m<l.length;m++)l[m].__id=nextVisibleId++,l[m].__falsecolor=this.__falsecolor}var n=l[0],o=l[1];n.pos=a.add(g.multiply(.5*(f-j))),o.pos=a.add(g.multiply(f-j)),n.axis=o.axis=c,n.up=o.up=e,n.size=vec(f-j,h,h),o.size=vec(j,i,i),n.color=o.color=this.color,n.opacity=o.opacity=this.opacity,this.size=vec(f,i,i),n.__update(),o.__update()}}),property.declare(curve.prototype,{__id:null,radius:0,color:new attributeVector(null,1,1,1),__zx_camera:null,__zy_camera:null,__xmin:null,__ymin:null,__zmin:null,__xmax:null,__ymax:null,__zmax:null,pickable:!0,pick:null,visible:{get:function(){return this.__id!=null},set:function(a){if(a==(this.__id!=null))return;if(a)this.__id=nextVisibleId,nextVisibleId++,this.canvas.__visiblePrimitives[this.__id]=this,this.canvas.__changed[this.__id]=this;else{delete this.canvas.__visiblePrimitives[this.__id],delete this.canvas.__changed[this.__id],this.__model&&delete this.__model.id_object[this.__id];if(this.__components)for(var b=0;b<this.__components.length;b++)delete this.__components[b].__model.id_object[this.__components[b].__id];this.__id=null}}},__change:function(){this.__id&&(this.canvas.__changed[this.__id]=this)},__get_extent:function(a){for(var b=0;b<this.points.length;b++)a.point_extent(this,this.points[b].pos)},__update:function(){for(var a=0;a<this.points.length;a++)this.points[a].__update()},moveto:function(a){var b=a.sub(this.points[0].pos),c=this.points;for(var d=0;d<c.length;d++)c[d].pos=c[d].pos.add(b)},rotate:function(a,b,c){if(a===undefined)throw new Error("curve.rotate() requires an angle");if(b===undefined)throw new Error("curve.rotate() requires an axis to rotate about");c===undefined&&(c=this.points[0].pos);var d=b.norm(),e=vec(0,1,0),f=d.cross(e).norm();f.dot(f)<1e-10&&(f=d.cross(vec(1,0,0)),f.dot(f)<1e-10&&(f=cross(d,vec(0,1,0))),e=f.cross(d));var g=this.points;for(var h=0;h<g.length;h++)g[h].pos=c.add(g[h].pos.sub(c).rotate(a,b))},push:function(a){var b=[],c;if(a.length!==undefined)b=a;else for(var d=0;d<arguments.length;d++)b.push(arguments[d]);for(var d=0;d<b.length;d++){c=point(b[d]),c.__curve=this,c.__id=nextVisibleId++,c.__falsecolor=id_to_falsecolor(c.__id);if(this.points.length){var e=this.points[this.points.length-1],f=c.__prevsegment=e.__nextsegment=new Float32Array(16);f[11]=f[15]=1,this.__model.id_object[c.__id]=c,e.__change()}this.points.push(c),c.__change()}this.__change()},pop:function(){var a=this.points.pop();return a.visible=!1,this.__change(),{pos:a.pos,color:a.color,radius:a.radius,visible:a.visible}},clear:function(){this.splice(0,this.points.length),this.__change()},shift:function(){var a=this.points.shift();return a.visible=!1,this.__change(),{pos:a.pos,color:a.color,radius:a.radius,visible:a.visible}},unshift:function(a){var b=[];if(a.length!==undefined)b=a;else for(var c=0;c<arguments.length;c++)b.push(arguments[c]);this.splice(0,0,b),this.__change()},splice:function(a){var b=arguments[0],c=arguments[1],d=[];for(var e=2;e<arguments.length;e++)d.push(arguments[e]);d.length==1&&d[0].length!==undefined&&(d=d[0]);var f=this.points.slice(b+c),g=[];for(var e=0;e<f.length;e++)g.push({pos:f[e].pos,color:f[e].color,radius:f[e].radius,visible:f[e].visible});for(var e=b;e<this.points.length;e++)this.points[e].visible=!1;this.points.splice(b),this.push(d),this.push(g),this.__change()},modify:function(a,b){b instanceof vec&&(b={pos:b});for(var c in b)c=="x"&&(this.points[a].pos.x=b[c]),c=="y"&&(this.points[a].pos.y=b[c]),c=="z"?this.points[a].pos.z=b[c]:this.points[a][c]=b[c];this.points[a].__change(),this.__change()},slice:function(a,b){var c=this.points.slice(a,b),d=[];for(var e=0;e<c.length;e++)d.push({pos:c[e].pos,color:c[e].color,radius:c[e].radius,visible:c[e].visible});return d}}),property.declare(point.prototype,{__curve:null,pos:new attributeVector(null,0,0,0),color:null,radius:null,visible:!0,pickable:!0,__change:function(){this.__id&&(this.__curve.canvas.__changed[this.__id]=this,this.__curve.canvas.__changed[this.__curve.__id]=this.__curve)},__update:function(){var a=this.__pos,b=this.radius||this.__curve.__radius,c=this.color||this.__curve.__color,d=this.__prevsegment;d&&(d[4]=a.x,d[5]=a.y,d[6]=a.z,d[7]=b,d[12]=c.x,d[13]=c.y,d[14]=c.z),d=this.__nextsegment,d&&(d[0]=a.x,d[1]=a.y,d[2]=a.z,d[3]=b,d[8]=c.x,d[9]=c.y,d[10]=c.z)}}),subclass(helix,Primitive),property.declare(helix.prototype,{__initialize:!0,thickness:{value:0,onchanged:function(){this.__change()}},coils:{value:5,onchanged:function(){this.__initialize=!0,this.__change()}},__update:function(){var a=20;this.__initialize&&(this.__helix!==undefined?this.__helix.clear():(this.__helix=curve(),this.__helix.__id=nextVisibleId++));var b=this.__helix;b.color=this.__color,b.radius=this.__thickness?this.__thickness/2:this.__size.y/40;var c=this.__axis.norm(),d,e;e=c.cross(this.__up),Math.abs(e.dot(e))<1e-10&&(e=c.cross(vec(1,0,0)),Math.abs(e.dot(e))<1e-10&&(e=c.cross(vec(0,1,0)))),e=e.norm(),d=e.cross(c);var f=this.__size.y/2,g=this.__coils*a,h=this.__axis.norm().multiply(this.__size.x/g),i=Math.sin(2*Math.PI/a),j=Math.cos(2*Math.PI/a),k=f*i,l=-f*(1-j),m,n=[];for(var o=0;o<a;o++)n.push(h.add(d.multiply(k)).add(e.multiply(l))),m=l*j-k*i,k=k*j+l*i,l=m;var p=this.__pos.add(e.multiply(f));for(var o=0;o<=g;o++)this.__initialize?b.push(p):b.modify(o,{pos:p}),p=p.add(n[o%a]);b.__update(),this.__initialize=!1}}),subclass(ring,Primitive),property.declare(ring.prototype,{__initialize:!0,__hasPosAtCenter:!0,__size:new attributeVector(null,.1,1,1),__update:function(){if(this.__initialize)if(this.__ring!==undefined){for(var a=0;a<this.__ring.points.length;a++)this.__ring.points[a].pos=this.__pos;this.__ring.__update(),this.__ring.points=[]}else this.__ring=curve(),this.__ring.__id=nextVisibleId++;var b=this.__ring;b.color=this.__color,b.radius=this.__size.x/2;var c=this.__axis.norm(),d,e;e=c.cross(this.__up),Math.abs(e.dot(e))<1e-10&&(e=c.cross(vec(1,0,0)),Math.abs(e.dot(e))<1e-10&&(e=c.cross(vec(0,1,0)))),e=e.norm(),d=e.cross(c);var f=100,g=(this.__size.y-this.__size.x)/2,h=g,i=0,j,k=Math.sin(2*Math.PI/f),l=Math.cos(2*Math.PI/f),m=this.__pos;for(var a=0;a<=f;a++){var n=m.add(d.multiply(i)).add(e.multiply(h));this.__initialize?b.push(point(n)):b.points[a].pos=n,j=i*l+h*k,h=h*l-i*k,i=j}b.__update(),this.__initialize=!1}}),property.declare(distant_light.prototype,{direction:new attributeVector(null,0,0,1),color:new attributeVector(null,1,1,1),__change:function(){}}),property.declare(local_light.prototype,{pos:new attributeVector(null,0,0,0),color:new attributeVector(null,1,1,1),__change:function(){}}),property.declare(draw.prototype,{color:{value:null,type:property.nullable_attributeVector},fillcolor:{value:null,type:property.nullable_attributeVector},linewidth:{value:1,onchanged:function(){this.__change()}},opacity:{value:.66,onchanged:function(){this.__change()}},visible:{value:!1,onchanged:function(){this.__change()}},__update:function(a,b){var c=this.points.length;if(c<2)return;if(this.fillcolor!=null){a.lineWidth=1,a.fillStyle=color.to_html_rgba(this.fillcolor,this.opacity),a.beginPath();for(var d=0;d<c;d++)d==0?a.moveTo(this.points[d].x,this.points[d].y):a.lineTo(this.points[d].x,this.points[d].y);a.fill()}if(this.color!=null){a.lineWidth=this.linewidth,a.strokeStyle=color.to_html_rgba(this.color,this.opacity),a.beginPath();for(var d=0;d<c;d++)d==0?a.moveTo(this.points[d].x,this.points[d].y):d==c-1&&this.points[d].equals(this.points[0])?a.closePath():a.lineTo(this.points[d].x,this.points[d].y);a.stroke()}},__change:function(){this.canvas.__overlay_objects.__changed=!0}}),property.declare(label.prototype,{pos:new attributeVector(null,0,0,0),color:{value:null,type:property.nullable_attributeVector},line:{value:!0,onchanged:function(){this.__change()}},linecolor:{value:null,type:property.nullable_attributeVector},background:{value:null,type:property.nullable_attributeVector},opacity:{value:.66,onchanged:function(){this.__change()}},text:{value:"",onchanged:function(){this.__change()}},font:{value:"Verdana",onchanged:function(){this.__change()}},height:{value:13,onchanged:function(){this.__change()}},visible:{value:!1,onchanged:function(){this.__change()}},align:{value:"center",onchanged:function(){this.__change()}},box:{value:!0,onchanged:function(){this.__change()}},border:{value:5,onchanged:function(){this.__change()}},linewidth:{value:1,onchanged:function(){this.__change()}},xoffset:{value:0,onchanged:function(){this.__change()}},yoffset:{value:0,onchanged:function(){this.__change()}},space:{value:0,onchanged:function(){this.__change()}},pixel_pos:{value:!1,onchanged:function(){this.__change()}},__update:function(a,b){var c=this.__xoffset,d=this.__yoffset,e,f;if(this.__pixel_pos)e=this.__pos.x,f=this.__pos.y,d=-d;else{if(this.canvas.__width>=this.canvas.__height)var g=2*this.canvas.__range/this.canvas.__height;else var g=2*this.canvas.__range/this.canvas.__width;var h=mat4.multiplyVec3(mat4.rotateY(mat4.rotateX(mat4.identity(mat4.create()),b.angleY),b.angleX),vec3.create([this.pos.x-this.canvas.center.x,this.pos.y-this.canvas.center.y,this.pos.z-this.canvas.center.z])),i=b.distance,j=(1+h[2]/(i-h[2]))/g;e=Math.round(j*h[0]+this.canvas.__width/2),f=Math.round(-j*h[1]+this.canvas.__height/2)}a.font=this.__height+"px "+this.__font,a.textAlign="left",a.textBaseline="middle",a.lineWidth=this.__linewidth;var k=vec(1,1,1);this.canvas.__background.equals(vec(1,1,1))&&(k=vec(0,0,0)),a.strokeStyle=color.to_html(this.__linecolor||this.__color||k);var l=e,m=f,n=a.measureText(this.__text).width,o,p,q,r,s,t;o=Math.ceil(n),p=Math.ceil(this.__height+2*this.__border),q=Math.floor(l-this.__border)+.5,r=Math.ceil(m-.4*p)-.5;if(c||d){Math.abs(d)>Math.abs(c)?(d>0?(r-=d+p/2,m-=d+p/2,t=r+p):(r-=d-p/2,m-=d-p/2,t=r),l+=c-o/2,q=l-this.border,s=l+o/2):(c>0?(q+=c,l+=c,s=q):(l+=c-o,q=l-this.border,s=l+o+this.border),m-=d,r-=d,t=r+p/2);if(this.__line){a.beginPath();if(this.space>0){var u=vec(s-e,t-f,0).norm().multiply(j*this.space);u=u.add(vec(e,f,0)),a.moveTo(u.x,u.y)}else a.moveTo(e,f);a.lineTo(s,t),a.stroke()}}else switch(this.__align){case"center":l-=n/2,q-=n/2;break;case"right":l-=n,q-=n}o+=2*this.__border;var v;this.__background==null?v=this.canvas.__background:v=this.__background,a.fillStyle=color.to_html_rgba(v,this.__opacity),a.fillRect(q,r,o,p),this.__box&&(a.beginPath(),a.moveTo(q,r),a.lineTo(q+o,r),a.lineTo(q+o,r+p),a.lineTo(q,r+p),a.closePath(),a.stroke()),a.fillStyle=color.to_html(this.__color||k),a.fillText(this.__text,l,m)},__change:function(){this.canvas!==undefined&&(this.canvas.__overlay_objects.__changed=!0)}}),subclass(compound,box),eval("0");var exports={box:box,cylinder:cylinder,cone:cone,pyramid:pyramid,sphere:sphere,arrow:arrow,curve:curve,helix:helix,ring:ring,draw:draw,label:label,distant_light:distant_light,local_light:local_light,compound:compound,attach_trail:attach_trail,attach_arrow:attach_arrow,textures:textures,bumpmaps:bumpmaps};Export(exports)}(),function(){function a(a,b){function c(){b()}setTimeout(c,1e3*a)}function b(b){a(0,b)}function d(b,d){if(d===undefined)throw new Error("rate(iterations_per_second, wait) called without wait");var e=1/b;c+=e;var f=(new Date).getTime()*.001;c>f?a(c-f,d):(c<f-.1&&(c=f),a(0,d))}"use strict",$.fn.waitfor=function(a,b){function d(e){c.unbind(a,d),b(null,e)}var c=this;this.bind(a,d)},$.fn.pause=function(a,b){function d(e){a.visible=!1,c.unbind("click",d),b(null,e)}var c=this;this.bind("click",d)};var c=0,e={sqrt:Math.sqrt,pi:Math.PI,abs:Math.abs,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,atan2:Math.atan2,exp:Math.exp,log:Math.log,pow:Math.pow,radians:function(a){return a*Math.PI/180},degrees:function(a){return a*180/Math.PI},sleep:a,update:b,rate:d};Export(e)}(),Export({shaders:{curve_render_vertex:'// Vertex shader for rendering curve segments, parameterized by\n// pos1, pos2, radius, color\n\n#ifdef GL_ES\nprecision highp float;\n#endif\n\nattribute vec4 position; // position.w is 0 at the beginning of the segment and 1 at the end; \n // position.xyz are relative to that end in an normal basis with x pointing along the segment and scaled by radius\nattribute vec3 normal;\nattribute vec2 texcoord;\nattribute vec3 bumpaxis;\n\nuniform vec4 segmentData[4];\n#define segmentPosR(i) segmentData[i].xyzw\n#define segmentColor(i) segmentData[2+i].rgba\n\nuniform mat4 viewMatrix;\nuniform mat4 projMatrix;\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump, flipx, flipy, turn\n\nmat3 getSegmentRotation() {\n // Construct the object rotation matrix. A waste to do this per vertex, but GPU >> CPU, especially javascript...\n vec3 X = normalize( segmentData[1].xyz - segmentData[0].xyz );\n float hemi = dot(X,vec3(1,0,0)); // need to prevent flip of texture seam in > pi/2 rotation\n if (hemi > 0.0) {\n hemi = 1.0; // object axis and <1,0,0> in same hemisphere\n } else {\n hemi = -1.0;\n } \n vec3 Z = cross(X,normalize(vec3(0,1,0)));\n if ( dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(1,0,0));\n if (dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(0,1,0));\n }\n }\n Z = normalize(Z);\n return mat3( X, hemi*normalize(cross(Z,X)), hemi*Z );\n}\n\nvoid main(void) { \n // A rotation matrix with x pointed along the segment\n mat3 rot = getSegmentRotation();\n\n // The position and radius of "this" end of the segment in world space\n vec4 ws_segmentEnd = segmentPosR(0) * (1.-position.w) + segmentPosR(1) * position.w;\n\n // The position of this vertex in world space\n vec3 ws_pos = ws_segmentEnd.xyz + rot * (ws_segmentEnd.w*position.xyz);\n\n vec4 pos4 = viewMatrix * vec4( ws_pos, 1.0);\n es_position = pos4.xyz;\n es_normal = (viewMatrix * vec4(rot * normal, 0.0)).xyz;\n // no texture or bump map yet for curve object:\n parameters = vec4(0.0, 0.0, 0.0, 0.0);\n bumpX = bumpaxis;\n mat_pos = texcoord;\n mat_color = segmentColor(0) * (1.-position.w) + segmentColor(1) * position.w;\n gl_Position = projMatrix * pos4;\n}\n',extent_vertex:"// Vertex shader for rendering standard 'objects' parameterized by\n// pos, axis, up, scale, color\n\n#ifdef GL_ES\nprecision highp float;\n#endif\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 texcoord;\nattribute vec3 bumpaxis;\n\nuniform vec4 objectData[5];\n#define objectPos objectData[0].xyz\n#define objectShininess objectData[0].w\n#define objectAxis objectData[1].xyz\n#define objectEmissive objectData[1].w\n#define objectUp objectData[2].xyz\n#define flags objectData[2].w\n#define objectScale objectData[3].xyz\n#define objectColor objectData[4].rgba\n\nuniform mat4 viewMatrix;\nuniform mat4 projMatrix;\nuniform vec3 center;\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump, flipx, flipy, turn\n\nvec3 encode_float(float k) { // assumes k is >= 0\n if (k <= 0.0) return vec3(0.0, 0.0, 0.0);\n float logk = log(k);\n if (logk < 0.0) {\n logk = -logk + 128.0;\n }\n return vec3(\n floor(logk)/255.0,\n floor(256.0*fract(logk))/255.0,\n floor(256.0*fract(256.0*logk))/255.0);\n}\n\nmat3 getObjectRotation() {\n // Construct the object rotation matrix. A waste to do this per vertex, but GPU >> CPU\n vec3 X = normalize(objectAxis);\n float hemi = dot(X,vec3(1,0,0)); // need to prevent flip of texture seam in > pi/2 rotation\n if (hemi > 0.0) {\n hemi = 1.0; // object axis and <1,0,0> in same hemisphere\n } else {\n hemi = -1.0;\n } \n vec3 Z = cross(X,normalize(objectUp));\n if ( dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(1,0,0));\n if (dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(0,1,0));\n }\n }\n Z = normalize(Z);\n return mat3( X, hemi*normalize(cross(Z,X)), hemi*Z );\n}\n\nvoid main(void) {\n mat3 rot = getObjectRotation();\n // The position of this vertex in world space\n vec3 ws_pos = rot*(objectScale*position) + objectPos;\n vec4 pos4 = viewMatrix * vec4( ws_pos, 1.0);\n es_position = pos4.xyz;\n es_normal = (viewMatrix * vec4(rot*normal, 0.0)).xyz;\n vec4 pos = projMatrix * pos4;\n bumpX = (viewMatrix * vec4(rot*bumpaxis, 0.0)).xyz;\n mat_pos = texcoord;\n float extent = abs(ws_pos.x-center.x);\n extent = max(abs(ws_pos.y-center.y), extent);\n extent = max(abs(ws_pos.z-center.z), extent);\n mat_color = vec4(encode_float(extent), 1.0);\n // Setting gl_Position.xy to (-1.0, -1.0) should store into pixel (0, 0), but doesn't work:\n gl_Position = vec4(-1.0, -1.0, 1e-20*extent, 1.0);\n //gl_Position = pos;\n parameters = vec4(objectShininess, objectEmissive, 0.0, 0.0);\n}\n",final_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform sampler2D FINAL;\nvarying vec2 mat_pos;\n\nvoid main(void) {\n gl_FragColor = vec4( texture2D(FINAL, mat_pos).xyz, 1.0);\n}\n",merge_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform int light_count;\nuniform vec4 light_pos[8];\nuniform vec3 light_color[8];\nuniform vec3 light_ambient;\n\nuniform sampler2D texmap; // TEXTURE0 - user texture\nuniform sampler2D bumpmap; // TEXTURE1 - user bumpmap\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\n\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump\n#define shininess parameters[0]\n#define emissive parameters[1]\n#define hasTexture parameters[2]\n#define hasBump parameters[3]\n\nuniform sampler2D C0; // TEXTURE2 - opaque color map (minormode 4)\nuniform sampler2D D2; // TEXTURE5 - 2nd of two ping-pong depth maps (minormode 7); also used for C4\nuniform sampler2D C1; // TEXTURE6 - color map for transparency render 1 (minormode 8)\nuniform sampler2D C2; // TEXTURE7 - color map for transparency render 2 (minormode 9)\nuniform sampler2D C3; // TEXTURE8 - color map for transparency render 3 (minormode 10)\nuniform vec2 canvas_size;\n\n// This code is a horrible kludge to work on Mac Snow Leopard and Linux.\n// Change almost anything, and it fails. Presumably there's something wrong\n// elsewhere in the GlowScript code, but where is unknown.\n// Obviously this (reduced) lightAt routine should be unnecessary.\n\nvec3 lightAt( vec3 normal, vec3 pos, vec3 diffuse_color, vec3 specular_color )\n{\n vec3 color;\n if (hasBump < 0.0) { // hasBump is never negative; block this code\n vec3 Y = cross(normal, bumpX);\n vec3 Nb = texture2D(bumpmap, mat_pos).xyz;\n Nb = 2.0*Nb - 1.0;\n normal = normalize(Nb.x*bumpX + Nb.y*Y + Nb.z*normal);\n }\n if (emissive < 0.0) { // emissive is never negative; block this code\n // From VPython materials.emissive:\n float d = dot(normalize(-pos), normal);\n d = pow(d * 1.5, 0.4) * 1.1;\n if (d > 1.0) d = 1.0;\n color = diffuse_color * d;\n return color;\n }\n color = light_ambient * diffuse_color;\n return diffuse_color;\n}\n\nvoid main(void) {\n // need to combine colors from C0, C1, C2, C3, C4\n vec2 loc = vec2( gl_FragCoord.x/canvas_size.x, gl_FragCoord.y/canvas_size.y);\n vec4 c0 = texture2D(C0, loc);\n vec4 c1 = texture2D(C1, loc);\n vec4 c2 = texture2D(C2, loc);\n vec4 c3 = texture2D(C3, loc);\n vec4 c4 = texture2D(D2, loc);\n vec3 mcolor = c1.rgb*c1.a + \n (1.0-c1.a)*(c2.rgb*c2.a +\n (1.0-c2.a)*(c3.rgb*c3.a +\n (1.0-c3.a)*(c4.rgb*c4.a + \n (1.0-c4.a)*c0.rgb)));\n \n // Kludge code to make things work on Snow Leopard and Linux\n vec3 color = lightAt(normalize(es_normal), es_position, mcolor, vec3(.8,.8,.8));\n gl_FragColor = vec4 (color, 1.0);\n}\n",merge_vertex:"// Vertex shader for rendering standard 'objects' parameterized by\n// pos, axis, up, scale, color\n\n#ifdef GL_ES\nprecision highp float;\n#endif\n\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 texcoord;\nattribute vec3 bumpaxis;\n\nuniform vec4 objectData[5];\n#define objectPos objectData[0].xyz\n#define objectShininess objectData[0].w\n#define objectAxis objectData[1].xyz\n#define objectEmissive objectData[1].w\n#define objectUp objectData[2].xyz\n#define flags objectData[2].w\n#define objectScale objectData[3].xyz\n#define objectColor objectData[4].rgba\n\nuniform mat4 viewMatrix;\nuniform mat4 projMatrix;\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump, flipx, flipy, turn\n\nmat3 getObjectRotation() {\n // Construct the object rotation matrix. A waste to do this per vertex, but GPU >> CPU\n vec3 X = normalize(objectAxis);\n float hemi = dot(X,vec3(1,0,0)); // need to prevent flip of texture seam in > pi/2 rotation\n if (hemi > 0.0) {\n hemi = 1.0; // object axis and <1,0,0> in same hemisphere\n } else {\n hemi = -1.0;\n } \n vec3 Z = cross(X,normalize(objectUp));\n if ( dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(1,0,0));\n if (dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(0,1,0));\n }\n }\n Z = normalize(Z);\n return mat3( X, hemi*normalize(cross(Z,X)), hemi*Z );\n}\n\nvoid main(void) {\n mat3 rot = getObjectRotation();\n // The position of this vertex in world space\n vec3 ws_pos = rot*(objectScale*position) + objectPos;\n vec4 pos4 = viewMatrix * vec4( ws_pos, 1.0);\n es_position = pos4.xyz;\n //es_normal = (viewMatrix * vec4(rot*normal, 0.0)).xyz;\n vec4 pos = projMatrix * pos4;\n bumpX = (viewMatrix * vec4(rot*bumpaxis, 0.0)).xyz;\n mat_pos = texcoord;\n mat_color = objectColor;\n //gl_Position = pos;\n parameters = vec4(objectShininess, objectEmissive, 0.0, 0.0);\n \n es_normal = normal;\n gl_Position = vec4(position, 1.0);\n}\n"
,opaque_render_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform int light_count;\nuniform vec4 light_pos[8];\nuniform vec3 light_color[8];\nuniform vec3 light_ambient;\n\nuniform sampler2D texmap; // TEXTURE0 - user texture\nuniform sampler2D bumpmap; // TEXTURE1 - user bumpmap\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump\n#define shininess parameters[0]\n#define emissive parameters[1]\n#define hasTexture parameters[2]\n#define hasBump parameters[3]\n\n// Return lit surface color based on the given surface properties and the lights\n// specified by the light_* uniforms.\nvec3 lightAt( vec3 normal, vec3 pos, vec3 diffuse_color, vec3 specular_color )\n{\n vec3 color;\n if (hasTexture != 0.0) {\n diffuse_color = diffuse_color * texture2D(texmap, mat_pos).xyz;\n }\n if (hasBump != 0.0) {\n vec3 Y = cross(normal, bumpX);\n vec3 Nb = texture2D(bumpmap, mat_pos).xyz;\n Nb = 2.0*Nb - 1.0;\n normal = normalize(Nb.x*bumpX + Nb.y*Y + Nb.z*normal);\n }\n if (emissive != 0.0) {\n // From VPython materials.emissive:\n float d = dot(normalize(-pos), normal);\n d = pow(d * 1.5, 0.4) * 1.1;\n if (d > 1.0) d = 1.0;\n color = diffuse_color * d;\n return color;\n }\n color = light_ambient * diffuse_color;\n\n for(int i=0; i<8; i++) {\n if (i >= light_count) break;\n vec3 L = light_pos[i].xyz - pos*light_pos[i].w; // w == 0 for distant_light\n L = normalize(L);\n color += (light_color[i].rgb * max(dot(normal,L), 0.0))*diffuse_color;\n if (shininess > 0.0) {\n vec3 R = reflect(L,normal);\n color += specular_color * light_color[i].rgb * pow(max(dot(R,normalize(pos)),0.0),100.0*shininess);\n }\n }\n return color;\n}\n\nvoid main(void) {\n vec3 color = lightAt(normalize(es_normal), es_position, mat_color.rgb, vec3(.8,.8,.8));\n gl_FragColor = vec4( color, 1.0 );\n}\n",peel_color_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform int light_count;\nuniform vec4 light_pos[8];\nuniform vec3 light_color[8];\nuniform vec3 light_ambient;\nuniform vec2 canvas_size;\n// minormode = 0 render, 1 pick, 2 autoscale, 4 C0, 5 D0, 6 D1, 7 D2, 8 C1, 9 C2, 10 C3, 11 C4\nuniform int minormode;\n\nuniform sampler2D texmap; // TEXTURE0 - user texture\nuniform sampler2D bumpmap; // TEXTURE1 - user bumpmap\nuniform sampler2D D0; // TEXTURE3 - opaque depth map (minormode 5)\nuniform sampler2D D1; // TEXTURE4 - 1st of two ping-pong depth maps (minormode 6)\nuniform sampler2D D2; // TEXTURE5 - 2nd of two ping-pong depth maps (minormode 7); also used for C4\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump\n#define shininess parameters[0]\n#define emissive parameters[1]\n#define hasTexture parameters[2]\n#define hasBump parameters[3]\n\n// Return lit surface color based on the given surface properties and the lights\n// specified by the light_* uniforms.\nvec3 lightAt( vec3 normal, vec3 pos, vec3 diffuse_color, vec3 specular_color )\n{\n vec3 color;\n if (hasTexture != 0.0) {\n diffuse_color = diffuse_color * texture2D(texmap, mat_pos).xyz;\n }\n if (hasBump != 0.0) {\n vec3 Y = cross(normal, bumpX);\n vec3 Nb = texture2D(bumpmap, mat_pos).xyz;\n Nb = 2.0*Nb - 1.0;\n normal = normalize(Nb.x*bumpX + Nb.y*Y + Nb.z*normal);\n }\n if (emissive != 0.0) {\n // From VPython materials.emissive:\n float d = dot(normalize(-pos), normal);\n d = pow(d * 1.5, 0.4) * 1.1;\n if (d > 1.0) d = 1.0;\n color = diffuse_color * d;\n return color;\n }\n color = light_ambient * diffuse_color;\n\n for(int i=0; i<8; i++) {\n if (i >= light_count) break;\n vec3 L = light_pos[i].xyz - pos*light_pos[i].w; // w == 0 for distant_light\n L = normalize(L);\n color += (light_color[i].rgb * max(dot(normal,L), 0.0))*diffuse_color;\n if (shininess > 0.0) {\n vec3 R = reflect(L,normal);\n color += specular_color * light_color[i].rgb * pow(max(dot(R,normalize(pos)),0.0),100.0*shininess);\n }\n }\n return color;\n}\n\nvec4 encode(float k) { // assumes k is >= 0\n if (k <= 0.0) return vec4(0.0, 0.0, 0.0, 0.0);\n return vec4(\n floor(256.0*k)/255.0,\n floor(256.0*fract(256.0*k))/255.0,\n floor(256.0*fract(65536.0*k))/255.0,\n 0.0);\n}\n\nfloat decode(vec4 d) {\n if (length(d) == 0.0) return 0.0;\n return (65536.0*d[0] + 256.0*d[1] + d[2])/16777216.0;\n}\n\nvoid main(void) {\n // create transparency color map - C1 (8), C2 (9), C3 (10), C4 (11)\n vec3 color = lightAt(normalize(es_normal), es_position, mat_color.rgb, vec3(.8,.8,.8));\n vec2 loc = vec2(gl_FragCoord.x/canvas_size.x, gl_FragCoord.y/canvas_size.y);\n float z = decode(encode(1.0-gl_FragCoord.z)); // bigger number => closer to camera; distance out of screen\n float zmin = decode(texture2D(D0, loc));\n float zmax;\n if (minormode == 8) { // C1\n if (z > zmin) {\n gl_FragColor = vec4( color, mat_color.a );\n } else {\n discard;\n }\n } else {\n if (minormode == 10) { // C3\n zmax = decode(texture2D(D2, loc));\n } else { // C2 or C4\n zmax = decode(texture2D(D1, loc));\n }\n if (zmin < z && z < zmax) {\n gl_FragColor = vec4( color, mat_color.a );\n } else {\n discard;\n }\n }\n}\n",peel_depth_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform int light_count;\nuniform vec4 light_pos[8];\nuniform vec3 light_color[8];\nuniform vec3 light_ambient;\n\nuniform sampler2D texmap; // TEXTURE0 - user texture\nuniform sampler2D bumpmap; // TEXTURE1 - user bumpmap\n\nuniform vec2 canvas_size;\nuniform sampler2D D0; // TEXTURE3 - opaque depth map (minormode 5)\nuniform sampler2D D1; // TEXTURE4 - 1st of two ping-pong depth maps (minormode 6)\nuniform sampler2D D2; // TEXTURE5 - 2nd of two ping-pong depth maps (minormode 7); also used for C4\n// minormode = 0 render, 1 pick, 2 autoscale, 4 C0, 5 D0, 6 D1, 7 D2, 8 C1, 9 C2, 10 C3, 11 C4\nuniform int minormode;\n// depthreference = 0 if no reference to max depth map, 1 if refers to D1, 2 if refers to D2\nuniform int depthreference;\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\n\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump\n#define shininess parameters[0]\n#define emissive parameters[1]\n#define hasTexture parameters[2]\n#define hasBump parameters[3]\n\nvec4 encode(float k) { // assumes k is >= 0\n if (k <= 0.0) return vec4(0.0, 0.0, 0.0, 0.0);\n return vec4(\n floor(256.0*k)/255.0,\n floor(256.0*fract(256.0*k))/255.0,\n floor(256.0*fract(65536.0*k))/255.0,\n 0.0);\n}\n\nfloat decode(vec4 d) {\n if (length(d) == 0.0) return 0.0;\n return (65536.0*d[0] + 256.0*d[1] + d[2])/16777216.0;\n}\n\n// This code is a horrible kludge to work on Mac Snow Leopard and Linux.\n// Change almost anything, and it fails. Presumably there's something wrong\n// elsewhere in the GlowScript code, but where is unknown.\n// Obviously this (reduced) lightAt routine should be unnecessary.\n\nvec3 lightAt( vec3 normal, vec3 pos, vec3 diffuse_color, vec3 specular_color )\n{\n vec3 color;\n if (hasBump < 0.0) { // hasBump is never negative; block this code\n vec3 Y = cross(normal, bumpX);\n vec3 Nb = texture2D(bumpmap, mat_pos).xyz;\n Nb = 2.0*Nb - 1.0;\n normal = normalize(Nb.x*bumpX + Nb.y*Y + Nb.z*normal);\n }\n if (emissive < 0.0) { // emissive is never negative; block this code\n // From VPython materials.emissive:\n float d = dot(normalize(-pos), normal);\n d = pow(d * 1.5, 0.4) * 1.1;\n if (d > 1.0) d = 1.0;\n color = diffuse_color * d;\n return color;\n }\n color = light_ambient * diffuse_color;\n return mat_color.rgb;\n}\n\nvoid main(void) {\n // Kludge code to make things work on Snow Leopard and Linux\n vec3 color = lightAt(normalize(es_normal), es_position, mat_color.rgb, vec3(.8,.8,.8));\n gl_FragColor = vec4(color, mat_color.a);\n \n // create depth map, D0 (5); ping-pong D1 (6) and D2 (7)\n vec4 c = encode(1.0-gl_FragCoord.z);\n float z = decode(c);\n if (minormode == 5) { // D0\n gl_FragColor = c;\n } else {\n vec2 loc = vec2(gl_FragCoord.x/canvas_size.x, gl_FragCoord.y/canvas_size.y);\n float zmin = decode(texture2D(D0, loc));\n float zmax;\n if (depthreference == 0) { // first creation of D1\n if (z > zmin) {\n gl_FragColor = c;\n } else {\n discard;\n }\n } else {\n if (depthreference == 1) {\n zmax = decode(texture2D(D1, loc));\n } else {\n zmax = decode(texture2D(D2, loc));\n }\n if (zmin < z && z < zmax) {\n gl_FragColor = c;\n } else {\n discard;\n }\n }\n }\n}\n",pick_fragment:"#ifdef GL_ES\nprecision highp float;\n#endif\n\nuniform int light_count;\nuniform vec4 light_pos[8];\nuniform vec3 light_color[8];\nuniform vec3 light_ambient;\n\nuniform sampler2D texmap; // TEXTURE0 - user texture\nuniform sampler2D bumpmap; // TEXTURE1 - user bumpmap\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\n\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump\n#define shininess parameters[0]\n#define emissive parameters[1]\n#define hasTexture parameters[2]\n#define hasBump parameters[3]\n\n// This code is a horrible kludge to work on Mac Snow Leopard and Linux.\n// Change almost anything, and it fails. Presumably there's something wrong\n// elsewhere in the GlowScript code, but where is unknown.\n// Obviously this (reduced) lightAt routine should be unnecessary.\n\nvec3 lightAt( vec3 normal, vec3 pos, vec3 diffuse_color, vec3 specular_color )\n{\n vec3 color;\n if (hasBump < 0.0) { // hasBump is never negative; block this code\n vec3 Y = cross(normal, bumpX);\n vec3 Nb = texture2D(bumpmap, mat_pos).xyz;\n Nb = 2.0*Nb - 1.0;\n normal = normalize(Nb.x*bumpX + Nb.y*Y + Nb.z*normal);\n }\n if (emissive < 0.0) { // emissive is never negative; block this code\n // From VPython materials.emissive:\n float d = dot(normalize(-pos), normal);\n d = pow(d * 1.5, 0.4) * 1.1;\n if (d > 1.0) d = 1.0;\n color = diffuse_color * d;\n return color;\n }\n color = light_ambient * diffuse_color;\n return mat_color.rgb;\n}\n\nvoid main(void) {\n // Kludge code to make things work on Snow Leopard and Linux\n vec3 color = lightAt(normalize(es_normal), es_position, mat_color.rgb, vec3(.8,.8,.8));\n gl_FragColor = vec4(color, mat_color.a);\n}\n",pick_vertex:"// Vertex shader for rendering standard 'objects' parameterized by\n// pos, axis, up, scale, color\n\n#ifdef GL_ES\nprecision highp float;\n#endif\n\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 texcoord;\nattribute vec3 bumpaxis;\n\nuniform vec4 objectData[5];\n#define objectPos objectData[0].xyz\n#define objectShininess objectData[0].w\n#define objectAxis objectData[1].xyz\n#define objectEmissive objectData[1].w\n#define objectUp objectData[2].xyz\n#define flags objectData[2].w\n#define objectScale objectData[3].xyz\n#define objectColor objectData[4].rgba\n\nuniform mat4 viewMatrix;\nuniform mat4 projMatrix;\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump, flipx, flipy, turn\n\nmat3 getObjectRotation() {\n // Construct the object rotation matrix. A waste to do this per vertex, but GPU >> CPU\n vec3 X = normalize(objectAxis);\n float hemi = dot(X,vec3(1,0,0)); // need to prevent flip of texture seam in > pi/2 rotation\n if (hemi > 0.0) {\n hemi = 1.0; // object axis and <1,0,0> in same hemisphere\n } else {\n hemi = -1.0;\n } \n vec3 Z = cross(X,normalize(objectUp));\n if ( dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(1,0,0));\n if (dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(0,1,0));\n }\n }\n Z = normalize(Z);\n return mat3( X, hemi*normalize(cross(Z,X)), hemi*Z );\n}\n\nvoid main(void) {\n mat3 rot = getObjectRotation();\n // The position of this vertex in world space\n vec3 ws_pos = rot*(objectScale*position) + objectPos;\n vec4 pos4 = viewMatrix * vec4( ws_pos, 1.0);\n es_position = pos4.xyz;\n es_normal = (viewMatrix * vec4(rot*normal, 0.0)).xyz;\n vec4 pos = projMatrix * pos4;\n bumpX = (viewMatrix * vec4(rot*bumpaxis, 0.0)).xyz;\n mat_pos = texcoord;\n mat_color = objectColor;\n gl_Position = pos;\n parameters = vec4(objectShininess, objectEmissive, 0.0, 0.0);\n}\n",render_vertex:"// Vertex shader for rendering standard 'objects' parameterized by\n// pos, axis, up, scale, color\n\n#ifdef GL_ES\nprecision highp float;\n#endif\n\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 texcoord;\nattribute vec3 bumpaxis;\n\nuniform vec4 objectData[5];\n#define objectPos objectData[0].xyz\n#define objectShininess objectData[0].w\n#define objectAxis objectData[1].xyz\n#define objectEmissive objectData[1].w\n#define objectUp objectData[2].xyz\n#define flags objectData[2].w\n#define objectScale objectData[3].xyz\n#define objectColor objectData[4].rgba\n\nuniform mat4 viewMatrix;\nuniform mat4 projMatrix;\n\nvarying vec3 es_position; // eye space surface position\nvarying vec3 es_normal; // eye space surface normal\nvarying vec2 mat_pos; // surface material position in [0,1]^2\nvarying vec4 mat_color;\nvarying vec3 bumpX;\nvarying vec4 parameters; // shininess, emissive, hasTexture, hasBump, flipx, flipy, turn\n\nmat3 getObjectRotation() {\n // Construct the object rotation matrix. A waste to do this per vertex, but GPU >> CPU\n vec3 X = normalize(objectAxis);\n float hemi = dot(X,vec3(1,0,0)); // need to prevent flip of texture seam in > pi/2 rotation\n if (hemi > 0.0) {\n hemi = 1.0; // object axis and <1,0,0> in same hemisphere\n } else {\n hemi = -1.0;\n } \n vec3 Z = cross(X,normalize(objectUp));\n if ( dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(1,0,0));\n if (dot(Z,Z) < 1e-10 ) {\n Z = cross(X, vec3(0,1,0));\n }\n }\n Z = normalize(Z);\n return mat3( X, hemi*normalize(cross(Z,X)), hemi*Z );\n}\n\nvoid main(void) {\n mat3 rot = getObjectRotation();\n // The position of this vertex in world space\n vec3 ws_pos = rot*(objectScale*position) + objectPos;\n vec4 pos4 = viewMatrix * vec4( ws_pos, 1.0);\n es_position = pos4.xyz;\n es_normal = (viewMatrix * vec4(rot*normal, 0.0)).xyz;\n vec4 pos = projMatrix * pos4;\n bumpX = (viewMatrix * vec4(rot*bumpaxis, 0.0)).xyz;\n mat_pos = texcoord;\n mat_color = objectColor;\n gl_Position = pos;\n float f = flags; // turn, flipy, flipx, sides, right, left, bumpmap, texture\n float turn = floor(f/128.0);\n f -= 128.0*turn;\n float flipy = floor(f/64.0);\n f -= 64.0*flipy;\n float flipx = floor(f/32.0);\n f -= 32.0*flipx;\n float sides = floor(f/16.0);\n f -= 16.0*sides;\n float right = floor(f/8.0);\n f -= 8.0*right;\n float left = floor(f/4.0);\n f -= 4.0*left;\n float B = floor(f/2.0);\n f -= 2.0*B;\n float T = f;\n if (T != 0.0) {\n if (flipx != 0.0) {\n mat_pos.x = 1.0 - mat_pos.x;\n }\n if (flipy != 0.0) {\n mat_pos.y = 1.0 - mat_pos.y;\n }\n if (turn > 0.0 && turn <= 3.0) {\n if (turn == 1.0) {\n mat_pos = vec2(mat_pos.y,1.0 - mat_pos.x);\n } else if (turn == 2.0) {\n mat_pos = vec2(1.0 - mat_pos.x,1.0 - mat_pos.y);\n } else {\n mat_pos = vec2(1.0 - mat_pos.y,mat_pos.x);\n }\n }\n T = 0.0;\n bool L = (normal.x == -1.0);\n bool R = (normal.x == 1.0);\n bool S = !L && !R;\n if (L && left == 1.0) T = 1.0;\n if (R && right == 1.0) T = 1.0;\n if (S && sides == 1.0) T = 1.0;\n if (T == 0.0) {\n B = 0.0;\n } else if (left == 0.0 || right == 0.0 || sides == 0.0) {\n // don't mix texture and object color if texture doesn't cover entire object\n mat_color = vec4(1.0, 1.0, 1.0, 1.0);\n }\n }\n parameters = vec4(objectShininess, objectEmissive, T, B);\n}\n"}})/*This is a combined, compressed file. Look at https://bitbucket.org/davidscherer/glowscript for source code and copyright information.*/
;(function(){})();