Published
Edited
Feb 16, 2021
1 star
Insert cell
Insert cell
{
var element = html`<div></div>`;

// create engine
var engine = Engine.create(),
world = engine.world;

var height = 700;
// create renderer
var render = Render.create({
element: element,
engine: engine,
options: {
width: width,
height: height,
wireframes: false,
background: 'rgb(255,255,255)'
}
});

Engine.run(engine);
Render.run(render);

let ground = Bodies.rectangle(width / 2, height, width, 5, {
isStatic: true
});
let left = Bodies.rectangle(0, height / 2, 5, height, {
isStatic: true
});
let right = Bodies.rectangle(width, height / 2, 5, height, {
isStatic: true
});

World.add(engine.world, [ground, left, right]);

const Spawn = () => {
// 1. Create ball
let size = 38;
const ball = Matter.Bodies.circle(
Math.random() * width, // x
-10, // y
size, // size
{
render: {
sprite: {
texture: ABCs[Math.floor(Math.random() * ABCs.length)],
xScale: size / Max_Size,
yScale: size / Max_Size
}
}
}
);

// 2. Add ball to world
World.add(engine.world, [ball]);

// 3. Set time to remove ball from world
setTimeout(() => {
World.remove(engine.world, ball);
}, 10000);
};

// Spawn every 100 ms
setInterval(Spawn, 500 - Spawn_Rate);

return element;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more