4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++/OpenSiv3D で 10 行ライフゲーム

Last updated at Posted at 2018-07-08

OpenSiv3Dでライフゲームを 10 LOC で書く方法
20180708-145419-291.png

Main
# include <Siv3D.hpp> // OpenSiv3D v0.2.7

void Main()
{
	Image i(Window::Size(), Arg::generator = []() { return Color(0, 0, Random(0, 1)); });
	DynamicTexture t(i);
	Array<Point> n = { { { -1,-1 },{ 0, -1 },{ 1, -1 },{ -1, 0 },{ 1,0 },{ -1, 1 },{ 0, 1 },{ 1,1 } } };

	while (System::Update())
	{
		for (auto p : step(Point(1, 1), i.size() - Point(2, 2)))
			i[p].r = (6152 >> i[p].b * 9 + n.count_if([&](auto v) { return i[p + v].b; })) & 1;

		t.fill(i.forEach([](auto& c) { c = c.r ? Color(0, 255, 1) : Color(0); }));
		t.draw();
	}
}
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?