mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
6 lines
149 KiB
JavaScript
6 lines
149 KiB
JavaScript
|
/*!
|
||
|
* matter-demo bundle 0.16.1 by @liabru
|
||
|
* http://brm.io/matter-js/
|
||
|
* License MIT
|
||
|
*/
|
||
|
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("MatterDemo",[],t):"object"==typeof exports?exports.MatterDemo=t():e.MatterDemo=t()}(this,(function(){return(this.webpackJsonpMatterDemo=this.webpackJsonpMatterDemo||[]).push([[0],{"+QOk":function(e,t,n){var r=r||{};r.timescale=function(){var e=Matter.Engine,t=Matter.Render,n=Matter.Runner,r=Matter.Body,o=Matter.Events,i=Matter.Composite,a=Matter.Composites,s=Matter.Common,c=Matter.MouseConstraint,l=Matter.Mouse,d=Matter.World,u=Matter.Bodies,p=e.create(),m=p.world,f=t.create({element:document.body,engine:p,options:{width:800,height:600,showAngleIndicator:!0}});t.run(f);var v=n.create();n.run(v,p),d.add(m,[u.rectangle(400,0,800,50,{isStatic:!0}),u.rectangle(400,600,800,50,{isStatic:!0}),u.rectangle(800,300,50,600,{isStatic:!0}),u.rectangle(0,300,50,600,{isStatic:!0})]);var g=1,y=0;o.on(p,"afterUpdate",(function(e){p.timing.timeScale+=.05*(g-p.timing.timeScale),(y+=1)>=90&&(g=g<1?1:.05,function(e){for(var t=i.allBodies(e.world),n=0;n<t.length;n++){var o=t[n];if(!o.isStatic&&o.position.y>=500){var a=.05*o.mass;r.applyForce(o,o.position,{x:(a+s.random()*a)*s.choose([1,-1]),y:-a+s.random()*-a})}}}(p),y=0)}));var x={frictionAir:0,friction:1e-4,restitution:.8};d.add(m,a.stack(20,100,15,3,20,40,(function(e,t){return u.circle(e,t,s.random(10,20),x)}))),d.add(m,a.stack(50,50,8,3,0,0,(function(e,t){switch(Math.round(s.random(0,1))){case 0:return s.random()<.8?u.rectangle(e,t,s.random(20,50),s.random(20,50),x):u.rectangle(e,t,s.random(80,120),s.random(20,30),x);case 1:return u.polygon(e,t,Math.round(s.random(4,8)),s.random(20,50),x)}})));var h=l.create(f.canvas),b=c.create(p,{mouse:h,constraint:{stiffness:.2,render:{visible:!1}}});return d.add(m,b),f.mouse=h,t.lookAt(f,{min:{x:0,y:0},max:{x:800,y:600}}),{engine:p,runner:v,render:f,canvas:f.canvas,stop:function(){Matter.Render.stop(f),Matter.Runner.stop(v)}}},r.timescale.title="Time Scaling",r.timescale.for=">=0.14.2",e.exports=r.timescale},"+jwT":function(e,t,n){var r=r||{};r.constraints=function(){var e=Matter.Engine,t=Matter.Render,n=Matter.Runner,r=(Matter.Composites,Matter.Common,Matter.Constraint),o=Matter.MouseConstraint,i=Matter.Mouse,a=Matter.World,s=Matter.Bodies,c=e.create(),l=c.world,d=t.create({element:document.body,engine:c,options:{width:800,height:600,showAngleIndicator:!0}});t.run(d);var u=n.create();n.run(u,c);var p=s.polygon(150,200,5,30),m=r.create({pointA:{x:150,y:100},bodyB:p,pointB:{x:-10,y:-10}});a.add(l,[p,m]);p=s.polygon(280,100,3,30),m=r.create({pointA:{x:280,y:120},bodyB:p,pointB:{x:-10,y:-7},stiffness:.001});a.add(l,[p,m]);p=s.polygon(400,100,4,30),m=r.create({pointA:{x:400,y:120},bodyB:p,pointB:{x:-10,y:-10},stiffness:.001,damping:.05});a.add(l,[p,m]);p=s.rectangle(600,200,200,20);var f=s.circle(550,150,20);m=r.create({pointA:{x:600,y:200},bodyB:p,length:0});a.add(l,[p,f,m]);p=s.rectangle(500,400,100,20,{collisionFilter:{group:-1}}),f=s.circle(600,400,20,{collisionFilter:{group:-1}}),m=r.create({bodyA:p,bodyB:f});a.add(l,[p,f,m]);var v=s.polygon(100,400,6,20),g=s.polygon(200,400,1,50);m=r.create({bodyA:v,pointA:{x:-10,y:-10},bodyB:g,pointB:{x:-10,y:-10}});a.add(l,[v,g,m]);v=s.polygon(300,400,4,20),g=s.polygon(400,400,3,30),m=r.create({bodyA:v,pointA:{x:-10,y:-10},bodyB:g,pointB:{x:-10,y:-7},stiffness:.001});a.add(l,[v,g,m]);v=s.polygon(500,400,6,30),g=s.polygon(600,400,7,60),m=r.create({bodyA:v,pointA:{x:-10,y:-10},bodyB:g,pointB:{x:-10,y:-10},stiffness:.001,damping:.1});a.add(l,[v,g,m]),a.add(l,[s.rectangle(400,0,800,50,{isStatic:!0}),s.rectangle(400,600,800,50,{isStatic:!0}),s.rectangle(800,300,50,600,{isStatic:!0}),s.rectangle(0,300,50,600,{isStatic:!0})]);var y=i.create(d.canvas),x=o.create(c,{mouse:y,constraint:{angularStiffness:0,render:{visible:!1}}});return a.add(l,x),d.mouse=y,t.lookAt(d,{min:{x:0,y:0},max:{x:800,y:600}}),{engine:c,runner:u,render:d,canvas:d.canvas,stop:function(){Matter.Render.stop(d),Matter.Runner.stop(u)}}},r.constraints.title="Constraints",r.constraints.for=">=0.14.2",e.exports=r.constraints},"/i
|