三すくみ
二次元テーブルに (0, 1, 2) をランダムに配置して
三すくみで(じゃんけんの関係のように)侵食
- 隣り合う2つのセルをランダムに選んで
- 0 の隣が 1 だったら 1 を 0 にする。
- 1 の隣が 2 だったら 2 を 1 にする。
- 2 の隣が 0 だったら 0 を 2 にする。
というのを繰り返す。
定期的に画像に保存する。
- 色
- 0 ⇒ シアン
- 1 ⇒ マゼンタ
- 2 ⇒ 黄色
保存した画像を(ちょっと拡大して)繋げて動画にすると...
http://stackprobe.ccsp.mydns.jp:58946/_rosetta/Hatena/20191031/Movie.mp4
CMYDispute()
public void CMYDispute() { Random rand = new Random(); const int w = 100; const int h = 100; int[,] map = new int[w, h]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { map[x, y] = rand.Next(3); } } for (int c = 0; c < 600; c++) { for (int d = 0; d < w * h; d++) { int x1 = rand.Next(w); int x2 = x1; int y1 = rand.Next(h); int y2 = y1; if (rand.Next(2) == 0) x2 = (x2 + 1) % w; else y2 = (y2 + 1) % h; if (map[x1, y1] == (map[x2, y2] + 1) % 3) map[x1, y1] = map[x2, y2]; else map[x2, y2] = map[x1, y1]; } using (Bitmap bmp = new Bitmap(w, h)) { Color[] colors = new Color[] { Color.Cyan, Color.Magenta, Color.Yellow, }; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { bmp.SetPixel(x, y, colors[map[x, y]]); } } bmp.Save(string.Format(@"C:\temp\{0}.bmp", c.ToString("D4"))); // 適当な場所にビットマップで保存 } } }