xxxxxxxxxx
60
const { Engine, World, Bodies } = Matter;
let engine;
let world;
let cup;
const particles = [];
const pegs = [];
let boundary;
const buckets = [];
const rows = 20;
const w = 550 / rows;
let slider;
function setup() {
createCanvas(600, 800);
engine = Engine.create();
world = engine.world;
cup = new Cup();
boundary = new Boundary();
for (let i = 0; i < 400; i++) {
particles.push(new Particle());
}
for (let j = 8; j < rows; j++) {
for (let i = 0; i < j+1; i++) {
pegs.push(new Peg(i*w + 305 - j*w/2, j*w*0.9 - 8*w*0.9+ 160));
}
}
for (let i = 0; i < rows; i++) {
buckets.push(new Bucket(i*w + 305 - 260));
}
slider = createSlider(-0.333, 0.333, 0.333, 0.055);
}
function draw() {
background(220);
world.gravity.y = slider.value();
for (let i = 0; i < 3; i++) {
Engine.update(engine);
}
cup.render();
boundary.render();
for (const p of particles) {
p.render();
}
for (const peg of pegs) {
peg.render();
}
for (const b of buckets) {
b.render();
}
}