Create a gist now

Instantly share code, notes, and snippets.

@Reputeless /GameOfLife.cpp Secret
Last active Dec 10, 2015

What would you like to do?
# include <Siv3D.hpp> // Siv3D June 2015 v2
void Main()
{
Graphics2D::SetSamplerState(SamplerState::ClampPoint);
Image img(128, 96, Color(0));
DynamicTexture tex;
for (auto& p : img)
p.r = Random(1);
while (System::Update())
{
for (auto b : step(img.size))
{
int s = 0;
for (auto d : step({ -1, -1 }, { 3, 3 }))
s += img.getPixel<ImageAddressMode::Wrap>(b.y + d.y, b.x + d.x).r;
auto& p = img[b.y][b.x];
p.b = (s == 3) || (p.r && s == 4);
}
tex.fill(img.forEach([](Color& p){p.g = (p.r = p.b) ? 255 : 0; }));
tex.scale(5).draw();
System::Sleep(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment