xxxxxxxxxx
42
// Daniel Shiffman
// https://youtu.be/4HsVCLakjtQ
// module aliases
const Engine = Matter.Engine;
// const Render = Matter.Render;
const World = Matter.World;
const Bodies = Matter.Bodies;
let engine;
let world;
let circles = [];
let boundaries = [];
let ground;
function setup() {
createCanvas(400, 400);
engine = Engine.create();
world = engine.world;
boundaries.push(new Boundary(150, 200, width * 0.6, 20, 0.3));
boundaries.push(new Boundary(250, 300, width * 0.6, 20, -0.3));
}
function draw() {
background(0);
circles.push(new Circle(200, 50, random(5, 10)));
Engine.update(engine);
for (let i = 0; i < circles.length; i++) {
circles[i].show();
if (circles[i].isOffScreen()) {
circles[i].removeFromWorld();
circles.splice(i, 1);
i--;
}
}
for (let i = 0; i < boundaries.length; i++) {
boundaries[i].show();
}
}