Public
Edited
Feb 16, 2023
6 forks
Importers
82 stars
Insert cell
Insert cell
Insert cell
Insert cell
count = {
let i = 0;
while (true) yield Promises.delay(1000, ++i);
}
Insert cell
Insert cell
doubleCount = count * 2
Insert cell
Insert cell
evenCount = {
yield count % 2 === 0 ? count : this;
}
Insert cell
Insert cell
Insert cell
Insert cell
counter = {
let i = 0;
while (true) {
if (i % 2 === 0) mutable counterEven = i;
if (i % 5 === 0) mutable counterFives = i;
yield Promises.delay(1000, ++i);
}
}
Insert cell
mutable counterEven = 0
Insert cell
mutable counterFives = 0
Insert cell
Insert cell
Insert cell
Insert cell
reactiveWalls
Insert cell
viewof reactiveWalls = {
var c = DOM.context2d(w, h);
var ball = {x: w / 2, y: h / 2, r: 8, dx: 2, dy: 2};
var wall = null;
while (true) {
ball.x += ball.dx, ball.y += ball.dy;
c.fillStyle = "black";
c.fillRect(0, 0, w, h);
c.beginPath();
c.fillStyle = "red";
c.arc(ball.x, ball.y, ball.r, 0, 2 * Math.PI);
c.fill();
if (ball.x - ball.r < 0) wall = "left", ball.dx = 2;
if (ball.x + ball.r > w) wall = "right", ball.dx = -2;
if (ball.y - ball.r < 0) wall = "top", ball.dy = 2;
if (ball.y + ball.r > h) wall = "bottom", ball.dy = -2;
c.canvas.value = wall;
yield c.canvas;
}
}
Insert cell
Insert cell
mutable wall = null
Insert cell
mutableWalls = {
var c = DOM.context2d(w, h);
var ball = {x: w / 2, y: h / 2, r: 8, dx: -2, dy: -2};
while (true) {
ball.x += ball.dx, ball.y += ball.dy;
c.fillStyle = "black";
c.fillRect(0, 0, w, h);
c.beginPath();
c.fillStyle = "blue";
c.arc(ball.x, ball.y, ball.r, 0, 2 * Math.PI);
c.fill();
if (ball.x - ball.r < 0) mutable wall = "left", ball.dx = 2;
if (ball.x + ball.r > w) mutable wall = "right", ball.dx = -2;
if (ball.y - ball.r < 0) mutable wall = "top", ball.dy = 2;
if (ball.y + ball.r > h) mutable wall = "bottom", ball.dy = -2;
yield c.canvas;
}
}
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