xxxxxxxxxx
55
var Engine = Matter.Engine,
Render = Matter.Render,
World = Matter.World,
Mouse = Matter.Mouse,
MouseConstraint = Matter.MouseConstraint,
Bodies = Matter.Bodies;
var engine, world, mouse, mConstraint;
function setup() {
var canvas = createCanvas(800, 600);
engine = Engine.create();
render = Render.create({
canvas: canvas.elt,
engine: engine,
});
render.options.wireframes = false;
world = engine.world;
mouse = Mouse.create(canvas.elt);
mConstraint = MouseConstraint.create(engine, {
mouse: mouse,
element: canvas.elt
});
World.add(world, mConstraint);
var ground = Bodies.rectangle(400, 610, 1600, 60, {
isStatic: true,
restitution: 0.75
});
var options = {
restitution: 1,
plugin: {
wrap: {
min: {
x: -width / 2,
y: -height / 2
},
max: {
x: width / 2,
y: height / 2
}
}
}
};
var circle = Bodies.circle(400, 100 + random(100) - 50, 50, options);
var polygon = Bodies.polygon(400, 100 + random(100) - 50, 5, 50, options);
var rectangle = Bodies.rectangle(400, 100 + random(100) - 50, 70, 80, options);
var trapezoid = Bodies.trapezoid(400, 100 + random(100) - 50, 80, 90, 0.5, options);
World.add(world, [ground, circle, polygon, rectangle, trapezoid]);
Render.run(render);
}
function draw() {
Engine.update(engine);
}