-
-
Save anonymous/cd0c161daa0909b860fb to your computer and use it in GitHub Desktop.
This file contains 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
# include <Siv3D.hpp> | |
void Main() | |
{ | |
unsigned char rule = 30;//ルール | |
int width = 100;//横幅 | |
int height = 100;//表示する世代の数 | |
Grid<int> cells(width,height);//1か0を格納する | |
Graphics::SetBackground(Palette::Gray); | |
while (System::Update()) | |
{ | |
//オートマトンの更新 | |
//下側から更新することによって下の段に影響を波及させずに1フレームで1世代ずつ更新させる | |
for (int y = height - 1; y >= 1; y--) | |
{ | |
for (int x = 0; x < width; x++) | |
{ | |
int state = cells[y - 1][(x + width - 1) % width] * 4 + | |
cells[y - 1][x] * 2 + | |
cells[y - 1][(x + 1) % width]; | |
cells[y][x] = (rule >> state) & 1; | |
} | |
} | |
int dotSize = Window::Width() / width; | |
for (auto p : step({width, height })) | |
{ | |
Rect rect(p * dotSize, dotSize , dotSize ); | |
if (p.y == 0) | |
{ | |
rect.w--; | |
rect.h--; | |
} | |
if (rect.leftClicked & p.y == 0) | |
{ | |
cells[p.y][p.x] = 1 - cells[p.y][p.x]; | |
} | |
if (cells[p.y][p.x])rect.draw(Palette::Black); | |
else rect.draw(Palette::White); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment