Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rossant committed Mar 13, 2024
1 parent e7cf24a commit aab4f2c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
39 changes: 20 additions & 19 deletions data/listings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"bgcolor": null,
"text": "Hi!"
},
"0,8": {
"bgcolor": null,
"text": "🍎"
},
"0,9": {
"bgcolor": [
80,
Expand Down Expand Up @@ -324,10 +328,6 @@
],
"text": ""
},
"7,8": {
"bgcolor": null,
"text": "🍎"
},
"7,9": {
"bgcolor": [
80,
Expand Down Expand Up @@ -3022,24 +3022,26 @@
"code": "import numpy as np\n\nn = 15\nsize(n, n)\n\n# Game of life implementation with NumPy.\ndef count_neighbors(X):\n n = X.shape[0]\n neighbor_count = np.zeros_like(X, dtype=np.int32)\n for i in range(n):\n for j in range(n):\n neighbors_i = [(i - 1) % n, i, (i + 1) % n]\n neighbors_j = [(j - 1) % n, j, (j + 1) % n]\n neighbor_count[i, j] = np.sum(X[neighbors_i, :][:, neighbors_j]) - X[i, j]\n return neighbor_count\n\ndef next_generation(X):\n neighbor_count = count_neighbors(X)\n new_grid = np.zeros_like(X)\n new_grid[(X) & (neighbor_count < 2)] = 0\n new_grid[(X) & ((neighbor_count == 2) | (neighbor_count == 3))] = 1\n new_grid[(X) & (neighbor_count > 3)] = 0\n new_grid[(~X) & (neighbor_count == 3)] = 1\n return new_grid\n\ndef show_grid(X):\n clear()\n for i in range(n):\n for j in range(n):\n if X[i, j]: color(i, j, black)\n\n# Initial conditions.\nA = np.zeros((n, n), dtype=bool)\nglider = np.array([[0, 1, 0],\n [0, 0, 1],\n [1, 1, 1]])\nA[:3, :3] = glider\nA[2:5, 5:8] = glider\nA[4:7, 10:13] = glider\nA[8:11, 2:5] = glider\n\n# Animation.\ninterval = .02\n\ndef frame(idx):\n global A\n A = next_generation(A)\n show_grid(A)\n\nshow_grid(A)\n",
"lang": "fr",
"data": {
"rows": 15,
"cols": 15,
"cells": {
"1,2": {
"1,1": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"2,0": {
"2,2": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"2,2": {
"2,3": {
"bgcolor": [
0,
0,
Expand All @@ -3063,23 +3065,23 @@
],
"text": ""
},
"3,7": {
"3,6": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"4,5": {
"4,7": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"4,7": {
"4,8": {
"bgcolor": [
0,
0,
Expand All @@ -3103,23 +3105,23 @@
],
"text": ""
},
"5,12": {
"5,11": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"6,10": {
"6,12": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"6,12": {
"6,13": {
"bgcolor": [
0,
0,
Expand All @@ -3143,23 +3145,23 @@
],
"text": ""
},
"9,4": {
"9,3": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"10,2": {
"10,4": {
"bgcolor": [
0,
0,
0
],
"text": ""
},
"10,4": {
"10,5": {
"bgcolor": [
0,
0,
Expand All @@ -3184,8 +3186,7 @@
"text": ""
}
},
"rows": 15,
"cols": 15
"fontSize": "calc((-250px + 30vh + 30vw) / 30)"
}
},
"5. 🐰 Bunny": {
Expand All @@ -3197,7 +3198,7 @@
"rows": 7,
"cols": 7,
"cells": {
"0,5": {
"1,3": {
"bgcolor": null,
"text": "🐰"
},
Expand Down
1 change: 1 addition & 0 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class App {
init() {
this.model.init().then(async () => {
this.selector.init();
await this.runner.init();
});
}
};
6 changes: 6 additions & 0 deletions scripts/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ class Runner {
}

async init() {
// Start the spinning cursor.
this.dispatcher.spinning(this, true);

this.pyodide = await loadPyodide();
this.pyodide.setStdout({
batched: (text) => {
this.stdout(text);
}
});

// Stop the spinning cursor.
this.dispatcher.spinning(this, false);
}

/* Setup functions */
Expand Down
6 changes: 4 additions & 2 deletions scripts/spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class Spinner {
}

setSpinning(isSpinning) {
if (isSpinning)
if (isSpinning) {
document.body.classList.add('waiting');
else
}
else {
document.body.classList.remove('waiting');
}
}

setupDispatcher() {
Expand Down
2 changes: 1 addition & 1 deletion styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ emoji-picker.visible {
#credits * {
color: #999;
font-size: 9pt;
max-height: 20px;
max-height: 30px;
padding: 0;
margin: 0;
}
Expand Down

0 comments on commit aab4f2c

Please sign in to comment.