Create a gist now

Instantly share code, notes, and snippets.

anonymous /SierpinskiCarpet Secret
Created Nov 24, 2015

What would you like to do?
//激重なのでリリースでの実行を推奨
# include <Siv3D.hpp>
void DrawCarpet(int left, int top, int size);
void Main()
{
Graphics::SetBackground(Palette::Black);
int size = Window::Width();
while (System::Update())
{
DrawCarpet(0, 0, size);
size *= 1.02;
if (size > Window::Width() * 3)size /= 3;
}
}
void DrawCarpet(int left, int top, int size){
//再帰的に白い正方形を描いていくだけ
Rect(left + size / 3, top + size / 3,size / 3,size / 3).draw(Palette::White);
if (size < 3)return;
DrawCarpet(left, top, size / 3);
if (size / 3 < Window::Width())
{
DrawCarpet(left + size / 3, top, size / 3);
DrawCarpet(left, top + size / 3, size / 3);
if (size * 2 / 3 < Window::Width())
{
DrawCarpet(left + size * 2 / 3, top, size / 3);
DrawCarpet(left + size * 2 / 3, top + size / 3, size / 3);
DrawCarpet(left, top + size * 2 / 3, size / 3);
DrawCarpet(left + size / 3, top + size * 2 / 3, size / 3);
DrawCarpet(left + size * 2 / 3, top + size * 2 / 3, size / 3);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment