Published
Edited
Apr 30, 2021
8 stars
Insert cell
Insert cell
Insert cell
viewof Motion = {
const bthread = checkbox({
label: 'Motion',
value: function*() {
while (true) {
this.requestFrame('circleFrame');
yield { wait: 'circleFrame' };
yield { request: 'takeStep' };
this.x = calcNextX();
}
}
});
return bthread;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof OvercomeObstacle = checkbox({
label:
"<b>OvercomeObstacle.</b> This bthread blocks a specific motion when it signals the obstacle.",
value: function* () {
while (true) {
if (touches(this.x, this.y)) {
yield { wait: "frame", block: "moveDown" };
} else if (this.y < 0 && !touches(this.x, this.y)) {
yield { wait: "frame", block: "moveUp" };
} else {
yield { wait: "frame", block: ["moveDown", "moveUp"] };
}
}
},
defaultValue: true
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof GoRandomly = checkbox({
label: '<b>GoRandomly</b>. This bthread blocks at random a direction.',
value: function*() {
const possibleEventsToBlock = ['Up', 'Down', ['Up', 'Down'], 'Right'];

while (true) {
const randomEventToBlock =
possibleEventsToBlock[
Math.floor(Math.random() * possibleEventsToBlock.length)
];
yield { wait: 'frame', block: randomEventToBlock };
}
},
})
Insert cell
Insert cell
Insert cell
viewof Corridor = checkbox({
label: '<b>Corridor</b>.',
value: function*() {
while (true) {
yield {
wait: 'frame',
block: event => {
let circle = { radius: radius };
if (event.type === 'Up') {
circle.x = this.x;
circle.y = this.y - 2;
} else if (event.type === 'Right') {
circle.x = this.x + 2;
circle.y = this.y;
} else if (event.type === 'Down') {
circle.x = this.x;
circle.y = this.y + 2;
}

if (this.lines.find(line => collisionCircleLine(circle, line))) {
return true;
}
}
};
}
}
})
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

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