Skip to content

Instantly share code, notes, and snippets.

@shutosg
Created February 16, 2018 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shutosg/4752771c595e18850b4eddd875ca4dfc to your computer and use it in GitHub Desktop.
Save shutosg/4752771c595e18850b4eddd875ca4dfc to your computer and use it in GitHub Desktop.
void Menger(PVector centerPosition, float sideWidth)
{
rect(centerPosition.x - sideWidth / 6, centerPosition.y - sideWidth / 6,
sideWidth/3, sideWidth/3);
if(sideWidth < 3) return;
for(int i=-1; i<2; i++)
{
for(int j=-1; j<2; j++)
{
if(i==0 && j==0) continue;
Menger(
new PVector(centerPosition.x + j * sideWidth / 3,
centerPosition.y + i * sideWidth / 3),
sideWidth / 3
);
}
}
}
void setup()
{
size(800, 800);
background(0);
fill(255);
noStroke();
rect(0, 0, width, height);
fill(100);
Menger(new PVector(width/2, height/2), width);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment