Skip to content

Instantly share code, notes, and snippets.

@butchi
Last active December 15, 2015 21:52
Show Gist options
  • Save butchi/59d10ab09c140e476c75 to your computer and use it in GitHub Desktop.
Save butchi/59d10ab09c140e476c75 to your computer and use it in GitHub Desktop.
シェルピンスキーのカーペット(Mathematicaショートフラクタルシリーズ) ref: http://qiita.com/butchi_y/items/3b164bb8e25dad7763cc
sierpinskiCarpet[x_] := ArrayFlatten[x /. {
0 -> {
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
},
1 -> {
{1, 1, 1},
{1, 0, 1},
{1, 1, 1}
}
}]
ArrayPlot[Nest[sierpinskiCarpet, 1, 5], PixelConstrained -> 1, Frame -> False]
In[1] = sierpinskiCarpet[1]
Out[1] = {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}
1 -> {
{1, 1, 1},
{1, 0, 1},
{1, 1, 1}
}
In[2] = sierpinskiCarpet[sierpinskiCarpet[1]]
Out[2] = {{1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 1, 1, 0, 1, 1, 0, 1}, {1, 1, 1,
1, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 1, 1, 1}, {1, 0, 1, 0, 0, 0,
1, 0, 1}, {1, 1, 1, 0, 0, 0, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1,
1}, {1, 0, 1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1}}
ArrayPlot[sierpinskiCarpet[sierpinskiCarpet[1]]]
{{{{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}, {{1, 1, 1}, {1, 0, 1}, {1, 1,
1}}, {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}}, {{{1, 1, 1}, {1, 0,
1}, {1, 1, 1}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{1, 1, 1}, {1,
0, 1}, {1, 1, 1}}}, {{{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}, {{1, 1,
1}, {1, 0, 1}, {1, 1, 1}}, {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}}}}
ArrayPlot[Nest[ArrayFlatten[#/.{0->ConstantArray[0,{3,3}],1->{{1,1,1},{1,0,1},{1,1,1}}}]&,1,5]]
ArrayPlot[
Nest[
ArrayFlatten[
#/.{
0 -> ConstantArray[0,{3,3}],
1 -> {{1,1,1},{1,0,1},{1,1,1}}
}
]&,
1,
5
],
PixelConstrained->1,
Frame->False
]
Graphics[Raster[Nest[
ArrayFlatten[
#/.{
1 -> ConstantArray[1,{3,3}],
0 -> {{0,0,0},{0,1,0},{0,0,0}}
}
]&,
0,
5
]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment