Conversation
Contributor
|
コードをリロードしたときはコードがすべて読み込み直されるので、毎回 //変数設定
let boardSize = 20; //盤面の大きさ(20x20)
const cellSize = 500 / boardSize; |
Contributor
|
編集可能性を上げるために、スタイルの確定を一箇所にまとめてやるといいと思う function getStyle(cell) {
return cell ? "black" : "white";
} |
Contributor
|
結局やってることとしては DOM 要素を使いまわしてるということなので、初期化と更新は完全に別の処理として、 function rerender() {
for (let i = 0; i < boardSize; i++) {
for (let j = 0; j < boardSize; j++)
const nextColor = board[i][j] ? "black" : "white";
const el = table.children[i].children[j].children[
if (el.style.backgroundColor != nextColor)
el.style.backgroundColor = nextColor;
}
}
}
}というように書いてやるのがシンプルかも! |
Deploying life-code with
|
| Latest commit: |
a6c1e2d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://df4ae507.life-code.pages.dev |
| Branch Preview URL: | https://performance-improvement.life-code.pages.dev |
aster-void
reviewed
Nov 13, 2025
src/iframe/life-game.js
Outdated
| function getStyle(cell) { | ||
| return cell ? "black" : "white"; | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
これは編集しやすいように上の方で定義してやるのがよいと思う
aster-void
reviewed
Nov 13, 2025
src/iframe/life-game.js
Outdated
| let boardSize = 20; //盤面の大きさ(20x20) | ||
| let cellScale = 1.0; //セルの大きさの倍率 | ||
|
|
||
| let cellSize = Math.floor(cellScale * DEFAULT_CELL_SIZE * (DEFAULT_BOARD_SIZE / boardSize)); //セルの大きさ(px) |
Contributor
Author
There was a problem hiding this comment.
cellSizeを直接いじられるとiframe内に収めるための自動調整(DEFAULT_CELL_SIZE * (DEFAULT_BOARD_SIZE / boardSize))と衝突しちゃうのでできるだけcellScaleをいじってほしいな、という感じの実装です。
cellScaleをいじるだけなら盤面がはみ出さないようになってます。
Contributor
There was a problem hiding this comment.
そっちではなく、 DEFAULT_BOARD_SIZE とDEFAULT_CELL_SIZE が必要でないんでない?という話
cellScale もいじられると自動調整がうまく働かなくなりそうなので、 iframe の許容横幅 (コード例では500) から直接計算するのが良さそう
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
・ボードの差分のみが更新されるように変更
・セルサイズが更新されないバグの修正
・ユーザーが変更できる変数をcellSizeそのものでなくcellScaleに変更(boardSizeの変更に伴うcellSizeの自動更新とユーザーによる入力の衝突の回避)