Public
Edited
Nov 21, 2023
Insert cell
Insert cell
Insert cell
viewof Spawn_Rate = slider({
min: 10,
max: 500,
value: 250,
step: 10,
title: "Spawn Rate"
})
Insert cell
viewof Max_Size = slider({
min: 1,
max: 100,
value: 50,
step: 1,
title: "Max Size"
})
Insert cell
{
var element = html`<div></div>`;

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

// create renderer
var render = Render.create({
element: element,
engine: engine,
options: {
width: width,
height: 600,
wireframes: false
}
});

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

const Spawn = () => {
// 1. Create ball
const ball = Matter.Bodies.circle(
Math.random() * width, // x
-10, // y
Math.random() * Max_Size // 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);
}, 2000);
};

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

return element;
}
Insert cell
Matter = require('matter-js@0.14.2/build/matter.js').catch(
() => window["Matter"]
)
Insert cell
Engine = Matter.Engine
Insert cell
Render = Matter.Render
Insert cell
World = Matter.World
Insert cell
Bodies = Matter.Bodies
Insert cell
import { slider, color } from "@jashkenas/inputs"
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