0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00
liabru-matter-js/build/matter.min.js

87 lines
82 KiB
JavaScript
Raw Normal View History

2014-02-19 09:15:05 -05:00
/**
2016-11-09 15:46:45 -05:00
* matter-js 0.11.1 by @liabru 2016-11-09
2014-02-19 09:15:05 -05:00
* http://brm.io/matter-js/
2015-12-05 11:47:50 -05:00
* License MIT
2014-02-19 09:15:05 -05:00
*/
2016-11-02 20:49:53 -04:00
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Matter=e()}}(function(){return function e(t,o,n){function i(s,a){if(!o[s]){if(!t[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(r)return r(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var u=o[s]={exports:{}};t[s][0].call(u.exports,function(e){var o=t[s][1][e];return i(o?o:e)},u,u.exports,e,t,o,n)}return o[s].exports}for(var r="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Sleeping"),a=(e("../render/Render"),e("../core/Common")),l=e("../geometry/Bounds"),c=e("../geometry/Axes");!function(){n._inertiaScale=4,n._nextCollidingGroupId=1,
n._nextNonCollidingGroupId=-1,n._nextCategory=1,n.create=function(t){var o={id:a.nextId(),type:"body",label:"Body",parts:[],angle:0,vertices:i.fromPath("L 0 0 L 40 0 L 40 40 L 0 40"),position:{x:0,y:0},force:{x:0,y:0},torque:0,positionImpulse:{x:0,y:0},constraintImpulse:{x:0,y:0,angle:0},totalContacts:0,speed:0,angularSpeed:0,velocity:{x:0,y:0},angularVelocity:0,isSensor:!1,isStatic:!1,isSleeping:!1,motion:0,sleepThreshold:60,density:.001,restitution:0,friction:.1,frictionStatic:.5,frictionAir:.01,collisionFilter:{category:1,mask:4294967295,group:0},slop:.05,timeScale:1,render:{visible:!0,opacity:1,sprite:{xScale:1,yScale:1,xOffset:0,yOffset:0},lineWidth:1.5}},n=a.extend(o,t);return e(n,t),n},n.nextGroup=function(e){return e?n._nextNonCollidingGroupId--:n._nextCollidingGroupId++},n.nextCategory=function(){return n._nextCategory=n._nextCategory<<1,n._nextCategory};var e=function(e,t){t=t||{},n.set(e,{bounds:e.bounds||l.create(e.vertices),positionPrev:e.positionPrev||r.clone(e.position),anglePrev:e.anglePrev||e.angle,
2016-01-16 17:43:32 -05:00
vertices:e.vertices,parts:e.parts||[e],isStatic:e.isStatic,isSleeping:e.isSleeping,parent:e.parent||e}),i.rotate(e.vertices,e.angle,e.position),c.rotate(e.axes,e.angle),l.update(e.bounds,e.vertices,e.velocity),n.set(e,{axes:t.axes||e.axes,area:t.area||e.area,mass:t.mass||e.mass,inertia:t.inertia||e.inertia});var o=e.isStatic?"#eeeeee":a.choose(["#556270","#4ECDC4","#C7F464","#FF6B6B","#C44D58"]),s=a.shadeColor(o,-20);e.render.fillStyle=e.render.fillStyle||o,e.render.strokeStyle=e.render.strokeStyle||s,e.render.sprite.xOffset+=-(e.bounds.min.x-e.position.x)/(e.bounds.max.x-e.bounds.min.x),e.render.sprite.yOffset+=-(e.bounds.min.y-e.position.y)/(e.bounds.max.y-e.bounds.min.y)};n.set=function(e,t,o){var i;"string"==typeof t&&(i=t,t={},t[i]=o);for(i in t)if(o=t[i],t.hasOwnProperty(i))switch(i){case"isStatic":n.setStatic(e,o);break;case"isSleeping":s.set(e,o);break;case"mass":n.setMass(e,o);break;case"density":n.setDensity(e,o);break;case"inertia":n.setInertia(e,o);break;case"vertices":n.setVertices(e,o);
break;case"position":n.setPosition(e,o);break;case"angle":n.setAngle(e,o);break;case"velocity":n.setVelocity(e,o);break;case"angularVelocity":n.setAngularVelocity(e,o);break;case"parts":n.setParts(e,o);break;default:e[i]=o}},n.setStatic=function(e,t){for(var o=0;o<e.parts.length;o++){var n=e.parts[o];n.isStatic=t,t&&(n.restitution=0,n.friction=1,n.mass=n.inertia=n.density=1/0,n.inverseMass=n.inverseInertia=0,n.positionPrev.x=n.position.x,n.positionPrev.y=n.position.y,n.anglePrev=n.angle,n.angularVelocity=0,n.speed=0,n.angularSpeed=0,n.motion=0)}},n.setMass=function(e,t){e.mass=t,e.inverseMass=1/e.mass,e.density=e.mass/e.area},n.setDensity=function(e,t){n.setMass(e,t*e.area),e.density=t},n.setInertia=function(e,t){e.inertia=t,e.inverseInertia=1/e.inertia},n.setVertices=function(e,t){t[0].body===e?e.vertices=t:e.vertices=i.create(t,e),e.axes=c.fromVertices(e.vertices),e.area=i.area(e.vertices),n.setMass(e,e.density*e.area);var o=i.centre(e.vertices);i.translate(e.vertices,o,-1),n.setInertia(e,n._inertiaScale*i.inertia(e.vertices,e.mass)),
2016-11-02 20:49:53 -04:00
i.translate(e.vertices,e.position),l.update(e.bounds,e.vertices,e.velocity)},n.setParts=function(e,o,r){var s;for(o=o.slice(0),e.parts.length=0,e.parts.push(e),e.parent=e,s=0;s<o.length;s++){var a=o[s];a!==e&&(a.parent=e,e.parts.push(a))}if(1!==e.parts.length){if(r="undefined"!=typeof r?r:!0){var l=[];for(s=0;s<o.length;s++)l=l.concat(o[s].vertices);i.clockwiseSort(l);var c=i.hull(l),u=i.centre(c);n.setVertices(e,c),i.translate(e.vertices,u)}var d=t(e);e.area=d.area,e.parent=e,e.position.x=d.centre.x,e.position.y=d.centre.y,e.positionPrev.x=d.centre.x,e.positionPrev.y=d.centre.y,n.setMass(e,d.mass),n.setInertia(e,d.inertia),n.setPosition(e,d.centre)}},n.setPosition=function(e,t){var o=r.sub(t,e.position);e.positionPrev.x+=o.x,e.positionPrev.y+=o.y;for(var n=0;n<e.parts.length;n++){var s=e.parts[n];s.position.x+=o.x,s.position.y+=o.y,i.translate(s.vertices,o),l.update(s.bounds,s.vertices,e.velocity)}},n.setAngle=function(e,t){var o=t-e.angle;e.anglePrev+=o;for(var n=0;n<e.parts.length;n++){
var s=e.parts[n];s.angle+=o,i.rotate(s.vertices,o,e.position),c.rotate(s.axes,o),l.update(s.bounds,s.vertices,e.velocity),n>0&&r.rotateAbout(s.position,o,e.position,s.position)}},n.setVelocity=function(e,t){e.positionPrev.x=e.position.x-t.x,e.positionPrev.y=e.position.y-t.y,e.velocity.x=t.x,e.velocity.y=t.y,e.speed=r.magnitude(e.velocity)},n.setAngularVelocity=function(e,t){e.anglePrev=e.angle-t,e.angularVelocity=t,e.angularSpeed=Math.abs(e.angularVelocity)},n.translate=function(e,t){n.setPosition(e,r.add(e.position,t))},n.rotate=function(e,t){n.setAngle(e,e.angle+t)},n.scale=function(e,o,r,s){for(var a=0;a<e.parts.length;a++){var u=e.parts[a];i.scale(u.vertices,o,r,e.position),u.axes=c.fromVertices(u.vertices),e.isStatic||(u.area=i.area(u.vertices),n.setMass(u,e.density*u.area),i.translate(u.vertices,{x:-u.position.x,y:-u.position.y}),n.setInertia(u,i.inertia(u.vertices,u.mass)),i.translate(u.vertices,{x:u.position.x,y:u.position.y})),l.update(u.bounds,u.vertices,e.velocity)}if(e.circleRadius&&(o===r?e.circleRadius*=o:e.circleRadius=null),
!e.isStatic){var d=t(e);e.area=d.area,n.setMass(e,d.mass),n.setInertia(e,d.inertia)}},n.update=function(e,t,o,n){var s=Math.pow(t*o*e.timeScale,2),a=1-e.frictionAir*o*e.timeScale,u=e.position.x-e.positionPrev.x,d=e.position.y-e.positionPrev.y;e.velocity.x=u*a*n+e.force.x/e.mass*s,e.velocity.y=d*a*n+e.force.y/e.mass*s,e.positionPrev.x=e.position.x,e.positionPrev.y=e.position.y,e.position.x+=e.velocity.x,e.position.y+=e.velocity.y,e.angularVelocity=(e.angle-e.anglePrev)*a*n+e.torque/e.inertia*s,e.anglePrev=e.angle,e.angle+=e.angularVelocity,e.speed=r.magnitude(e.velocity),e.angularSpeed=Math.abs(e.angularVelocity);for(var p=0;p<e.parts.length;p++){var f=e.parts[p];i.translate(f.vertices,e.velocity),p>0&&(f.position.x+=e.velocity.x,f.position.y+=e.velocity.y),0!==e.angularVelocity&&(i.rotate(f.vertices,e.angularVelocity,e.position),c.rotate(f.axes,e.angularVelocity),p>0&&r.rotateAbout(f.position,e.angularVelocity,e.position,f.position)),l.update(f.bounds,f.vertices,e.velocity)}},n.applyForce=function(e,t,o){
2016-09-19 18:53:35 -04:00
e.force.x+=o.x,e.force.y+=o.y;var n={x:t.x-e.position.x,y:t.y-e.position.y};e.torque+=n.x*o.y-n.y*o.x};var t=function(e){for(var t={mass:0,area:0,inertia:0,centre:{x:0,y:0}},o=1===e.parts.length?0:1;o<e.parts.length;o++){var n=e.parts[o];t.mass+=n.mass,t.area+=n.area,t.inertia+=n.inertia,t.centre=r.add(t.centre,r.mult(n.position,n.mass!==1/0?n.mass:1))}return t.centre=r.div(t.centre,t.mass!==1/0?t.mass:e.parts.length),t}}()},{"../core/Common":14,"../core/Sleeping":22,"../geometry/Axes":25,"../geometry/Bounds":26,"../geometry/Vector":28,"../geometry/Vertices":29,"../render/Render":31}],2:[function(e,t,o){var n={};t.exports=n;var i=e("../core/Events"),r=e("../core/Common"),s=e("./Body");!function(){n.create=function(e){return r.extend({id:r.nextId(),type:"composite",parent:null,isModified:!1,bodies:[],constraints:[],composites:[],label:"Composite"},e)},n.setModified=function(e,t,o,i){if(e.isModified=t,o&&e.parent&&n.setModified(e.parent,t,o,i),i)for(var r=0;r<e.composites.length;r++){var s=e.composites[r];
n.setModified(s,t,o,i)}},n.add=function(e,t){var o=[].concat(t);i.trigger(e,"beforeAdd",{object:t});for(var s=0;s<o.length;s++){var a=o[s];switch(a.type){case"body":if(a.parent!==a){r.warn("Composite.add: skipped adding a compound body part (you must add its parent instead)");break}n.addBody(e,a);break;case"constraint":n.addConstraint(e,a);break;case"composite":n.addComposite(e,a);break;case"mouseConstraint":n.addConstraint(e,a.constraint)}}return i.trigger(e,"afterAdd",{object:t}),e},n.remove=function(e,t,o){var r=[].concat(t);i.trigger(e,"beforeRemove",{object:t});for(var s=0;s<r.length;s++){var a=r[s];switch(a.type){case"body":n.removeBody(e,a,o);break;case"constraint":n.removeConstraint(e,a,o);break;case"composite":n.removeComposite(e,a,o);break;case"mouseConstraint":n.removeConstraint(e,a.constraint)}}return i.trigger(e,"afterRemove",{object:t}),e},n.addComposite=function(e,t){return e.composites.push(t),t.parent=e,n.setModified(e,!0,!0,!1),e},n.removeComposite=function(e,t,o){var i=r.indexOf(e.composites,t);
if(-1!==i&&(n.removeCompositeAt(e,i),n.setModified(e,!0,!0,!1)),o)for(var s=0;s<e.composites.length;s++)n.removeComposite(e.composites[s],t,!0);return e},n.removeCompositeAt=function(e,t){return e.composites.splice(t,1),n.setModified(e,!0,!0,!1),e},n.addBody=function(e,t){return e.bodies.push(t),n.setModified(e,!0,!0,!1),e},n.removeBody=function(e,t,o){var i=r.indexOf(e.bodies,t);if(-1!==i&&(n.removeBodyAt(e,i),n.setModified(e,!0,!0,!1)),o)for(var s=0;s<e.composites.length;s++)n.removeBody(e.composites[s],t,!0);return e},n.removeBodyAt=function(e,t){return e.bodies.splice(t,1),n.setModified(e,!0,!0,!1),e},n.addConstraint=function(e,t){return e.constraints.push(t),n.setModified(e,!0,!0,!1),e},n.removeConstraint=function(e,t,o){var i=r.indexOf(e.constraints,t);if(-1!==i&&n.removeConstraintAt(e,i),o)for(var s=0;s<e.composites.length;s++)n.removeConstraint(e.composites[s],t,!0);return e},n.removeConstraintAt=function(e,t){return e.constraints.splice(t,1),n.setModified(e,!0,!0,!1),e},n.clear=function(e,t,o){
if(o)for(var i=0;i<e.composites.length;i++)n.clear(e.composites[i],t,!0);return t?e.bodies=e.bodies.filter(function(e){return e.isStatic}):e.bodies.length=0,e.constraints.length=0,e.composites.length=0,n.setModified(e,!0,!0,!1),e},n.allBodies=function(e){for(var t=[].concat(e.bodies),o=0;o<e.composites.length;o++)t=t.concat(n.allBodies(e.composites[o]));return t},n.allConstraints=function(e){for(var t=[].concat(e.constraints),o=0;o<e.composites.length;o++)t=t.concat(n.allConstraints(e.composites[o]));return t},n.allComposites=function(e){for(var t=[].concat(e.composites),o=0;o<e.composites.length;o++)t=t.concat(n.allComposites(e.composites[o]));return t},n.get=function(e,t,o){var i,r;switch(o){case"body":i=n.allBodies(e);break;case"constraint":i=n.allConstraints(e);break;case"composite":i=n.allComposites(e).concat(e)}return i?(r=i.filter(function(e){return e.id.toString()===t.toString()}),0===r.length?null:r[0]):null},n.move=function(e,t,o){return n.remove(e,t),n.add(o,t),e},n.rebase=function(e){
2016-11-02 20:49:53 -04:00
for(var t=n.allBodies(e).concat(n.allConstraints(e)).concat(n.allComposites(e)),o=0;o<t.length;o++)t[o].id=r.nextId();return n.setModified(e,!0,!0,!1),e},n.translate=function(e,t,o){for(var i=o?n.allBodies(e):e.bodies,r=0;r<i.length;r++)s.translate(i[r],t);return n.setModified(e,!0,!0,!1),e},n.rotate=function(e,t,o,i){for(var r=Math.cos(t),a=Math.sin(t),l=i?n.allBodies(e):e.bodies,c=0;c<l.length;c++){var u=l[c],d=u.position.x-o.x,p=u.position.y-o.y;s.setPosition(u,{x:o.x+(d*r-p*a),y:o.y+(d*a+p*r)}),s.rotate(u,t)}return n.setModified(e,!0,!0,!1),e},n.scale=function(e,t,o,i,r){for(var a=r?n.allBodies(e):e.bodies,l=0;l<a.length;l++){var c=a[l],u=c.position.x-i.x,d=c.position.y-i.y;s.setPosition(c,{x:i.x+u*t,y:i.y+d*o}),s.scale(c,t,o)}return n.setModified(e,!0,!0,!1),e}}()},{"../core/Common":14,"../core/Events":16,"./Body":1}],3:[function(e,t,o){var n={};t.exports=n;var i=e("./Composite"),r=(e("../constraint/Constraint"),e("../core/Common"));!function(){n.create=function(e){var t=i.create(),o={
label:"World",gravity:{x:0,y:1,scale:.001},bounds:{min:{x:-(1/0),y:-(1/0)},max:{x:1/0,y:1/0}}};return r.extend(t,o,e)}}()},{"../constraint/Constraint":12,"../core/Common":14,"./Composite":2}],4:[function(e,t,o){var n={};t.exports=n,function(){n.create=function(e){return{id:n.id(e),vertex:e,normalImpulse:0,tangentImpulse:0}},n.id=function(e){return e.body.id+"_"+e.index}}()},{}],5:[function(e,t,o){var n={};t.exports=n;var i=e("./SAT"),r=e("./Pair"),s=e("../geometry/Bounds");!function(){n.collisions=function(e,t){for(var o=[],a=t.pairs.table,l=0;l<e.length;l++){var c=e[l][0],u=e[l][1];if((!c.isStatic&&!c.isSleeping||!u.isStatic&&!u.isSleeping)&&n.canCollide(c.collisionFilter,u.collisionFilter)&&s.overlaps(c.bounds,u.bounds))for(var d=c.parts.length>1?1:0;d<c.parts.length;d++)for(var p=c.parts[d],f=u.parts.length>1?1:0;f<u.parts.length;f++){var v=u.parts[f];if(p===c&&v===u||s.overlaps(p.bounds,v.bounds)){var m,y=r.id(p,v),g=a[y];m=g&&g.isActive?g.collision:null;var x=i.collides(p,v,m);x.collided&&o.push(x);
2016-09-19 18:53:35 -04:00
}}}return o},n.canCollide=function(e,t){return e.group===t.group&&0!==e.group?e.group>0:0!==(e.mask&t.category)&&0!==(t.mask&e.category)}}()},{"../geometry/Bounds":26,"./Pair":7,"./SAT":11}],6:[function(e,t,o){var n={};t.exports=n;var i=e("./Pair"),r=e("./Detector"),s=e("../core/Common");!function(){n.create=function(e){var t={controller:n,detector:r.collisions,buckets:{},pairs:{},pairsList:[],bucketWidth:48,bucketHeight:48};return s.extend(t,e)},n.update=function(o,n,i,r){var s,p,f,v,m,y=i.world,g=o.buckets,x=!1;for(s=0;s<n.length;s++){var h=n[s];if((!h.isSleeping||r)&&!(h.bounds.max.x<y.bounds.min.x||h.bounds.min.x>y.bounds.max.x||h.bounds.max.y<y.bounds.min.y||h.bounds.min.y>y.bounds.max.y)){var b=t(o,h);if(!h.region||b.id!==h.region.id||r){h.region&&!r||(h.region=b);var w=e(b,h.region);for(p=w.startCol;p<=w.endCol;p++)for(f=w.startRow;f<=w.endRow;f++){m=a(p,f),v=g[m];var S=p>=b.startCol&&p<=b.endCol&&f>=b.startRow&&f<=b.endRow,C=p>=h.region.startCol&&p<=h.region.endCol&&f>=h.region.startRow&&f<=h.region.endRow;
2016-11-02 20:49:53 -04:00
!S&&C&&C&&v&&u(o,v,h),(h.region===b||S&&!C||r)&&(v||(v=l(g,m)),c(o,v,h))}h.region=b,x=!0}}}x&&(o.pairsList=d(o))},n.clear=function(e){e.buckets={},e.pairs={},e.pairsList=[]};var e=function(e,t){var n=Math.min(e.startCol,t.startCol),i=Math.max(e.endCol,t.endCol),r=Math.min(e.startRow,t.startRow),s=Math.max(e.endRow,t.endRow);return o(n,i,r,s)},t=function(e,t){var n=t.bounds,i=Math.floor(n.min.x/e.bucketWidth),r=Math.floor(n.max.x/e.bucketWidth),s=Math.floor(n.min.y/e.bucketHeight),a=Math.floor(n.max.y/e.bucketHeight);return o(i,r,s,a)},o=function(e,t,o,n){return{id:e+","+t+","+o+","+n,startCol:e,endCol:t,startRow:o,endRow:n}},a=function(e,t){return e+","+t},l=function(e,t){var o=e[t]=[];return o},c=function(e,t,o){for(var n=0;n<t.length;n++){var r=t[n];if(!(o.id===r.id||o.isStatic&&r.isStatic)){var s=i.id(o,r),a=e.pairs[s];a?a[2]+=1:e.pairs[s]=[o,r,1]}}t.push(o)},u=function(e,t,o){t.splice(s.indexOf(t,o),1);for(var n=0;n<t.length;n++){var r=t[n],a=i.id(o,r),l=e.pairs[a];l&&(l[2]-=1)}},d=function(e){
2016-04-07 15:03:37 -04:00
var t,o,n=[];t=s.keys(e.pairs);for(var i=0;i<t.length;i++)o=e.pairs[t[i]],o[2]>0?n.push(o):delete e.pairs[t[i]];return n}}()},{"../core/Common":14,"./Detector":5,"./Pair":7}],7:[function(e,t,o){var n={};t.exports=n;var i=e("./Contact");!function(){n.create=function(e,t){var o=e.bodyA,i=e.bodyB,r=e.parentA,s=e.parentB,a={id:n.id(o,i),bodyA:o,bodyB:i,contacts:{},activeContacts:[],separation:0,isActive:!0,isSensor:o.isSensor||i.isSensor,timeCreated:t,timeUpdated:t,inverseMass:r.inverseMass+s.inverseMass,friction:Math.min(r.friction,s.friction),frictionStatic:Math.max(r.frictionStatic,s.frictionStatic),restitution:Math.max(r.restitution,s.restitution),slop:Math.max(r.slop,s.slop)};return n.update(a,e,t),a},n.update=function(e,t,o){var r=e.contacts,s=t.supports,a=e.activeContacts,l=t.parentA,c=t.parentB;if(e.collision=t,e.inverseMass=l.inverseMass+c.inverseMass,e.friction=Math.min(l.friction,c.friction),e.frictionStatic=Math.max(l.frictionStatic,c.frictionStatic),e.restitution=Math.max(l.restitution,c.restitution),
2016-11-02 20:49:53 -04:00
e.slop=Math.max(l.slop,c.slop),a.length=0,t.collided){for(var u=0;u<s.length;u++){var d=s[u],p=i.id(d),f=r[p];f?a.push(f):a.push(r[p]=i.create(d))}e.separation=t.depth,n.setActive(e,!0,o)}else e.isActive===!0&&n.setActive(e,!1,o)},n.setActive=function(e,t,o){t?(e.isActive=!0,e.timeUpdated=o):(e.isActive=!1,e.activeContacts.length=0)},n.id=function(e,t){return e.id<t.id?e.id+"_"+t.id:t.id+"_"+e.id}}()},{"./Contact":4}],8:[function(e,t,o){var n={};t.exports=n;var i=e("./Pair"),r=e("../core/Common");!function(){var e=1e3;n.create=function(e){return r.extend({table:{},list:[],collisionStart:[],collisionActive:[],collisionEnd:[]},e)},n.update=function(e,t,o){var n,s,a,l,c=e.list,u=e.table,d=e.collisionStart,p=e.collisionEnd,f=e.collisionActive,v=[];for(d.length=0,p.length=0,f.length=0,l=0;l<t.length;l++)n=t[l],n.collided&&(s=i.id(n.bodyA,n.bodyB),v.push(s),a=u[s],a?(a.isActive?f.push(a):d.push(a),i.update(a,n,o)):(a=i.create(n,o),u[s]=a,d.push(a),c.push(a)));for(l=0;l<c.length;l++)a=c[l],a.isActive&&-1===r.indexOf(v,a.id)&&(i.setActive(a,!1,o),
p.push(a))},n.removeOld=function(t,o){var n,i,r,s,a=t.list,l=t.table,c=[];for(s=0;s<a.length;s++)n=a[s],i=n.collision,i.bodyA.isSleeping||i.bodyB.isSleeping?n.timeUpdated=o:o-n.timeUpdated>e&&c.push(s);for(s=0;s<c.length;s++)r=c[s]-s,n=a[r],delete l[n.id],a.splice(r,1)},n.clear=function(e){return e.table={},e.list.length=0,e.collisionStart.length=0,e.collisionActive.length=0,e.collisionEnd.length=0,e}}()},{"../core/Common":14,"./Pair":7}],9:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vector"),r=e("./SAT"),s=e("../geometry/Bounds"),a=e("../factory/Bodies"),l=e("../geometry/Vertices");!function(){n.ray=function(e,t,o,n){n=n||1e-100;for(var l=i.angle(t,o),c=i.magnitude(i.sub(t,o)),u=.5*(o.x+t.x),d=.5*(o.y+t.y),p=a.rectangle(u,d,c,n,{angle:l}),f=[],v=0;v<e.length;v++){var m=e[v];if(s.overlaps(m.bounds,p.bounds))for(var y=1===m.parts.length?0:1;y<m.parts.length;y++){var g=m.parts[y];if(s.overlaps(g.bounds,p.bounds)){var x=r.collides(g,p);if(x.collided){x.body=x.bodyA=x.bodyB=m,
2016-09-19 18:53:35 -04:00
f.push(x);break}}}}return f},n.region=function(e,t,o){for(var n=[],i=0;i<e.length;i++){var r=e[i],a=s.overlaps(r.bounds,t);(a&&!o||!a&&o)&&n.push(r)}return n},n.point=function(e,t){for(var o=[],n=0;n<e.length;n++){var i=e[n];if(s.contains(i.bounds,t))for(var r=1===i.parts.length?0:1;r<i.parts.length;r++){var a=i.parts[r];if(s.contains(a.bounds,t)&&l.contains(a.vertices,t)){o.push(i);break}}}return o}}()},{"../factory/Bodies":23,"../geometry/Bounds":26,"../geometry/Vector":28,"../geometry/Vertices":29,"./SAT":11}],10:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Common"),a=e("../geometry/Bounds");!function(){n._restingThresh=4,n._restingThreshTangent=6,n._positionDampen=.9,n._positionWarming=.8,n._frictionNormalMultiplier=5,n.preSolvePosition=function(e){var t,o,n;for(t=0;t<e.length;t++)o=e[t],o.isActive&&(n=o.activeContacts.length,o.collision.parentA.totalContacts+=n,o.collision.parentB.totalContacts+=n)},n.solvePosition=function(e,t){
2016-11-02 20:49:53 -04:00
var o,i,s,a,l,c,u,d,p,f=r._temp[0],v=r._temp[1],m=r._temp[2],y=r._temp[3];for(o=0;o<e.length;o++)i=e[o],i.isActive&&!i.isSensor&&(s=i.collision,a=s.parentA,l=s.parentB,c=s.normal,u=r.sub(r.add(l.positionImpulse,l.position,f),r.add(a.positionImpulse,r.sub(l.position,s.penetration,v),m),y),i.separation=r.dot(c,u));for(o=0;o<e.length;o++)i=e[o],!i.isActive||i.isSensor||i.separation<0||(s=i.collision,a=s.parentA,l=s.parentB,c=s.normal,p=(i.separation-i.slop)*t,(a.isStatic||l.isStatic)&&(p*=2),a.isStatic||a.isSleeping||(d=n._positionDampen/a.totalContacts,a.positionImpulse.x+=c.x*p*d,a.positionImpulse.y+=c.y*p*d),l.isStatic||l.isSleeping||(d=n._positionDampen/l.totalContacts,l.positionImpulse.x-=c.x*p*d,l.positionImpulse.y-=c.y*p*d))},n.postSolvePosition=function(e){for(var t=0;t<e.length;t++){var o=e[t];if(o.totalContacts=0,0!==o.positionImpulse.x||0!==o.positionImpulse.y){for(var s=0;s<o.parts.length;s++){var l=o.parts[s];i.translate(l.vertices,o.positionImpulse),a.update(l.bounds,l.vertices,o.velocity),
l.position.x+=o.positionImpulse.x,l.position.y+=o.positionImpulse.y}o.positionPrev.x+=o.positionImpulse.x,o.positionPrev.y+=o.positionImpulse.y,r.dot(o.positionImpulse,o.velocity)<0?(o.positionImpulse.x=0,o.positionImpulse.y=0):(o.positionImpulse.x*=n._positionWarming,o.positionImpulse.y*=n._positionWarming)}}},n.preSolveVelocity=function(e){var t,o,n,i,s,a,l,c,u,d,p,f,v,m,y=r._temp[0],g=r._temp[1];for(t=0;t<e.length;t++)if(n=e[t],n.isActive&&!n.isSensor)for(i=n.activeContacts,s=n.collision,a=s.parentA,l=s.parentB,c=s.normal,u=s.tangent,o=0;o<i.length;o++)d=i[o],p=d.vertex,f=d.normalImpulse,v=d.tangentImpulse,0===f&&0===v||(y.x=c.x*f+u.x*v,y.y=c.y*f+u.y*v,a.isStatic||a.isSleeping||(m=r.sub(p,a.position,g),a.positionPrev.x+=y.x*a.inverseMass,a.positionPrev.y+=y.y*a.inverseMass,a.anglePrev+=r.cross(m,y)*a.inverseInertia),l.isStatic||l.isSleeping||(m=r.sub(p,l.position,g),l.positionPrev.x-=y.x*l.inverseMass,l.positionPrev.y-=y.y*l.inverseMass,l.anglePrev-=r.cross(m,y)*l.inverseInertia))},n.solveVelocity=function(e,t){
for(var o=t*t,i=r._temp[0],a=r._temp[1],l=r._temp[2],c=r._temp[3],u=r._temp[4],d=r._temp[5],p=0;p<e.length;p++){var f=e[p];if(f.isActive&&!f.isSensor){var v=f.collision,m=v.parentA,y=v.parentB,g=v.normal,x=v.tangent,h=f.activeContacts,b=1/h.length;m.velocity.x=m.position.x-m.positionPrev.x,m.velocity.y=m.position.y-m.positionPrev.y,y.velocity.x=y.position.x-y.positionPrev.x,y.velocity.y=y.position.y-y.positionPrev.y,m.angularVelocity=m.angle-m.anglePrev,y.angularVelocity=y.angle-y.anglePrev;for(var w=0;w<h.length;w++){var S=h[w],C=S.vertex,A=r.sub(C,m.position,a),P=r.sub(C,y.position,l),B=r.add(m.velocity,r.mult(r.perp(A),m.angularVelocity),c),M=r.add(y.velocity,r.mult(r.perp(P),y.angularVelocity),u),k=r.sub(B,M,d),I=r.dot(g,k),T=r.dot(x,k),V=Math.abs(T),R=s.sign(T),_=(1+f.restitution)*I,E=s.clamp(f.separation+I,0,1)*n._frictionNormalMultiplier,F=T,L=1/0;V>f.friction*f.frictionStatic*E*o&&(L=V,F=s.clamp(f.friction*R*o,-L,L));var O=r.cross(A,g),q=r.cross(P,g),W=b/(m.inverseMass+y.inverseMass+m.inverseInertia*O*O+y.inverseInertia*q*q);
if(_*=W,F*=W,0>I&&I*I>n._restingThresh*o)S.normalImpulse=0;else{var N=S.normalImpulse;S.normalImpulse=Math.min(S.normalImpulse+_,0),_=S.normalImpulse-N}if(T*T>n._restingThreshTangent*o)S.tangentImpulse=0;else{var D=S.tangentImpulse;S.tangentImpulse=s.clamp(S.tangentImpulse+F,-L,L),F=S.tangentImpulse-D}i.x=g.x*_+x.x*F,i.y=g.y*_+x.y*F,m.isStatic||m.isSleeping||(m.positionPrev.x+=i.x*m.inverseMass,m.positionPrev.y+=i.y*m.inverseMass,m.anglePrev+=r.cross(A,i)*m.inverseInertia),y.isStatic||y.isSleeping||(y.positionPrev.x-=i.x*y.inverseMass,y.positionPrev.y-=i.y*y.inverseMass,y.anglePrev-=r.cross(P,i)*y.inverseInertia)}}}}}()},{"../core/Common":14,"../geometry/Bounds":26,"../geometry/Vector":28,"../geometry/Vertices":29}],11:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector");!function(){n.collides=function(t,n,s){var a,l,c,u,d=s,p=!1;if(d){var f=t.parent,v=n.parent,m=f.speed*f.speed+f.angularSpeed*f.angularSpeed+v.speed*v.speed+v.angularSpeed*v.angularSpeed;
p=d&&d.collided&&.2>m,u=d}else u={collided:!1,bodyA:t,bodyB:n};if(d&&p){var y=u.axisBody,g=y===t?n:t,x=[y.axes[d.axisNumber]];if(c=e(y.vertices,g.vertices,x),u.reused=!0,c.overlap<=0)return u.collided=!1,u}else{if(a=e(t.vertices,n.vertices,t.axes),a.overlap<=0)return u.collided=!1,u;if(l=e(n.vertices,t.vertices,n.axes),l.overlap<=0)return u.collided=!1,u;a.overlap<l.overlap?(c=a,u.axisBody=t):(c=l,u.axisBody=n),u.axisNumber=c.axisNumber}u.bodyA=t.id<n.id?t:n,u.bodyB=t.id<n.id?n:t,u.collided=!0,u.normal=c.axis,u.depth=c.overlap,u.parentA=u.bodyA.parent,u.parentB=u.bodyB.parent,t=u.bodyA,n=u.bodyB,r.dot(u.normal,r.sub(n.position,t.position))>0&&(u.normal=r.neg(u.normal)),u.tangent=r.perp(u.normal),u.penetration={x:u.normal.x*u.depth,y:u.normal.y*u.depth};var h=o(t,n,u.normal),b=u.supports||[];if(b.length=0,i.contains(t.vertices,h[0])&&b.push(h[0]),i.contains(t.vertices,h[1])&&b.push(h[1]),b.length<2){var w=o(n,t,r.neg(u.normal));i.contains(n.vertices,w[0])&&b.push(w[0]),b.length<2&&i.contains(n.vertices,w[1])&&b.push(w[1]);
}return b.length<1&&(b=[h[0]]),u.supports=b,u};var e=function(e,o,n){for(var i,s,a=r._temp[0],l=r._temp[1],c={overlap:Number.MAX_VALUE},u=0;u<n.length;u++){if(s=n[u],t(a,e,s),t(l,o,s),i=Math.min(a.max-l.min,l.max-a.min),0>=i)return c.overlap=i,c;i<c.overlap&&(c.overlap=i,c.axis=s,c.axisNumber=u)}return c},t=function(e,t,o){for(var n=r.dot(t[0],o),i=n,s=1;s<t.length;s+=1){var a=r.dot(t[s],o);a>i?i=a:n>a&&(n=a)}e.min=n,e.max=i},o=function(e,t,o){for(var n,i,s,a,l=Number.MAX_VALUE,c=r._temp[0],u=t.vertices,d=e.position,p=0;p<u.length;p++)i=u[p],c.x=i.x-d.x,c.y=i.y-d.y,n=-r.dot(o,c),l>n&&(l=n,s=i);var f=s.index-1>=0?s.index-1:u.length-1;i=u[f],c.x=i.x-d.x,c.y=i.y-d.y,l=-r.dot(o,c),a=i;var v=(s.index+1)%u.length;return i=u[v],c.x=i.x-d.x,c.y=i.y-d.y,n=-r.dot(o,c),l>n&&(a=i),[s,a]}}()},{"../geometry/Vector":28,"../geometry/Vertices":29}],12:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Sleeping"),a=e("../geometry/Bounds"),l=e("../geometry/Axes"),c=e("../core/Common");
!function(){var e=1e-6,t=.001;n.create=function(t){var o=t;o.bodyA&&!o.pointA&&(o.pointA={x:0,y:0}),o.bodyB&&!o.pointB&&(o.pointB={x:0,y:0});var n=o.bodyA?r.add(o.bodyA.position,o.pointA):o.pointA,i=o.bodyB?r.add(o.bodyB.position,o.pointB):o.pointB,s=r.magnitude(r.sub(n,i));o.length=o.length||s||e;var a={visible:!0,lineWidth:2,strokeStyle:"#666"};return o.render=c.extend(a,o.render),o.id=o.id||c.nextId(),o.label=o.label||"Constraint",o.type="constraint",o.stiffness=o.stiffness||1,o.angularStiffness=o.angularStiffness||0,o.angleA=o.bodyA?o.bodyA.angle:o.angleA,o.angleB=o.bodyB?o.bodyB.angle:o.angleB,o},n.solveAll=function(e,t){for(var o=0;o<e.length;o++)n.solve(e[o],t)},n.solve=function(o,n){var i=o.bodyA,s=o.bodyB,a=o.pointA,l=o.pointB;i&&!i.isStatic&&(o.pointA=r.rotate(a,i.angle-o.angleA),o.angleA=i.angle),s&&!s.isStatic&&(o.pointB=r.rotate(l,s.angle-o.angleB),o.angleB=s.angle);var c=a,u=l;if(i&&(c=r.add(i.position,a)),s&&(u=r.add(s.position,l)),c&&u){var d=r.sub(c,u),p=r.magnitude(d);0===p&&(p=e);
var f=(p-o.length)/p,v=r.div(d,p),m=r.mult(d,.5*f*o.stiffness*n*n);if(!(Math.abs(1-p/o.length)<t*n)){var y,g,x,h,b,w,S,C;i&&!i.isStatic?(x={x:c.x-i.position.x+m.x,y:c.y-i.position.y+m.y},i.velocity.x=i.position.x-i.positionPrev.x,i.velocity.y=i.position.y-i.positionPrev.y,i.angularVelocity=i.angle-i.anglePrev,y=r.add(i.velocity,r.mult(r.perp(x),i.angularVelocity)),b=r.dot(x,v),S=i.inverseMass+i.inverseInertia*b*b):(y={x:0,y:0},S=i?i.inverseMass:0),s&&!s.isStatic?(h={x:u.x-s.position.x-m.x,y:u.y-s.position.y-m.y},s.velocity.x=s.position.x-s.positionPrev.x,s.velocity.y=s.position.y-s.positionPrev.y,s.angularVelocity=s.angle-s.anglePrev,g=r.add(s.velocity,r.mult(r.perp(h),s.angularVelocity)),w=r.dot(h,v),C=s.inverseMass+s.inverseInertia*w*w):(g={x:0,y:0},C=s?s.inverseMass:0);var A=r.sub(g,y),P=r.dot(v,A)/(S+C);P>0&&(P=0);var B,M={x:v.x*P,y:v.y*P};i&&!i.isStatic&&(B=r.cross(x,M)*i.inverseInertia*(1-o.angularStiffness),i.constraintImpulse.x-=m.x,i.constraintImpulse.y-=m.y,i.constraintImpulse.angle+=B,
i.position.x-=m.x,i.position.y-=m.y,i.angle+=B),s&&!s.isStatic&&(B=r.cross(h,M)*s.inverseInertia*(1-o.angularStiffness),s.constraintImpulse.x+=m.x,s.constraintImpulse.y+=m.y,s.constraintImpulse.angle-=B,s.position.x+=m.x,s.position.y+=m.y,s.angle-=B)}}},n.postSolveAll=function(e){for(var t=0;t<e.length;t++){var o=e[t],n=o.constraintImpulse;if(0!==n.x||0!==n.y||0!==n.angle){s.set(o,!1);for(var c=0;c<o.parts.length;c++){var u=o.parts[c];i.translate(u.vertices,n),c>0&&(u.position.x+=n.x,u.position.y+=n.y),0!==n.angle&&(i.rotate(u.vertices,n.angle,o.position),l.rotate(u.axes,n.angle),c>0&&r.rotateAbout(u.position,n.angle,o.position,u.position)),a.update(u.bounds,u.vertices,o.velocity)}n.angle=0,n.x=0,n.y=0}}}}()},{"../core/Common":14,"../core/Sleeping":22,"../geometry/Axes":25,"../geometry/Bounds":26,"../geometry/Vector":28,"../geometry/Vertices":29}],13:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../core/Sleeping"),s=e("../core/Mouse"),a=e("../core/Events"),l=e("../collision/Detector"),c=e("./Constraint"),u=e("../body/Composite"),d=e("../core/Common"),p=e("../geometry/Bounds");
!function(){n.create=function(t,o){var i=(t?t.mouse:null)||(o?o.mouse:null);i||(t&&t.render&&t.render.canvas?i=s.create(t.render.canvas):o&&o.element?i=s.create(o.element):(i=s.create(),d.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected")));var r=c.create({label:"Mouse Constraint",pointA:i.position,pointB:{x:0,y:0},length:.01,stiffness:.1,angularStiffness:1,render:{strokeStyle:"#90EE90",lineWidth:3}}),l={type:"mouseConstraint",mouse:i,element:null,body:null,constraint:r,collisionFilter:{category:1,mask:4294967295,group:0}},p=d.extend(l,o);return a.on(t,"tick",function(){var o=u.allBodies(t.world);n.update(p,o),e(p)}),p},n.update=function(e,t){var o=e.mouse,n=e.constraint,s=e.body;if(0===o.button){if(n.bodyB)r.set(n.bodyB,!1),n.pointA=o.position;else for(var c=0;c<t.length;c++)if(s=t[c],p.contains(s.bounds,o.position)&&l.canCollide(s.collisionFilter,e.collisionFilter))for(var u=s.parts.length>1?1:0;u<s.parts.length;u++){
var d=s.parts[u];if(i.contains(d.vertices,o.position)){n.pointA=o.position,n.bodyB=e.body=s,n.pointB={x:o.position.x-s.position.x,y:o.position.y-s.position.y},n.angleB=s.angle,r.set(s,!1),a.trigger(e,"startdrag",{mouse:o,body:s});break}}}else n.bodyB=e.body=null,n.pointB=null,s&&a.trigger(e,"enddrag",{mouse:o,body:s})};var e=function(e){var t=e.mouse,o=t.sourceEvents;o.mousemove&&a.trigger(e,"mousemove",{mouse:t}),o.mousedown&&a.trigger(e,"mousedown",{mouse:t}),o.mouseup&&a.trigger(e,"mouseup",{mouse:t}),s.clearSourceEvents(t)}}()},{"../body/Composite":2,"../collision/Detector":5,"../core/Common":14,"../core/Events":16,"../core/Mouse":19,"../core/Sleeping":22,"../geometry/Bounds":26,"../geometry/Vertices":29,"./Constraint":12}],14:[function(e,t,o){var n={};t.exports=n,function(){n._nextId=0,n._seed=0,n.extend=function(e,t){var o,i,r;"boolean"==typeof t?(o=2,r=t):(o=1,r=!0),i=Array.prototype.slice.call(arguments,o);for(var s=0;s<i.length;s++){var a=i[s];if(a)for(var l in a)r&&a[l]&&a[l].constructor===Object?e[l]&&e[l].constructor!==Object?e[l]=a[l]:(e[l]=e[l]||{},
n.extend(e[l],r,a[l])):e[l]=a[l]}return e},n.clone=function(e,t){return n.extend({},t,e)},n.keys=function(e){if(Object.keys)return Object.keys(e);var t=[];for(var o in e)t.push(o);return t},n.values=function(e){var t=[];if(Object.keys){for(var o=Object.keys(e),n=0;n<o.length;n++)t.push(e[o[n]]);return t}for(var i in e)t.push(e[i]);return t},n.get=function(e,t,o,n){t=t.split(".").slice(o,n);for(var i=0;i<t.length;i+=1)e=e[t[i]];return e},n.set=function(e,t,o,i,r){var s=t.split(".").slice(i,r);return n.get(e,t,0,-1)[s[s.length-1]]=o,o},n.shadeColor=function(e,t){var o=parseInt(e.slice(1),16),n=Math.round(2.55*t),i=(o>>16)+n,r=(o>>8&255)+n,s=(255&o)+n;return"#"+(16777216+65536*(255>i?1>i?0:i:255)+256*(255>r?1>r?0:r:255)+(255>s?1>s?0:s:255)).toString(16).slice(1)},n.shuffle=function(e){for(var t=e.length-1;t>0;t--){var o=Math.floor(n.random()*(t+1)),i=e[t];e[t]=e[o],e[o]=i}return e},n.choose=function(e){return e[Math.floor(n.random()*e.length)]},n.isElement=function(e){try{return e instanceof HTMLElement;
}catch(t){return"object"==typeof e&&1===e.nodeType&&"object"==typeof e.style&&"object"==typeof e.ownerDocument}},n.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},n.isFunction=function(e){return"function"==typeof e},n.isPlainObject=function(e){return"object"==typeof e&&e.constructor===Object},n.isString=function(e){return"[object String]"===toString.call(e)},n.clamp=function(e,t,o){return t>e?t:e>o?o:e},n.sign=function(e){return 0>e?-1:1},n.now=function(){var e=window.performance||{};return e.now=function(){return e.now||e.webkitNow||e.msNow||e.oNow||e.mozNow||function(){return+new Date}}(),e.now()},n.random=function(t,o){return t="undefined"!=typeof t?t:0,o="undefined"!=typeof o?o:1,t+e()*(o-t)};var e=function(){return n._seed=(9301*n._seed+49297)%233280,n._seed/233280};n.colorToNumber=function(e){return e=e.replace("#",""),3==e.length&&(e=e.charAt(0)+e.charAt(0)+e.charAt(1)+e.charAt(1)+e.charAt(2)+e.charAt(2)),parseInt(e,16)},n.logLevel=1,n.log=function(){
console&&n.logLevel>0&&n.logLevel<=3&&console.log.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},n.info=function(){console&&n.logLevel>0&&n.logLevel<=2&&console.info.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},n.warn=function(){console&&n.logLevel>0&&n.logLevel<=3&&console.warn.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},n.nextId=function(){return n._nextId++},n.indexOf=function(e,t){if(e.indexOf)return e.indexOf(t);for(var o=0;o<e.length;o++)if(e[o]===t)return o;return-1},n.map=function(e,t){if(e.map)return e.map(t);for(var o=[],n=0;n<e.length;n+=1)o.push(t(e[n]));return o},n.topologicalSort=function(e){var o=[],n=[],i=[];for(var r in e)n[r]||i[r]||t(r,n,i,e,o);return o};var t=function(e,o,n,i,r){var s=i[e]||[];n[e]=!0;for(var a=0;a<s.length;a+=1){var l=s[a];n[l]||o[l]||t(l,o,n,i,r)}n[e]=!1,o[e]=!0,r.push(e)};n.chain=function(){for(var e=Array.prototype.slice.call(arguments),t=[],o=0;o<e.length;o+=1){
var n=e[o];n._chained?t.push.apply(t,n._chained):t.push(n)}var i=function(){for(var e,o=0;o<t.length;o+=1){var n=t[o].apply(e,arguments);"undefined"!=typeof n&&(e=n)}return e};return i._chained=t,i},n.chainPathBefore=function(e,t,o){return n.set(e,t,n.chain(o,n.get(e,t)))},n.chainPathAfter=function(e,t,o){return n.set(e,t,n.chain(n.get(e,t),o))}}()},{}],15:[function(e,t,o){var n={};t.exports=n;var i=e("../body/World"),r=e("./Sleeping"),s=e("../collision/Resolver"),a=e("../render/Render"),l=e("../collision/Pairs"),c=(e("./Metrics"),e("../collision/Grid")),u=e("./Events"),d=e("../body/Composite"),p=e("../constraint/Constraint"),f=e("./Common"),v=e("../body/Body");!function(){n.create=function(e,t){t=f.isElement(e)?t:e,e=f.isElement(e)?e:null,t=t||{},(e||t.render)&&f.warn("Engine.create: engine.render is deprecated (see docs)");var o={positionIterations:6,velocityIterations:4,constraintIterations:2,enableSleeping:!1,events:[],timing:{timestamp:0,timeScale:1},broadphase:{controller:c}},n=f.extend(o,t);
if(e||n.render){var r={element:e,controller:a};n.render=f.extend(r,n.render)}return n.render&&n.render.controller&&(n.render=n.render.controller.create(n.render)),n.render&&(n.render.engine=n),n.world=t.world||i.create(n.world),n.pairs=l.create(),n.broadphase=n.broadphase.controller.create(n.broadphase),n.metrics=n.metrics||{extended:!1},n},n.update=function(n,i,a){i=i||1e3/60,a=a||1;var c,f=n.world,v=n.timing,m=n.broadphase,y=[];v.timestamp+=i*v.timeScale;var g={timestamp:v.timestamp};u.trigger(n,"beforeUpdate",g);var x=d.allBodies(f),h=d.allConstraints(f);for(n.enableSleeping&&r.update(x,v.timeScale),t(x,f.gravity),o(x,i,v.timeScale,a,f.bounds),c=0;c<n.constraintIterations;c++)p.solveAll(h,v.timeScale);p.postSolveAll(x),m.controller?(f.isModified&&m.controller.clear(m),m.controller.update(m,x,n,f.isModified),y=m.pairsList):y=x,f.isModified&&d.setModified(f,!1,!1,!0);var b=m.detector(y,n),w=n.pairs,S=v.timestamp;for(l.update(w,b,S),l.removeOld(w,S),n.enableSleeping&&r.afterCollisions(w.list,v.timeScale),
w.collisionStart.length>0&&u.trigger(n,"collisionStart",{pairs:w.collisionStart}),s.preSolvePosition(w.list),c=0;c<n.positionIterations;c++)s.solvePosition(w.list,v.timeScale);for(s.postSolvePosition(x),s.preSolveVelocity(w.list),c=0;c<n.velocityIterations;c++)s.solveVelocity(w.list,v.timeScale);return w.collisionActive.length>0&&u.trigger(n,"collisionActive",{pairs:w.collisionActive}),w.collisionEnd.length>0&&u.trigger(n,"collisionEnd",{pairs:w.collisionEnd}),e(x),u.trigger(n,"afterUpdate",g),n},n.merge=function(e,t){if(f.extend(e,t),t.world){e.world=t.world,n.clear(e);for(var o=d.allBodies(e.world),i=0;i<o.length;i++){var s=o[i];r.set(s,!1),s.id=f.nextId()}}},n.clear=function(e){var t=e.world;l.clear(e.pairs);var o=e.broadphase;if(o.controller){var n=d.allBodies(t);o.controller.clear(o),o.controller.update(o,n,e,!0)}};var e=function(e){for(var t=0;t<e.length;t++){var o=e[t];o.force.x=0,o.force.y=0,o.torque=0}},t=function(e,t){var o="undefined"!=typeof t.scale?t.scale:.001;if((0!==t.x||0!==t.y)&&0!==o)for(var n=0;n<e.length;n++){
var i=e[n];i.isStatic||i.isSleeping||(i.force.y+=i.mass*t.y*o,i.force.x+=i.mass*t.x*o)}},o=function(e,t,o,n,i){for(var r=0;r<e.length;r++){var s=e[r];s.isStatic||s.isSleeping||v.update(s,t,o,n)}}}()},{"../body/Body":1,"../body/Composite":2,"../body/World":3,"../collision/Grid":6,"../collision/Pairs":8,"../collision/Resolver":10,"../constraint/Constraint":12,"../render/Render":31,"./Common":14,"./Events":16,"./Metrics":18,"./Sleeping":22}],16:[function(e,t,o){var n={};t.exports=n;var i=e("./Common");!function(){n.on=function(e,t,o){for(var n,i=t.split(" "),r=0;r<i.length;r++)n=i[r],e.events=e.events||{},e.events[n]=e.events[n]||[],e.events[n].push(o);return o},n.off=function(e,t,o){if(!t)return void(e.events={});"function"==typeof t&&(o=t,t=i.keys(e.events).join(" "));for(var n=t.split(" "),r=0;r<n.length;r++){var s=e.events[n[r]],a=[];if(o&&s)for(var l=0;l<s.length;l++)s[l]!==o&&a.push(s[l]);e.events[n[r]]=a}},n.trigger=function(e,t,o){var n,r,s,a;if(e.events){o||(o={}),n=t.split(" ");for(var l=0;l<n.length;l++)if(r=n[l],
2016-11-09 15:46:45 -05:00
s=e.events[r]){a=i.clone(o,!1),a.name=r,a.source=e;for(var c=0;c<s.length;c++)s[c].apply(e,[a])}}}}()},{"./Common":14}],17:[function(e,t,o){var n={};t.exports=n;var i=e("./Plugin"),r=e("./Common");!function(){n.name="matter-js",n.version="0.11.1",n.uses=[],n.used=[],n.use=function(){i.use(n,Array.prototype.slice.call(arguments))},n.before=function(e,t){return e=e.replace(/^Matter./,""),r.chainPathBefore(n,e,t)},n.after=function(e,t){return e=e.replace(/^Matter./,""),r.chainPathAfter(n,e,t)}}()},{"./Common":14,"./Plugin":20}],18:[function(e,t,o){},{"../body/Composite":2,"./Common":14}],19:[function(e,t,o){var n={};t.exports=n;var i=e("../core/Common");!function(){n.create=function(t){var o={};return t||i.log("Mouse.create: element was undefined, defaulting to document.body","warn"),o.element=t||document.body,o.absolute={x:0,y:0},o.position={x:0,y:0},o.mousedownPosition={x:0,y:0},o.mouseupPosition={x:0,y:0},o.offset={x:0,y:0},o.scale={x:1,y:1},o.wheelDelta=0,o.button=-1,o.pixelRatio=o.element.getAttribute("data-pixel-ratio")||1,
2016-11-02 20:49:53 -04:00
o.sourceEvents={mousemove:null,mousedown:null,mouseup:null,mousewheel:null},o.mousemove=function(t){var n=e(t,o.element,o.pixelRatio),i=t.changedTouches;i&&(o.button=0,t.preventDefault()),o.absolute.x=n.x,o.absolute.y=n.y,o.position.x=o.absolute.x*o.scale.x+o.offset.x,o.position.y=o.absolute.y*o.scale.y+o.offset.y,o.sourceEvents.mousemove=t},o.mousedown=function(t){var n=e(t,o.element,o.pixelRatio),i=t.changedTouches;i?(o.button=0,t.preventDefault()):o.button=t.button,o.absolute.x=n.x,o.absolute.y=n.y,o.position.x=o.absolute.x*o.scale.x+o.offset.x,o.position.y=o.absolute.y*o.scale.y+o.offset.y,o.mousedownPosition.x=o.position.x,o.mousedownPosition.y=o.position.y,o.sourceEvents.mousedown=t},o.mouseup=function(t){var n=e(t,o.element,o.pixelRatio),i=t.changedTouches;i&&t.preventDefault(),o.button=-1,o.absolute.x=n.x,o.absolute.y=n.y,o.position.x=o.absolute.x*o.scale.x+o.offset.x,o.position.y=o.absolute.y*o.scale.y+o.offset.y,o.mouseupPosition.x=o.position.x,o.mouseupPosition.y=o.position.y,
o.sourceEvents.mouseup=t},o.mousewheel=function(e){o.wheelDelta=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail)),e.preventDefault()},n.setElement(o,o.element),o},n.setElement=function(e,t){e.element=t,t.addEventListener("mousemove",e.mousemove),t.addEventListener("mousedown",e.mousedown),t.addEventListener("mouseup",e.mouseup),t.addEventListener("mousewheel",e.mousewheel),t.addEventListener("DOMMouseScroll",e.mousewheel),t.addEventListener("touchmove",e.mousemove),t.addEventListener("touchstart",e.mousedown),t.addEventListener("touchend",e.mouseup)},n.clearSourceEvents=function(e){e.sourceEvents.mousemove=null,e.sourceEvents.mousedown=null,e.sourceEvents.mouseup=null,e.sourceEvents.mousewheel=null,e.wheelDelta=0},n.setOffset=function(e,t){e.offset.x=t.x,e.offset.y=t.y,e.position.x=e.absolute.x*e.scale.x+e.offset.x,e.position.y=e.absolute.y*e.scale.y+e.offset.y},n.setScale=function(e,t){e.scale.x=t.x,e.scale.y=t.y,e.position.x=e.absolute.x*e.scale.x+e.offset.x,e.position.y=e.absolute.y*e.scale.y+e.offset.y;
};var e=function(e,t,o){var n,i,r=t.getBoundingClientRect(),s=document.documentElement||document.body.parentNode||document.body,a=void 0!==window.pageXOffset?window.pageXOffset:s.scrollLeft,l=void 0!==window.pageYOffset?window.pageYOffset:s.scrollTop,c=e.changedTouches;return c?(n=c[0].pageX-r.left-a,i=c[0].pageY-r.top-l):(n=e.pageX-r.left-a,i=e.pageY-r.top-l),{x:n/(t.clientWidth/(t.width||t.clientWidth)*o),y:i/(t.clientHeight/(t.height||t.clientHeight)*o)}}}()},{"../core/Common":14}],20:[function(e,t,o){var n={};t.exports=n;var i=e("./Common");!function(){n._registry={},n.register=function(e){if(n.isPlugin(e)||i.warn("Plugin.register:",n.toString(e),"does not implement all required fields."),e.name in n._registry){var t=n._registry[e.name],o=n.versionParse(e.version).number,r=n.versionParse(t.version).number;o>r?(i.warn("Plugin.register:",n.toString(t),"was upgraded to",n.toString(e)),n._registry[e.name]=e):r>o?i.warn("Plugin.register:",n.toString(t),"can not be downgraded to",n.toString(e)):e!==t&&i.warn("Plugin.register:",n.toString(e),"is already registered to different plugin object");
}else n._registry[e.name]=e;return e},n.resolve=function(e){return n._registry[n.dependencyParse(e).name]},n.toString=function(e){return"string"==typeof e?e:(e.name||"anonymous")+"@"+(e.version||e.range||"0.0.0")},n.isPlugin=function(e){return e&&e.name&&e.version&&e.install},n.isUsed=function(e,t){return e.used.indexOf(t)>-1},n.isFor=function(e,t){var o=e["for"]&&n.dependencyParse(e["for"]);return!e["for"]||t.name===o.name&&n.versionSatisfies(t.version,o.range)},n.use=function(e,t){if(e.uses=(e.uses||[]).concat(t||[]),0===e.uses.length)return void i.warn("Plugin.use:",n.toString(e),"does not specify any dependencies to install.");for(var o=n.dependencies(e),r=i.topologicalSort(o),s=[],a=0;a<r.length;a+=1)if(r[a]!==e.name){var l=n.resolve(r[a]);l?n.isUsed(e,l.name)||(n.isFor(l,e)||(i.warn("Plugin.use:",n.toString(l),"is for",l["for"],"but installed on",n.toString(e)+"."),l._warned=!0),l.install?l.install(e):(i.warn("Plugin.use:",n.toString(l),"does not specify an install function."),l._warned=!0),
l._warned?(s.push("🔶 "+n.toString(l)),delete l._warned):s.push("✅ "+n.toString(l)),e.used.push(l.name)):s.push("❌ "+r[a])}s.length>0&&i.info(s.join(" "))},n.dependencies=function(e,t){var o=n.dependencyParse(e),r=o.name;if(t=t||{},!(r in t)){e=n.resolve(e)||e,t[r]=i.map(e.uses||[],function(t){n.isPlugin(t)&&n.register(t);var r=n.dependencyParse(t),s=n.resolve(t);return s&&!n.versionSatisfies(s.version,r.range)?(i.warn("Plugin.dependencies:",n.toString(s),"does not satisfy",n.toString(r),"used by",n.toString(o)+"."),s._warned=!0,e._warned=!0):s||(i.warn("Plugin.dependencies:",n.toString(t),"used by",n.toString(o),"could not be resolved."),e._warned=!0),r.name});for(var s=0;s<t[r].length;s+=1)n.dependencies(t[r][s],t);return t}},n.dependencyParse=function(e){if(i.isString(e)){var t=/^[\w-]+(@(\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-]+)?))?$/;return t.test(e)||i.warn("Plugin.dependencyParse:",e,"is not a valid dependency string."),{name:e.split("@")[0],range:e.split("@")[1]||"*"}}return{name:e.name,
range:e.range||e.version}},n.versionParse=function(e){var t=/^\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-]+)?$/;t.test(e)||i.warn("Plugin.versionParse:",e,"is not a valid version or range.");var o=e.split("-");e=o[0];var n=isNaN(Number(e[0])),r=n?e.substr(1):e,s=i.map(r.split("."),function(e){return Number(e)});return{isRange:n,version:r,range:e,operator:n?e[0]:"",parts:s,prerelease:o[1],number:1e8*s[0]+1e4*s[1]+s[2]}},n.versionSatisfies=function(e,t){t=t||"*";var o=n.versionParse(t),i=o.parts,r=n.versionParse(e),s=r.parts;if(o.isRange){if("*"===o.operator||"*"===e)return!0;if("~"===o.operator)return s[0]===i[0]&&s[1]===i[1]&&s[2]>=i[2];if("^"===o.operator)return i[0]>0?s[0]===i[0]&&r.number>=o.number:i[1]>0?s[1]===i[1]&&s[2]>=i[2]:s[2]===i[2]}return e===t||"*"===e}}()},{"./Common":14}],21:[function(e,t,o){var n={};t.exports=n;var i=e("./Events"),r=e("./Engine"),s=e("./Common");!function(){var e,t;if("undefined"!=typeof window&&(e=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame,
t=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame),!e){var o;e=function(e){o=setTimeout(function(){e(s.now())},1e3/60)},t=function(){clearTimeout(o)}}n.create=function(e){var t={fps:60,correction:1,deltaSampleSize:60,counterTimestamp:0,frameCounter:0,deltaHistory:[],timePrev:null,timeScalePrev:1,frameRequestId:null,isFixed:!1,enabled:!0},o=s.extend(t,e);return o.delta=o.delta||1e3/o.fps,o.deltaMin=o.deltaMin||1e3/o.fps,o.deltaMax=o.deltaMax||1e3/(.5*o.fps),o.fps=1e3/o.delta,o},n.run=function(t,o){return"undefined"!=typeof t.positionIterations&&(o=t,t=n.create()),function i(r){t.frameRequestId=e(i),r&&t.enabled&&n.tick(t,o,r)}(),t},n.tick=function(e,t,o){var n,s=t.timing,a=1,l={timestamp:s.timestamp};i.trigger(e,"beforeTick",l),i.trigger(t,"beforeTick",l),e.isFixed?n=e.delta:(n=o-e.timePrev||e.delta,e.timePrev=o,e.deltaHistory.push(n),e.deltaHistory=e.deltaHistory.slice(-e.deltaSampleSize),n=Math.min.apply(null,e.deltaHistory),
n=n<e.deltaMin?e.deltaMin:n,n=n>e.deltaMax?e.deltaMax:n,a=n/e.delta,e.delta=n),0!==e.timeScalePrev&&(a*=s.timeScale/e.timeScalePrev),0===s.timeScale&&(a=0),e.timeScalePrev=s.timeScale,e.correction=a,e.frameCounter+=1,o-e.counterTimestamp>=1e3&&(e.fps=e.frameCounter*((o-e.counterTimestamp)/1e3),e.counterTimestamp=o,e.frameCounter=0),i.trigger(e,"tick",l),i.trigger(t,"tick",l),t.world.isModified&&t.render&&t.render.controller&&t.render.controller.clear&&t.render.controller.clear(t.render),i.trigger(e,"beforeUpdate",l),r.update(t,n,a),i.trigger(e,"afterUpdate",l),t.render&&t.render.controller&&(i.trigger(e,"beforeRender",l),i.trigger(t,"beforeRender",l),t.render.controller.world(t.render),i.trigger(e,"afterRender",l),i.trigger(t,"afterRender",l)),i.trigger(e,"afterTick",l),i.trigger(t,"afterTick",l)},n.stop=function(e){t(e.frameRequestId)},n.start=function(e,t){n.run(e,t)}}()},{"./Common":14,"./Engine":15,"./Events":16}],22:[function(e,t,o){var n={};t.exports=n;var i=e("./Events");!function(){
n._motionWakeThreshold=.18,n._motionSleepThreshold=.08,n._minBias=.9,n.update=function(e,t){for(var o=t*t*t,i=0;i<e.length;i++){var r=e[i],s=r.speed*r.speed+r.angularSpeed*r.angularSpeed;if(0===r.force.x&&0===r.force.y){var a=Math.min(r.motion,s),l=Math.max(r.motion,s);r.motion=n._minBias*a+(1-n._minBias)*l,r.sleepThreshold>0&&r.motion<n._motionSleepThreshold*o?(r.sleepCounter+=1,r.sleepCounter>=r.sleepThreshold&&n.set(r,!0)):r.sleepCounter>0&&(r.sleepCounter-=1)}else n.set(r,!1)}},n.afterCollisions=function(e,t){for(var o=t*t*t,i=0;i<e.length;i++){var r=e[i];if(r.isActive){var s=r.collision,a=s.bodyA.parent,l=s.bodyB.parent;if(!(a.isSleeping&&l.isSleeping||a.isStatic||l.isStatic)&&(a.isSleeping||l.isSleeping)){var c=a.isSleeping&&!a.isStatic?a:l,u=c===a?l:a;!c.isStatic&&u.motion>n._motionWakeThreshold*o&&n.set(c,!1)}}}},n.set=function(e,t){var o=e.isSleeping;t?(e.isSleeping=!0,e.sleepCounter=e.sleepThreshold,e.positionImpulse.x=0,e.positionImpulse.y=0,e.positionPrev.x=e.position.x,e.positionPrev.y=e.position.y,
e.anglePrev=e.angle,e.speed=0,e.angularSpeed=0,e.motion=0,o||i.trigger(e,"sleepStart")):(e.isSleeping=!1,e.sleepCounter=0,o&&i.trigger(e,"sleepEnd"))}}()},{"./Events":16}],23:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vertices"),r=e("../core/Common"),s=e("../body/Body"),a=e("../geometry/Bounds"),l=e("../geometry/Vector");!function(){n.rectangle=function(e,t,o,n,a){a=a||{};var l={label:"Rectangle Body",position:{x:e,y:t},vertices:i.fromPath("L 0 0 L "+o+" 0 L "+o+" "+n+" L 0 "+n)};if(a.chamfer){var c=a.chamfer;l.vertices=i.chamfer(l.vertices,c.radius,c.quality,c.qualityMin,c.qualityMax),delete a.chamfer}return s.create(r.extend({},l,a))},n.trapezoid=function(e,t,o,n,a,l){l=l||{},a*=.5;var c,u=(1-2*a)*o,d=o*a,p=d+u,f=p+d;c=.5>a?"L 0 0 L "+d+" "+-n+" L "+p+" "+-n+" L "+f+" 0":"L 0 0 L "+p+" "+-n+" L "+f+" 0";var v={label:"Trapezoid Body",position:{x:e,y:t},vertices:i.fromPath(c)};if(l.chamfer){var m=l.chamfer;v.vertices=i.chamfer(v.vertices,m.radius,m.quality,m.qualityMin,m.qualityMax),
delete l.chamfer}return s.create(r.extend({},v,l))},n.circle=function(e,t,o,i,s){i=i||{};var a={label:"Circle Body",circleRadius:o};s=s||25;var l=Math.ceil(Math.max(10,Math.min(s,o)));return l%2===1&&(l+=1),n.polygon(e,t,l,o,r.extend({},a,i))},n.polygon=function(e,t,o,a,l){if(l=l||{},3>o)return n.circle(e,t,a,l);for(var c=2*Math.PI/o,u="",d=.5*c,p=0;o>p;p+=1){var f=d+p*c,v=Math.cos(f)*a,m=Math.sin(f)*a;u+="L "+v.toFixed(3)+" "+m.toFixed(3)+" "}var y={label:"Polygon Body",position:{x:e,y:t},vertices:i.fromPath(u)};if(l.chamfer){var g=l.chamfer;y.vertices=i.chamfer(y.vertices,g.radius,g.quality,g.qualityMin,g.qualityMax),delete l.chamfer}return s.create(r.extend({},y,l))},n.fromVertices=function(e,t,o,n,c,u,d){var p,f,v,m,y,g,x,h,b;for(n=n||{},f=[],c="undefined"!=typeof c?c:!1,u="undefined"!=typeof u?u:.01,d="undefined"!=typeof d?d:10,window.decomp||r.warn("Bodies.fromVertices: poly-decomp.js required. Could not decompose vertices. Fallback to convex hull."),r.isArray(o[0])||(o=[o]),h=0;h<o.length;h+=1)if(m=o[h],
v=i.isConvex(m),v||!window.decomp)m=v?i.clockwiseSort(m):i.hull(m),f.push({position:{x:e,y:t},vertices:m});else{var w=new decomp.Polygon;for(y=0;y<m.length;y++)w.vertices.push([m[y].x,m[y].y]);w.makeCCW(),u!==!1&&w.removeCollinearPoints(u);var S=w.quickDecomp();for(y=0;y<S.length;y++){var C=S[y],A=[];for(g=0;g<C.vertices.length;g++)A.push({x:C.vertices[g][0],y:C.vertices[g][1]});d>0&&i.area(A)<d||f.push({position:i.centre(A),vertices:A})}}for(y=0;y<f.length;y++)f[y]=s.create(r.extend(f[y],n));if(c){var P=5;for(y=0;y<f.length;y++){var B=f[y];for(g=y+1;g<f.length;g++){var M=f[g];if(a.overlaps(B.bounds,M.bounds)){var k=B.vertices,I=M.vertices;for(x=0;x<B.vertices.length;x++)for(b=0;b<M.vertices.length;b++){var T=l.magnitudeSquared(l.sub(k[(x+1)%k.length],I[b])),V=l.magnitudeSquared(l.sub(k[x],I[(b+1)%I.length]));P>T&&P>V&&(k[x].isInternal=!0,I[b].isInternal=!0)}}}}}return f.length>1?(p=s.create(r.extend({parts:f.slice(0)},n)),s.setPosition(p,{x:e,y:t}),p):f[0]}}()},{"../body/Body":1,"../core/Common":14,
"../geometry/Bounds":26,"../geometry/Vector":28,"../geometry/Vertices":29}],24:[function(e,t,o){var n={};t.exports=n;var i=e("../body/Composite"),r=e("../constraint/Constraint"),s=e("../core/Common"),a=e("../body/Body"),l=e("./Bodies");!function(){n.stack=function(e,t,o,n,r,s,l){for(var c,u=i.create({label:"Stack"}),d=e,p=t,f=0,v=0;n>v;v++){for(var m=0,y=0;o>y;y++){var g=l(d,p,y,v,c,f);if(g){var x=g.bounds.max.y-g.bounds.min.y,h=g.bounds.max.x-g.bounds.min.x;x>m&&(m=x),a.translate(g,{x:.5*h,y:.5*x}),d=g.bounds.max.x+r,i.addBody(u,g),c=g,f+=1}else d+=r}p+=m+s,d=e}return u},n.chain=function(e,t,o,n,a,l){for(var c=e.bodies,u=1;u<c.length;u++){var d=c[u-1],p=c[u],f=d.bounds.max.y-d.bounds.min.y,v=d.bounds.max.x-d.bounds.min.x,m=p.bounds.max.y-p.bounds.min.y,y=p.bounds.max.x-p.bounds.min.x,g={bodyA:d,pointA:{x:v*t,y:f*o},bodyB:p,pointB:{x:y*n,y:m*a}},x=s.extend(g,l);i.addConstraint(e,r.create(x))}return e.label+=" Chain",e},n.mesh=function(e,t,o,n,a){var l,c,u,d,p,f=e.bodies;for(l=0;o>l;l++){
for(c=1;t>c;c++)u=f[c-1+l*t],d=f[c+l*t],i.addConstraint(e,r.create(s.extend({bodyA:u,bodyB:d},a)));if(l>0)for(c=0;t>c;c++)u=f[c+(l-1)*t],d=f[c+l*t],i.addConstraint(e,r.create(s.extend({bodyA:u,bodyB:d},a))),n&&c>0&&(p=f[c-1+(l-1)*t],i.addConstraint(e,r.create(s.extend({bodyA:p,bodyB:d},a)))),n&&t-1>c&&(p=f[c+1+(l-1)*t],i.addConstraint(e,r.create(s.extend({bodyA:p,bodyB:d},a))))}return e.label+=" Mesh",e},n.pyramid=function(e,t,o,i,r,s,l){return n.stack(e,t,o,i,r,s,function(t,n,s,c,u,d){var p=Math.min(i,Math.ceil(o/2)),f=u?u.bounds.max.x-u.bounds.min.x:0;if(!(c>p)){c=p-c;var v=c,m=o-1-c;if(!(v>s||s>m)){1===d&&a.translate(u,{x:(s+(o%2===1?1:-1))*f,y:0});var y=u?s*f:0;return l(e+y+s*r,n,s,c,u,d)}}})},n.newtonsCradle=function(e,t,o,n,s){for(var a=i.create({label:"Newtons Cradle"}),c=0;o>c;c++){var u=1.9,d=l.circle(e+c*(n*u),t+s,n,{inertia:1/0,restitution:1,friction:0,frictionAir:1e-4,slop:1}),p=r.create({pointA:{x:e+c*(n*u),y:t},bodyB:d});i.addBody(a,d),i.addConstraint(a,p)}return a},n.car=function(e,t,o,n,s){
var c=a.nextGroup(!0),u=-20,d=.5*-o+u,p=.5*o-u,f=0,v=i.create({label:"Car"}),m=l.trapezoid(e,t,o,n,.3,{collisionFilter:{group:c},friction:.01,chamfer:{radius:10}}),y=l.circle(e+d,t+f,s,{collisionFilter:{group:c},friction:.8,density:.01}),g=l.circle(e+p,t+f,s,{collisionFilter:{group:c},friction:.8,density:.01}),x=r.create({bodyA:m,pointA:{x:d,y:f},bodyB:y,stiffness:.2}),h=r.create({bodyA:m,pointA:{x:p,y:f},bodyB:g,stiffness:.2});return i.addBody(v,m),i.addBody(v,y),i.addBody(v,g),i.addConstraint(v,x),i.addConstraint(v,h),v},n.softBody=function(e,t,o,i,r,a,c,u,d,p){d=s.extend({inertia:1/0},d),p=s.extend({stiffness:.4},p);var f=n.stack(e,t,o,i,r,a,function(e,t){return l.circle(e,t,u,d)});return n.mesh(f,o,i,c,p),f.label="Soft Body",f}}()},{"../body/Body":1,"../body/Composite":2,"../constraint/Constraint":12,"../core/Common":14,"./Bodies":23}],25:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vector"),r=e("../core/Common");!function(){n.fromVertices=function(e){for(var t={},o=0;o<e.length;o++){
var n=(o+1)%e.length,s=i.normalise({x:e[n].y-e[o].y,y:e[o].x-e[n].x}),a=0===s.y?1/0:s.x/s.y;a=a.toFixed(3).toString(),t[a]=s}return r.values(t)},n.rotate=function(e,t){if(0!==t)for(var o=Math.cos(t),n=Math.sin(t),i=0;i<e.length;i++){var r,s=e[i];r=s.x*o-s.y*n,s.y=s.x*n+s.y*o,s.x=r}}}()},{"../core/Common":14,"../geometry/Vector":28}],26:[function(e,t,o){var n={};t.exports=n,function(){n.create=function(e){var t={min:{x:0,y:0},max:{x:0,y:0}};return e&&n.update(t,e),t},n.update=function(e,t,o){e.min.x=1/0,e.max.x=-(1/0),e.min.y=1/0,e.max.y=-(1/0);for(var n=0;n<t.length;n++){var i=t[n];i.x>e.max.x&&(e.max.x=i.x),i.x<e.min.x&&(e.min.x=i.x),i.y>e.max.y&&(e.max.y=i.y),i.y<e.min.y&&(e.min.y=i.y)}o&&(o.x>0?e.max.x+=o.x:e.min.x+=o.x,o.y>0?e.max.y+=o.y:e.min.y+=o.y)},n.contains=function(e,t){return t.x>=e.min.x&&t.x<=e.max.x&&t.y>=e.min.y&&t.y<=e.max.y},n.overlaps=function(e,t){return e.min.x<=t.max.x&&e.max.x>=t.min.x&&e.max.y>=t.min.y&&e.min.y<=t.max.y},n.translate=function(e,t){e.min.x+=t.x,e.max.x+=t.x,
e.min.y+=t.y,e.max.y+=t.y},n.shift=function(e,t){var o=e.max.x-e.min.x,n=e.max.y-e.min.y;e.min.x=t.x,e.max.x=t.x+o,e.min.y=t.y,e.max.y=t.y+n}}()},{}],27:[function(e,t,o){var n={};t.exports=n;e("../geometry/Bounds");!function(){n.pathToVertices=function(t,o){var n,i,r,s,a,l,c,u,d,p,f,v,m=[],y=0,g=0,x=0;o=o||15;var h=function(e,t,o){var n=o%2===1&&o>1;if(!d||e!=d.x||t!=d.y){d&&n?(f=d.x,v=d.y):(f=0,v=0);var i={x:f+e,y:v+t};!n&&d||(d=i),m.push(i),g=f+e,x=v+t}},b=function(e){var t=e.pathSegTypeAsLetter.toUpperCase();if("Z"!==t){switch(t){case"M":case"L":case"T":case"C":case"S":case"Q":g=e.x,x=e.y;break;case"H":g=e.x;break;case"V":x=e.y}h(g,x,e.pathSegType)}};for(e(t),r=t.getTotalLength(),l=[],n=0;n<t.pathSegList.numberOfItems;n+=1)l.push(t.pathSegList.getItem(n));for(c=l.concat();r>y;){if(p=t.getPathSegAtLength(y),a=l[p],a!=u){for(;c.length&&c[0]!=a;)b(c.shift());u=a}switch(a.pathSegTypeAsLetter.toUpperCase()){case"C":case"T":case"S":case"Q":case"A":s=t.getPointAtLength(y),h(s.x,s.y,0)}y+=o}
for(n=0,i=c.length;i>n;++n)b(c[n]);return m};var e=function(e){for(var t,o,n,i,r,s,a=e.pathSegList,l=0,c=0,u=a.numberOfItems,d=0;u>d;++d){var p=a.getItem(d),f=p.pathSegTypeAsLetter;if(/[MLHVCSQTA]/.test(f))"x"in p&&(l=p.x),"y"in p&&(c=p.y);else switch("x1"in p&&(n=l+p.x1),"x2"in p&&(r=l+p.x2),"y1"in p&&(i=c+p.y1),"y2"in p&&(s=c+p.y2),"x"in p&&(l+=p.x),"y"in p&&(c+=p.y),f){case"m":a.replaceItem(e.createSVGPathSegMovetoAbs(l,c),d);break;case"l":a.replaceItem(e.createSVGPathSegLinetoAbs(l,c),d);break;case"h":a.replaceItem(e.createSVGPathSegLinetoHorizontalAbs(l),d);break;case"v":a.replaceItem(e.createSVGPathSegLinetoVerticalAbs(c),d);break;case"c":a.replaceItem(e.createSVGPathSegCurvetoCubicAbs(l,c,n,i,r,s),d);break;case"s":a.replaceItem(e.createSVGPathSegCurvetoCubicSmoothAbs(l,c,r,s),d);break;case"q":a.replaceItem(e.createSVGPathSegCurvetoQuadraticAbs(l,c,n,i),d);break;case"t":a.replaceItem(e.createSVGPathSegCurvetoQuadraticSmoothAbs(l,c),d);break;case"a":a.replaceItem(e.createSVGPathSegArcAbs(l,c,p.r1,p.r2,p.angle,p.largeArcFlag,p.sweepFlag),d);
break;case"z":case"Z":l=t,c=o}"M"!=f&&"m"!=f||(t=l,o=c)}}}()},{"../geometry/Bounds":26}],28:[function(e,t,o){var n={};t.exports=n,function(){n.create=function(e,t){return{x:e||0,y:t||0}},n.clone=function(e){return{x:e.x,y:e.y}},n.magnitude=function(e){return Math.sqrt(e.x*e.x+e.y*e.y)},n.magnitudeSquared=function(e){return e.x*e.x+e.y*e.y},n.rotate=function(e,t){var o=Math.cos(t),n=Math.sin(t);return{x:e.x*o-e.y*n,y:e.x*n+e.y*o}},n.rotateAbout=function(e,t,o,n){var i=Math.cos(t),r=Math.sin(t);n||(n={});var s=o.x+((e.x-o.x)*i-(e.y-o.y)*r);return n.y=o.y+((e.x-o.x)*r+(e.y-o.y)*i),n.x=s,n},n.normalise=function(e){var t=n.magnitude(e);return 0===t?{x:0,y:0}:{x:e.x/t,y:e.y/t}},n.dot=function(e,t){return e.x*t.x+e.y*t.y},n.cross=function(e,t){return e.x*t.y-e.y*t.x},n.cross3=function(e,t,o){return(t.x-e.x)*(o.y-e.y)-(t.y-e.y)*(o.x-e.x)},n.add=function(e,t,o){return o||(o={}),o.x=e.x+t.x,o.y=e.y+t.y,o},n.sub=function(e,t,o){return o||(o={}),o.x=e.x-t.x,o.y=e.y-t.y,o},n.mult=function(e,t){return{
x:e.x*t,y:e.y*t}},n.div=function(e,t){return{x:e.x/t,y:e.y/t}},n.perp=function(e,t){return t=t===!0?-1:1,{x:t*-e.y,y:t*e.x}},n.neg=function(e){return{x:-e.x,y:-e.y}},n.angle=function(e,t){return Math.atan2(t.y-e.y,t.x-e.x)},n._temp=[n.create(),n.create(),n.create(),n.create(),n.create(),n.create()]}()},{}],29:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Vector"),r=e("../core/Common");!function(){n.create=function(e,t){for(var o=[],n=0;n<e.length;n++){var i=e[n],r={x:i.x,y:i.y,index:n,body:t,isInternal:!1};o.push(r)}return o},n.fromPath=function(e,t){var o=/L?\s*([\-\d\.e]+)[\s,]*([\-\d\.e]+)*/gi,i=[];return e.replace(o,function(e,t,o){i.push({x:parseFloat(t),y:parseFloat(o)})}),n.create(i,t)},n.centre=function(e){for(var t,o,r,s=n.area(e,!0),a={x:0,y:0},l=0;l<e.length;l++)r=(l+1)%e.length,t=i.cross(e[l],e[r]),o=i.mult(i.add(e[l],e[r]),t),a=i.add(a,o);return i.div(a,6*s)},n.mean=function(e){for(var t={x:0,y:0},o=0;o<e.length;o++)t.x+=e[o].x,t.y+=e[o].y;return i.div(t,e.length);
},n.area=function(e,t){for(var o=0,n=e.length-1,i=0;i<e.length;i++)o+=(e[n].x-e[i].x)*(e[n].y+e[i].y),n=i;return t?o/2:Math.abs(o)/2},n.inertia=function(e,t){for(var o,n,r=0,s=0,a=e,l=0;l<a.length;l++)n=(l+1)%a.length,o=Math.abs(i.cross(a[n],a[l])),r+=o*(i.dot(a[n],a[n])+i.dot(a[n],a[l])+i.dot(a[l],a[l])),s+=o;return t/6*(r/s)},n.translate=function(e,t,o){var n;if(o)for(n=0;n<e.length;n++)e[n].x+=t.x*o,e[n].y+=t.y*o;else for(n=0;n<e.length;n++)e[n].x+=t.x,e[n].y+=t.y;return e},n.rotate=function(e,t,o){if(0!==t){for(var n=Math.cos(t),i=Math.sin(t),r=0;r<e.length;r++){var s=e[r],a=s.x-o.x,l=s.y-o.y;s.x=o.x+(a*n-l*i),s.y=o.y+(a*i+l*n)}return e}},n.contains=function(e,t){for(var o=0;o<e.length;o++){var n=e[o],i=e[(o+1)%e.length];if((t.x-n.x)*(i.y-n.y)+(t.y-n.y)*(n.x-i.x)>0)return!1}return!0},n.scale=function(e,t,o,r){if(1===t&&1===o)return e;r=r||n.centre(e);for(var s,a,l=0;l<e.length;l++)s=e[l],a=i.sub(s,r),e[l].x=r.x+a.x*t,e[l].y=r.y+a.y*o;return e},n.chamfer=function(e,t,o,n,s){t=t||[8],
t.length||(t=[t]),o="undefined"!=typeof o?o:-1,n=n||2,s=s||14;for(var a=[],l=0;l<e.length;l++){var c=e[l-1>=0?l-1:e.length-1],u=e[l],d=e[(l+1)%e.length],p=t[l<t.length?l:t.length-1];if(0!==p){var f=i.normalise({x:u.y-c.y,y:c.x-u.x}),v=i.normalise({x:d.y-u.y,y:u.x-d.x}),m=Math.sqrt(2*Math.pow(p,2)),y=i.mult(r.clone(f),p),g=i.normalise(i.mult(i.add(f,v),.5)),x=i.sub(u,i.mult(g,m)),h=o;-1===o&&(h=1.75*Math.pow(p,.32)),h=r.clamp(h,n,s),h%2===1&&(h+=1);for(var b=Math.acos(i.dot(f,v)),w=b/h,S=0;h>S;S++)a.push(i.add(i.rotate(y,w*S),x))}else a.push(u)}return a},n.clockwiseSort=function(e){var t=n.mean(e);return e.sort(function(e,o){return i.angle(t,e)-i.angle(t,o)}),e},n.isConvex=function(e){var t,o,n,i,r=0,s=e.length;if(3>s)return null;for(t=0;s>t;t++)if(o=(t+1)%s,n=(t+2)%s,i=(e[o].x-e[t].x)*(e[n].y-e[o].y),i-=(e[o].y-e[t].y)*(e[n].x-e[o].x),0>i?r|=1:i>0&&(r|=2),3===r)return!1;return 0!==r?!0:null},n.hull=function(e){var t,o,n=[],r=[];for(e=e.slice(0),e.sort(function(e,t){var o=e.x-t.x;return 0!==o?o:e.y-t.y;
}),o=0;o<e.length;o++){for(t=e[o];r.length>=2&&i.cross3(r[r.length-2],r[r.length-1],t)<=0;)r.pop();r.push(t)}for(o=e.length-1;o>=0;o--){for(t=e[o];n.length>=2&&i.cross3(n[n.length-2],n[n.length-1],t)<=0;)n.pop();n.push(t)}return n.pop(),r.pop(),n.concat(r)}}()},{"../core/Common":14,"../geometry/Vector":28}],30:[function(e,t,o){var n=t.exports=e("../core/Matter");n.Body=e("../body/Body"),n.Composite=e("../body/Composite"),n.World=e("../body/World"),n.Contact=e("../collision/Contact"),n.Detector=e("../collision/Detector"),n.Grid=e("../collision/Grid"),n.Pairs=e("../collision/Pairs"),n.Pair=e("../collision/Pair"),n.Query=e("../collision/Query"),n.Resolver=e("../collision/Resolver"),n.SAT=e("../collision/SAT"),n.Constraint=e("../constraint/Constraint"),n.MouseConstraint=e("../constraint/MouseConstraint"),n.Common=e("../core/Common"),n.Engine=e("../core/Engine"),n.Events=e("../core/Events"),n.Mouse=e("../core/Mouse"),n.Runner=e("../core/Runner"),n.Sleeping=e("../core/Sleeping"),n.Plugin=e("../core/Plugin"),
n.Bodies=e("../factory/Bodies"),n.Composites=e("../factory/Composites"),n.Axes=e("../geometry/Axes"),n.Bounds=e("../geometry/Bounds"),n.Svg=e("../geometry/Svg"),n.Vector=e("../geometry/Vector"),n.Vertices=e("../geometry/Vertices"),n.Render=e("../render/Render"),n.RenderPixi=e("../render/RenderPixi"),n.World.add=n.Composite.add,n.World.remove=n.Composite.remove,n.World.addComposite=n.Composite.addComposite,n.World.addBody=n.Composite.addBody,n.World.addConstraint=n.Composite.addConstraint,n.World.clear=n.Composite.clear,n.Engine.run=n.Runner.run},{"../body/Body":1,"../body/Composite":2,"../body/World":3,"../collision/Contact":4,"../collision/Detector":5,"../collision/Grid":6,"../collision/Pair":7,"../collision/Pairs":8,"../collision/Query":9,"../collision/Resolver":10,"../collision/SAT":11,"../constraint/Constraint":12,"../constraint/MouseConstraint":13,"../core/Common":14,"../core/Engine":15,"../core/Events":16,"../core/Matter":17,"../core/Metrics":18,"../core/Mouse":19,"../core/Plugin":20,
"../core/Runner":21,"../core/Sleeping":22,"../factory/Bodies":23,"../factory/Composites":24,"../geometry/Axes":25,"../geometry/Bounds":26,"../geometry/Svg":27,"../geometry/Vector":28,"../geometry/Vertices":29,"../render/Render":31,"../render/RenderPixi":32}],31:[function(e,t,o){var n={};t.exports=n;var i=e("../core/Common"),r=e("../body/Composite"),s=e("../geometry/Bounds"),a=e("../core/Events"),l=e("../collision/Grid"),c=e("../geometry/Vector");!function(){var e,t;"undefined"!=typeof window&&(e=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(function(){e(i.now())},1e3/60)},t=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame),n.create=function(e){var t={controller:n,engine:null,element:null,canvas:null,mouse:null,frameRequestId:null,options:{width:800,height:600,pixelRatio:1,background:"#fafafa",wireframeBackground:"#222",
hasBounds:!!e.bounds,enabled:!0,wireframes:!0,showSleeping:!0,showDebug:!1,showBroadphase:!1,showBounds:!1,showVelocity:!1,showCollisions:!1,showSeparations:!1,showAxes:!1,showPositions:!1,showAngleIndicator:!1,showIds:!1,showShadows:!1,showVertexNumbers:!1,showConvexHulls:!1,showInternalEdges:!1,showMousePosition:!1}},r=i.extend(t,e);return r.canvas&&(r.canvas.width=r.options.width||r.canvas.width,r.canvas.height=r.options.height||r.canvas.height),r.mouse=e.mouse,r.engine=e.engine,r.canvas=r.canvas||o(r.options.width,r.options.height),r.context=r.canvas.getContext("2d"),r.textures={},r.bounds=r.bounds||{min:{x:0,y:0},max:{x:r.canvas.width,y:r.canvas.height}},1!==r.options.pixelRatio&&n.setPixelRatio(r,r.options.pixelRatio),i.isElement(r.element)?r.element.appendChild(r.canvas):i.log("Render.create: options.element was undefined, render.canvas was created but not appended","warn"),r},n.run=function(t){!function o(i){t.frameRequestId=e(o),n.world(t)}()},n.stop=function(e){t(e.frameRequestId);
},n.setPixelRatio=function(e,t){var o=e.options,n=e.canvas;"auto"===t&&(t=u(n)),o.pixelRatio=t,n.setAttribute("data-pixel-ratio",t),n.width=o.width*t,n.height=o.height*t,n.style.width=o.width+"px",n.style.height=o.height+"px",e.context.scale(t,t)},n.world=function(e){var t,o=e.engine,i=o.world,u=e.canvas,d=e.context,f=e.options,v=r.allBodies(i),m=r.allConstraints(i),y=f.wireframes?f.wireframeBackground:f.background,g=[],x=[],h={timestamp:o.timing.timestamp};if(a.trigger(e,"beforeRender",h),e.currentBackground!==y&&p(e,y),d.globalCompositeOperation="source-in",d.fillStyle="transparent",d.fillRect(0,0,u.width,u.height),d.globalCompositeOperation="source-over",f.hasBounds){var b=e.bounds.max.x-e.bounds.min.x,w=e.bounds.max.y-e.bounds.min.y,S=b/f.width,C=w/f.height;for(t=0;t<v.length;t++){var A=v[t];s.overlaps(A.bounds,e.bounds)&&g.push(A)}for(t=0;t<m.length;t++){var P=m[t],B=P.bodyA,M=P.bodyB,k=P.pointA,I=P.pointB;B&&(k=c.add(B.position,P.pointA)),M&&(I=c.add(M.position,P.pointB)),k&&I&&(s.contains(e.bounds,k)||s.contains(e.bounds,I))&&x.push(P);
}d.scale(1/S,1/C),d.translate(-e.bounds.min.x,-e.bounds.min.y)}else x=m,g=v;!f.wireframes||o.enableSleeping&&f.showSleeping?n.bodies(e,g,d):(f.showConvexHulls&&n.bodyConvexHulls(e,g,d),n.bodyWireframes(e,g,d)),f.showBounds&&n.bodyBounds(e,g,d),(f.showAxes||f.showAngleIndicator)&&n.bodyAxes(e,g,d),f.showPositions&&n.bodyPositions(e,g,d),f.showVelocity&&n.bodyVelocity(e,g,d),f.showIds&&n.bodyIds(e,g,d),f.showSeparations&&n.separations(e,o.pairs.list,d),f.showCollisions&&n.collisions(e,o.pairs.list,d),f.showVertexNumbers&&n.vertexNumbers(e,g,d),f.showMousePosition&&n.mousePosition(e,e.mouse,d),n.constraints(x,d),f.showBroadphase&&o.broadphase.controller===l&&n.grid(e,o.broadphase,d),f.showDebug&&n.debug(e,d),f.hasBounds&&d.setTransform(f.pixelRatio,0,0,f.pixelRatio,0,0),a.trigger(e,"afterRender",h)},n.debug=function(e,t){var o=t,n=e.engine,i=n.world,s=n.metrics,a=e.options,l=(r.allBodies(i)," ");if(n.timing.timestamp-(e.debugTimestamp||0)>=500){var c="";s.timing&&(c+="fps: "+Math.round(s.timing.fps)+l),
e.debugString=c,e.debugTimestamp=n.timing.timestamp}if(e.debugString){o.font="12px Arial",a.wireframes?o.fillStyle="rgba(255,255,255,0.5)":o.fillStyle="rgba(0,0,0,0.5)";for(var u=e.debugString.split("\n"),d=0;d<u.length;d++)o.fillText(u[d],50,50+18*d)}},n.constraints=function(e,t){for(var o=t,n=0;n<e.length;n++){var i=e[n];if(i.render.visible&&i.pointA&&i.pointB){var r=i.bodyA,s=i.bodyB;r?(o.beginPath(),o.moveTo(r.position.x+i.pointA.x,r.position.y+i.pointA.y)):(o.beginPath(),o.moveTo(i.pointA.x,i.pointA.y)),s?o.lineTo(s.position.x+i.pointB.x,s.position.y+i.pointB.y):o.lineTo(i.pointB.x,i.pointB.y),o.lineWidth=i.render.lineWidth,o.strokeStyle=i.render.strokeStyle,o.stroke()}}},n.bodyShadows=function(e,t,o){for(var n=o,i=(e.engine,0);i<t.length;i++){var r=t[i];if(r.render.visible){if(r.circleRadius)n.beginPath(),n.arc(r.position.x,r.position.y,r.circleRadius,0,2*Math.PI),n.closePath();else{n.beginPath(),n.moveTo(r.vertices[0].x,r.vertices[0].y);for(var s=1;s<r.vertices.length;s++)n.lineTo(r.vertices[s].x,r.vertices[s].y);
n.closePath()}var a=r.position.x-.5*e.options.width,l=r.position.y-.2*e.options.height,c=Math.abs(a)+Math.abs(l);n.shadowColor="rgba(0,0,0,0.15)",n.shadowOffsetX=.05*a,n.shadowOffsetY=.05*l,n.shadowBlur=1+12*Math.min(1,c/1e3),n.fill(),n.shadowColor=null,n.shadowOffsetX=null,n.shadowOffsetY=null,n.shadowBlur=null}}},n.bodies=function(e,t,o){var n,i,r,s,a=o,l=(e.engine,e.options),c=l.showInternalEdges||!l.wireframes;for(r=0;r<t.length;r++)if(n=t[r],n.render.visible)for(s=n.parts.length>1?1:0;s<n.parts.length;s++)if(i=n.parts[s],i.render.visible){if(l.showSleeping&&n.isSleeping?a.globalAlpha=.5*i.render.opacity:1!==i.render.opacity&&(a.globalAlpha=i.render.opacity),i.render.sprite&&i.render.sprite.texture&&!l.wireframes){var u=i.render.sprite,p=d(e,u.texture);a.translate(i.position.x,i.position.y),a.rotate(i.angle),a.drawImage(p,p.width*-u.xOffset*u.xScale,p.height*-u.yOffset*u.yScale,p.width*u.xScale,p.height*u.yScale),a.rotate(-i.angle),a.translate(-i.position.x,-i.position.y)}else{if(i.circleRadius)a.beginPath(),
a.arc(i.position.x,i.position.y,i.circleRadius,0,2*Math.PI);else{a.beginPath(),a.moveTo(i.vertices[0].x,i.vertices[0].y);for(var f=1;f<i.vertices.length;f++)!i.vertices[f-1].isInternal||c?a.lineTo(i.vertices[f].x,i.vertices[f].y):a.moveTo(i.vertices[f].x,i.vertices[f].y),i.vertices[f].isInternal&&!c&&a.moveTo(i.vertices[(f+1)%i.vertices.length].x,i.vertices[(f+1)%i.vertices.length].y);a.lineTo(i.vertices[0].x,i.vertices[0].y),a.closePath()}l.wireframes?(a.lineWidth=1,a.strokeStyle="#bbb"):(a.fillStyle=i.render.fillStyle,a.lineWidth=i.render.lineWidth,a.strokeStyle=i.render.strokeStyle,a.fill()),a.stroke()}a.globalAlpha=1}},n.bodyWireframes=function(e,t,o){var n,i,r,s,a,l=o,c=e.options.showInternalEdges;for(l.beginPath(),r=0;r<t.length;r++)if(n=t[r],n.render.visible)for(a=n.parts.length>1?1:0;a<n.parts.length;a++){for(i=n.parts[a],l.moveTo(i.vertices[0].x,i.vertices[0].y),s=1;s<i.vertices.length;s++)!i.vertices[s-1].isInternal||c?l.lineTo(i.vertices[s].x,i.vertices[s].y):l.moveTo(i.vertices[s].x,i.vertices[s].y),
2016-09-19 18:53:35 -04:00
i.vertices[s].isInternal&&!c&&l.moveTo(i.vertices[(s+1)%i.vertices.length].x,i.vertices[(s+1)%i.vertices.length].y);l.lineTo(i.vertices[0].x,i.vertices[0].y)}l.lineWidth=1,l.strokeStyle="#bbb",l.stroke()},n.bodyConvexHulls=function(e,t,o){var n,i,r,s=o;for(s.beginPath(),i=0;i<t.length;i++)if(n=t[i],n.render.visible&&1!==n.parts.length){for(s.moveTo(n.vertices[0].x,n.vertices[0].y),r=1;r<n.vertices.length;r++)s.lineTo(n.vertices[r].x,n.vertices[r].y);s.lineTo(n.vertices[0].x,n.vertices[0].y)}s.lineWidth=1,s.strokeStyle="rgba(255,255,255,0.2)",s.stroke()},n.vertexNumbers=function(e,t,o){var n,i,r,s=o;for(n=0;n<t.length;n++){var a=t[n].parts;for(r=a.length>1?1:0;r<a.length;r++){var l=a[r];for(i=0;i<l.vertices.length;i++)s.fillStyle="rgba(255,255,255,0.2)",s.fillText(n+"_"+i,l.position.x+.8*(l.vertices[i].x-l.position.x),l.position.y+.8*(l.vertices[i].y-l.position.y))}}},n.mousePosition=function(e,t,o){var n=o;n.fillStyle="rgba(255,255,255,0.8)",n.fillText(t.position.x+" "+t.position.y,t.position.x+5,t.position.y-5);
2016-11-02 20:49:53 -04:00
},n.bodyBounds=function(e,t,o){var n=o,i=(e.engine,e.options);n.beginPath();for(var r=0;r<t.length;r++){var s=t[r];if(s.render.visible)for(var a=t[r].parts,l=a.length>1?1:0;l<a.length;l++){var c=a[l];n.rect(c.bounds.min.x,c.bounds.min.y,c.bounds.max.x-c.bounds.min.x,c.bounds.max.y-c.bounds.min.y)}}i.wireframes?n.strokeStyle="rgba(255,255,255,0.08)":n.strokeStyle="rgba(0,0,0,0.1)",n.lineWidth=1,n.stroke()},n.bodyAxes=function(e,t,o){var n,i,r,s,a=o,l=(e.engine,e.options);for(a.beginPath(),i=0;i<t.length;i++){var c=t[i],u=c.parts;if(c.render.visible)if(l.showAxes)for(r=u.length>1?1:0;r<u.length;r++)for(n=u[r],s=0;s<n.axes.length;s++){var d=n.axes[s];a.moveTo(n.position.x,n.position.y),a.lineTo(n.position.x+20*d.x,n.position.y+20*d.y)}else for(r=u.length>1?1:0;r<u.length;r++)for(n=u[r],s=0;s<n.axes.length;s++)a.moveTo(n.position.x,n.position.y),a.lineTo((n.vertices[0].x+n.vertices[n.vertices.length-1].x)/2,(n.vertices[0].y+n.vertices[n.vertices.length-1].y)/2)}l.wireframes?a.strokeStyle="indianred":(a.strokeStyle="rgba(0,0,0,0.8)",
2016-09-19 18:53:35 -04:00
a.globalCompositeOperation="overlay"),a.lineWidth=1,a.stroke(),a.globalCompositeOperation="source-over"},n.bodyPositions=function(e,t,o){var n,i,r,s,a=o,l=(e.engine,e.options);for(a.beginPath(),r=0;r<t.length;r++)if(n=t[r],n.render.visible)for(s=0;s<n.parts.length;s++)i=n.parts[s],a.arc(i.position.x,i.position.y,3,0,2*Math.PI,!1),a.closePath();for(l.wireframes?a.fillStyle="indianred":a.fillStyle="rgba(0,0,0,0.5)",a.fill(),a.beginPath(),r=0;r<t.length;r++)n=t[r],n.render.visible&&(a.arc(n.positionPrev.x,n.positionPrev.y,2,0,2*Math.PI,!1),a.closePath());a.fillStyle="rgba(255,165,0,0.8)",a.fill()},n.bodyVelocity=function(e,t,o){var n=o;n.beginPath();for(var i=0;i<t.length;i++){var r=t[i];r.render.visible&&(n.moveTo(r.position.x,r.position.y),n.lineTo(r.position.x+2*(r.position.x-r.positionPrev.x),r.position.y+2*(r.position.y-r.positionPrev.y)))}n.lineWidth=3,n.strokeStyle="cornflowerblue",n.stroke()},n.bodyIds=function(e,t,o){var n,i,r=o;for(n=0;n<t.length;n++)if(t[n].render.visible){var s=t[n].parts;
2016-11-02 20:49:53 -04:00
for(i=s.length>1?1:0;i<s.length;i++){var a=s[i];r.font="12px Arial",r.fillStyle="rgba(255,255,255,0.5)",r.fillText(a.id,a.position.x+10,a.position.y-10)}}},n.collisions=function(e,t,o){var n,i,r,s,a=o,l=e.options;for(a.beginPath(),r=0;r<t.length;r++)if(n=t[r],n.isActive)for(i=n.collision,s=0;s<n.activeContacts.length;s++){var c=n.activeContacts[s],u=c.vertex;a.rect(u.x-1.5,u.y-1.5,3.5,3.5)}for(l.wireframes?a.fillStyle="rgba(255,255,255,0.7)":a.fillStyle="orange",a.fill(),a.beginPath(),r=0;r<t.length;r++)if(n=t[r],n.isActive&&(i=n.collision,n.activeContacts.length>0)){var d=n.activeContacts[0].vertex.x,p=n.activeContacts[0].vertex.y;2===n.activeContacts.length&&(d=(n.activeContacts[0].vertex.x+n.activeContacts[1].vertex.x)/2,p=(n.activeContacts[0].vertex.y+n.activeContacts[1].vertex.y)/2),i.bodyB===i.supports[0].body||i.bodyA.isStatic===!0?a.moveTo(d-8*i.normal.x,p-8*i.normal.y):a.moveTo(d+8*i.normal.x,p+8*i.normal.y),a.lineTo(d,p)}l.wireframes?a.strokeStyle="rgba(255,165,0,0.7)":a.strokeStyle="orange",
a.lineWidth=1,a.stroke()},n.separations=function(e,t,o){var n,i,r,s,a,l=o,c=e.options;for(l.beginPath(),a=0;a<t.length;a++)if(n=t[a],n.isActive){i=n.collision,r=i.bodyA,s=i.bodyB;var u=1;s.isStatic||r.isStatic||(u=.5),s.isStatic&&(u=0),l.moveTo(s.position.x,s.position.y),l.lineTo(s.position.x-i.penetration.x*u,s.position.y-i.penetration.y*u),u=1,s.isStatic||r.isStatic||(u=.5),r.isStatic&&(u=0),l.moveTo(r.position.x,r.position.y),l.lineTo(r.position.x+i.penetration.x*u,r.position.y+i.penetration.y*u)}c.wireframes?l.strokeStyle="rgba(255,165,0,0.5)":l.strokeStyle="orange",l.stroke()},n.grid=function(e,t,o){var n=o,r=e.options;r.wireframes?n.strokeStyle="rgba(255,180,0,0.1)":n.strokeStyle="rgba(255,180,0,0.5)",n.beginPath();for(var s=i.keys(t.buckets),a=0;a<s.length;a++){var l=s[a];if(!(t.buckets[l].length<2)){var c=l.split(",");n.rect(.5+parseInt(c[0],10)*t.bucketWidth,.5+parseInt(c[1],10)*t.bucketHeight,t.bucketWidth,t.bucketHeight)}}n.lineWidth=1,n.stroke()},n.inspector=function(e,t){var o,n=(e.engine,
e.selected),i=e.render,r=i.options;if(r.hasBounds){var s=i.bounds.max.x-i.bounds.min.x,a=i.bounds.max.y-i.bounds.min.y,l=s/i.options.width,c=a/i.options.height;t.scale(1/l,1/c),t.translate(-i.bounds.min.x,-i.bounds.min.y)}for(var u=0;u<n.length;u++){var d=n[u].data;switch(t.translate(.5,.5),t.lineWidth=1,t.strokeStyle="rgba(255,165,0,0.9)",t.setLineDash([1,2]),d.type){case"body":o=d.bounds,t.beginPath(),t.rect(Math.floor(o.min.x-3),Math.floor(o.min.y-3),Math.floor(o.max.x-o.min.x+6),Math.floor(o.max.y-o.min.y+6)),t.closePath(),t.stroke();break;case"constraint":var p=d.pointA;d.bodyA&&(p=d.pointB),t.beginPath(),t.arc(p.x,p.y,10,0,2*Math.PI),t.closePath(),t.stroke()}t.setLineDash([]),t.translate(-.5,-.5)}null!==e.selectStart&&(t.translate(.5,.5),t.lineWidth=1,t.strokeStyle="rgba(255,165,0,0.6)",t.fillStyle="rgba(255,165,0,0.1)",o=e.selectBounds,t.beginPath(),t.rect(Math.floor(o.min.x),Math.floor(o.min.y),Math.floor(o.max.x-o.min.x),Math.floor(o.max.y-o.min.y)),t.closePath(),t.stroke(),t.fill(),
t.translate(-.5,-.5)),r.hasBounds&&t.setTransform(1,0,0,1,0,0)};var o=function(e,t){var o=document.createElement("canvas");return o.width=e,o.height=t,o.oncontextmenu=function(){return!1},o.onselectstart=function(){return!1},o},u=function(e){var t=e.getContext("2d"),o=window.devicePixelRatio||1,n=t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1;return o/n},d=function(e,t){var o=e.textures[t];return o?o:(o=e.textures[t]=new Image,o.src=t,o)},p=function(e,t){var o=t;/(jpg|gif|png)$/.test(t)&&(o="url("+t+")"),e.canvas.style.background=o,e.canvas.style.backgroundSize="contain",e.currentBackground=t}}()},{"../body/Composite":2,"../collision/Grid":6,"../core/Common":14,"../core/Events":16,"../geometry/Bounds":26,"../geometry/Vector":28}],32:[function(e,t,o){var n={};t.exports=n;var i=e("../geometry/Bounds"),r=e("../body/Composite"),s=e("../core/Common"),a=e("../core/Events"),l=e("../geometry/Vector");
2016-09-19 18:53:35 -04:00
!function(){var e,t;"undefined"!=typeof window&&(e=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(e){window.setTimeout(function(){e(s.now())},1e3/60)},t=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame),n.create=function(e){s.warn("RenderPixi.create: Matter.RenderPixi is deprecated (see docs)");var t={controller:n,engine:null,element:null,frameRequestId:null,canvas:null,renderer:null,container:null,spriteContainer:null,pixiOptions:null,options:{width:800,height:600,background:"#fafafa",wireframeBackground:"#222",hasBounds:!1,enabled:!0,wireframes:!0,showSleeping:!0,showDebug:!1,showBroadphase:!1,showBounds:!1,showVelocity:!1,showCollisions:!1,showAxes:!1,showPositions:!1,showAngleIndicator:!1,showIds:!1,showShadows:!1}},o=s.extend(t,e),i=!o.options.wireframes&&"transparent"===o.options.background;return o.pixiOptions=o.pixiOptions||{
view:o.canvas,transparent:i,antialias:!0,backgroundColor:e.background},o.mouse=e.mouse,o.engine=e.engine,o.renderer=o.renderer||new PIXI.WebGLRenderer(o.options.width,o.options.height,o.pixiOptions),o.container=o.container||new PIXI.Container,o.spriteContainer=o.spriteContainer||new PIXI.Container,o.canvas=o.canvas||o.renderer.view,o.bounds=o.bounds||{min:{x:0,y:0},max:{x:o.options.width,y:o.options.height}},a.on(o.engine,"beforeUpdate",function(){n.clear(o)}),o.textures={},o.sprites={},o.primitives={},o.container.addChild(o.spriteContainer),s.isElement(o.element)?o.element.appendChild(o.canvas):s.warn('No "render.element" passed, "render.canvas" was not inserted into document.'),o.canvas.oncontextmenu=function(){return!1},o.canvas.onselectstart=function(){return!1},o},n.run=function(t){!function o(i){t.frameRequestId=e(o),n.world(t)}()},n.stop=function(e){t(e.frameRequestId)},n.clear=function(e){for(var t=e.container,o=e.spriteContainer;t.children[0];)t.removeChild(t.children[0]);for(;o.children[0];)o.removeChild(o.children[0]);
2016-11-02 20:49:53 -04:00
var n=e.sprites["bg-0"];e.textures={},e.sprites={},e.primitives={},e.sprites["bg-0"]=n,n&&t.addChildAt(n,0),e.container.addChild(e.spriteContainer),e.currentBackground=null,t.scale.set(1,1),t.position.set(0,0)},n.setBackground=function(e,t){if(e.currentBackground!==t){var o=t.indexOf&&-1!==t.indexOf("#"),n=e.sprites["bg-0"];if(o){var i=s.colorToNumber(t);e.renderer.backgroundColor=i,n&&e.container.removeChild(n)}else if(!n){var r=u(e,t);n=e.sprites["bg-0"]=new PIXI.Sprite(r),n.position.x=0,n.position.y=0,e.container.addChildAt(n,0)}e.currentBackground=t}},n.world=function(e){var t,o=e.engine,s=o.world,a=e.renderer,c=e.container,u=e.options,d=r.allBodies(s),p=r.allConstraints(s),f=[];u.wireframes?n.setBackground(e,u.wireframeBackground):n.setBackground(e,u.background);var v=e.bounds.max.x-e.bounds.min.x,m=e.bounds.max.y-e.bounds.min.y,y=v/e.options.width,g=m/e.options.height;if(u.hasBounds){for(t=0;t<d.length;t++){var x=d[t];x.render.sprite.visible=i.overlaps(x.bounds,e.bounds)}for(t=0;t<p.length;t++){
var h=p[t],b=h.bodyA,w=h.bodyB,S=h.pointA,C=h.pointB;b&&(S=l.add(b.position,h.pointA)),w&&(C=l.add(w.position,h.pointB)),S&&C&&(i.contains(e.bounds,S)||i.contains(e.bounds,C))&&f.push(h)}c.scale.set(1/y,1/g),c.position.set(-e.bounds.min.x*(1/y),-e.bounds.min.y*(1/g))}else f=p;for(t=0;t<d.length;t++)n.body(e,d[t]);for(t=0;t<f.length;t++)n.constraint(e,f[t]);a.render(c)},n.constraint=function(e,t){var o=(e.engine,t.bodyA),n=t.bodyB,i=t.pointA,r=t.pointB,a=e.container,l=t.render,c="c-"+t.id,u=e.primitives[c];return u||(u=e.primitives[c]=new PIXI.Graphics),l.visible&&t.pointA&&t.pointB?(-1===s.indexOf(a.children,u)&&a.addChild(u),u.clear(),u.beginFill(0,0),u.lineStyle(l.lineWidth,s.colorToNumber(l.strokeStyle),1),o?u.moveTo(o.position.x+i.x,o.position.y+i.y):u.moveTo(i.x,i.y),n?u.lineTo(n.position.x+r.x,n.position.y+r.y):u.lineTo(r.x,r.y),void u.endFill()):void u.clear()},n.body=function(e,t){var n=(e.engine,t.render);if(n.visible)if(n.sprite&&n.sprite.texture){var i="b-"+t.id,r=e.sprites[i],a=e.spriteContainer;
r||(r=e.sprites[i]=o(e,t)),-1===s.indexOf(a.children,r)&&a.addChild(r),r.position.x=t.position.x,r.position.y=t.position.y,r.rotation=t.angle,r.scale.x=n.sprite.xScale||1,r.scale.y=n.sprite.yScale||1}else{var l="b-"+t.id,u=e.primitives[l],d=e.container;u||(u=e.primitives[l]=c(e,t),u.initialAngle=t.angle),-1===s.indexOf(d.children,u)&&d.addChild(u),u.position.x=t.position.x,u.position.y=t.position.y,u.rotation=t.angle-u.initialAngle}};var o=function(e,t){var o=t.render,n=o.sprite.texture,i=u(e,n),r=new PIXI.Sprite(i);return r.anchor.x=t.render.sprite.xOffset,r.anchor.y=t.render.sprite.yOffset,r},c=function(e,t){var o,n=t.render,i=e.options,r=new PIXI.Graphics,a=s.colorToNumber(n.fillStyle),l=s.colorToNumber(n.strokeStyle),c=s.colorToNumber(n.strokeStyle),u=s.colorToNumber("#bbb"),d=s.colorToNumber("#CD5C5C");r.clear();for(var p=t.parts.length>1?1:0;p<t.parts.length;p++){o=t.parts[p],i.wireframes?(r.beginFill(0,0),r.lineStyle(1,u,1)):(r.beginFill(a,1),r.lineStyle(n.lineWidth,l,1)),r.moveTo(o.vertices[0].x-t.position.x,o.vertices[0].y-t.position.y);
for(var f=1;f<o.vertices.length;f++)r.lineTo(o.vertices[f].x-t.position.x,o.vertices[f].y-t.position.y);r.lineTo(o.vertices[0].x-t.position.x,o.vertices[0].y-t.position.y),r.endFill(),(i.showAngleIndicator||i.showAxes)&&(r.beginFill(0,0),i.wireframes?r.lineStyle(1,d,1):r.lineStyle(1,c),r.moveTo(o.position.x-t.position.x,o.position.y-t.position.y),r.lineTo((o.vertices[0].x+o.vertices[o.vertices.length-1].x)/2-t.position.x,(o.vertices[0].y+o.vertices[o.vertices.length-1].y)/2-t.position.y),r.endFill())}return r},u=function(e,t){var o=e.textures[t];return o||(o=e.textures[t]=PIXI.Texture.fromImage(t)),o}}()},{"../body/Composite":2,"../core/Common":14,"../core/Events":16,"../geometry/Bounds":26,"../geometry/Vector":28}]},{},[30])(30)});