mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-30 10:20:52 -05:00
42 lines
No EOL
1.3 KiB
JavaScript
42 lines
No EOL
1.3 KiB
JavaScript
(function() {
|
|
|
|
var World = Matter.World,
|
|
Bodies = Matter.Bodies,
|
|
Composites = Matter.Composites,
|
|
Common = Matter.Common;
|
|
|
|
Example.mixed = function(demo) {
|
|
var engine = demo.engine,
|
|
world = engine.world;
|
|
|
|
var stack = Composites.stack(20, 20, 15, 4, 0, 0, function(x, y) {
|
|
var sides = Math.round(Common.random(1, 8));
|
|
|
|
// triangles can be a little unstable, so avoid until fixed
|
|
sides = (sides === 3) ? 4 : sides;
|
|
|
|
// round the edges of some bodies
|
|
var chamfer = null;
|
|
if (sides > 2 && Common.random() > 0.7) {
|
|
chamfer = {
|
|
radius: 10
|
|
};
|
|
}
|
|
|
|
switch (Math.round(Common.random(0, 1))) {
|
|
case 0:
|
|
if (Common.random() < 0.8) {
|
|
return Bodies.rectangle(x, y, Common.random(25, 50), Common.random(25, 50), { chamfer: chamfer });
|
|
} else {
|
|
return Bodies.rectangle(x, y, Common.random(80, 120), Common.random(25, 30), { chamfer: chamfer });
|
|
}
|
|
break;
|
|
case 1:
|
|
return Bodies.polygon(x, y, sides, Common.random(25, 50), { chamfer: chamfer });
|
|
}
|
|
});
|
|
|
|
World.add(world, stack);
|
|
};
|
|
|
|
})(); |