Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create an array with 1s around the perimeter
ResourceFunction["PerimeterMaskArray"][dims,r] creates an array of dimensions dims where cells within r cells of the border are 1, and all other cells are 0. | |
ResourceFunction["PerimeterMaskArray"][dims] creates an array where only border cells are 1, else 0. |
In[1]:= | ![]() |
Out[1]= | ![]() |
In[2]:= | ![]() |
Out[2]= | ![]() |
Create a 10×10 perimeter mask array with border radius 1:
In[3]:= | ![]() |
Out[3]= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
Create a 20×40 perimeter mask array with border radius 5:
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
Create a 3D perimeter mask array:
In[7]:= | ![]() |
Out[7]= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
When r<1, the resulting array will be all zeros:
In[9]:= | ![]() |
Out[9]= | ![]() |
When r>=(dimi/2), the resulting array will be all ones:
In[10]:= | ![]() |
Out[10]= | ![]() |
PerimeterMaskArray will fail if provided non-integer dimensions:
In[11]:= | ![]() |
Out[11]= | ![]() |
PerimeterMaskArray will fail if provided non-positive dimensions:
In[12]:= | ![]() |
Out[12]= | ![]() |
Use PerimeterMaskArray to set up and run a fixed boundary 1D cellular automaton simulation:
In[13]:= | ![]() |
Out[13]= | ![]() |
Use PerimeterMaskArray to set up and run a fixed boundary 2D cellular automaton simulation:
In[14]:= | ![]() |
Out[14]= | ![]() |
Interpret a square perimeter mask array as a graph adjacency matrix:
In[15]:= | ![]() |
Out[15]= | ![]() |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License