砂遊び
#InteractiveArt #VisualAlgorithm #ca
砂遊び=セルオートマトンの一種というか呼び方の違いというか。
近傍の状態によって、ピクセルの状態を変えるアルゴリズム
Falling-sand game
https://en.wikipedia.org/wiki/Falling-sand_game
https://maxbittker.com/making-sandspiel 解説
サンプルコード
https://zenn.dev/baroqueengine/books/a19140f2d9fc1a/viewer/d01773
code:sand.js
function fall(x, y) {
const cur = getPixel(x, y);
if (!colorCompare(cur, Color.Sand)) {
return;//sand以外は何もしない
}
if (canvas.height - 1 <= y) {
setPixel(x, y, Color.None);//画面一番下
} else if (colorCompare(getPixel(x, y + 1), Color.None)) {
//下に何にもなかったら
setPixel(x, y + 1, cur);//下と交換する
setPixel(x, y, Color.None);//下と交換する
} else {
//下に何かあったら
//ランダムで、左右にいくつかうごして、交換
const tx = x + floor(random(-4, 4));
if (colorCompare(getPixel(tx, y), Color.None)) {//何もなかった、ときだけ
setPixel(x, y, Color.None);
setPixel(tx, y, Color.Sand);
}
//何もしない
}
}
例
すごいやつ
https://sandspiel.club/
https://studio.sandspiel.club/
https://github.com/maxbittker/sandspiel
https://maxbittker.com/making-sandspiel 解説
unity asset storeで
https://assetstore.unity.com/ja-JP/search#q=sand
https://kamgam.com/unity/SandGameDemos/WebGLDemo/index.html
https://androdome.com/Sand/
https://www.youtube.com/watch?v=5Ka3tbbT-9E
bakuくん作。
https://baku89.com/2014/12/22/three-js-ca
https://px.baku89.com/fuse/27 https://px.baku89.com
https://github.com/baku89/PXCA
https://github.com/m4ym4y/falling-sand-shader?tab=readme-ov-file
他と比較する
GoL系との違い
砂の場合、下のピクセルが空気だったら入れ替えswapping
植物の場合、上のピクセルが空いていたら自己複製
GoLの場合、(周囲の個数で)(0/1)ごとに状態変化のルール
1Dセルオートマトンの場合
常に上の3ピクセルをチェック
3ピクセルの状況で、自分が決まる
ラングトンのアリの場合
エージェントがいて、セルの状況で移動方向が変化、セルにも影響
砂遊び(セルオートマトン)が一般化されたツール
https://studio.sandspiel.club/
使い方
https://www.youtube.com/watch?v=ecCVor7mJ6o
砂
下が、空気か水であれば、
下と入れ替える。
斜め右下が空気であれば
斜め右下と入れ替え
https://gyazo.com/33b382548015b72e155d61adc5588d58 
水
https://gyazo.com/07af372e61e82705c1131445825dd14e