xxxxxxxxxx
41
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
const { Engine, Bodies, Body, Composite, Vector } = Matter;
// A reference to the matter physics engine
let engine;
let boundaries = [];
let box;
function setup() {
let canvas = createCanvas(640, 240);
// Create the Matter engine
engine = Engine.create();
// Add a bunch of fixed boundaries
boundaries.push(new Boundary(width / 2, height - 5, width, 10));
boundaries.push(new Boundary(width / 2, 5, width, 10));
boundaries.push(new Boundary(5, height / 2, 10, height));
boundaries.push(new Boundary(width - 5, height / 2, 10, height));
box = new Box(width / 2, 20, 48, 48);
}
function draw() {
background(255);
// Update the engine!
Engine.update(engine);
// Display all the boundaries
for (let i = 0; i < boundaries.length; i++) {
boundaries[i].show();
}
box.show();
}