Published
Edited
Jul 24, 2018
2 stars
Insert cell
Insert cell
счёт = {
let i = 0;
while (true) yield Promises.delay(1000, ++i);
}
Insert cell
Insert cell
пара = счёт * 2
Insert cell
Insert cell
чёт = {
yield счёт % 2 === 0 ? счёт : this;
}
Insert cell
Insert cell
счётчик = {
let i = 0;
while (true) {
if (i % 2 === 0) mutable чётник = i;
if (i % 5 === 0) mutable пятка = i;
yield Promises.delay(1000, ++i);
}
}
Insert cell
mutable чётник = 0
Insert cell
mutable пятка = 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 = "лево", ball.dx = 2;
if (ball.x + ball.r > w) wall = "право", ball.dx = -2;
if (ball.y - ball.r < 0) wall = "верх", ball.dy = 2;
if (ball.y + ball.r > h) wall = "низ", 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 = "лево", ball.dx = 2;
if (ball.x + ball.r > w) mutable wall = "право", ball.dx = -2;
if (ball.y - ball.r < 0) mutable wall = "верх", ball.dy = 2;
if (ball.y + ball.r > h) mutable wall = "низ", ball.dy = -2;
yield c.canvas;
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more