Cell[CellGroupData[{Cell[BoxData[ RowBox[{ RowBox[{"pad", "[", "m_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"PadRight", "[", RowBox[{ RowBox[{"PadLeft", "[", RowBox[{"m", ",", RowBox[{"#1", "+", "#2"}], ",", "#2"}], "]"}], ",", RowBox[{"#1", "+", RowBox[{"2", "#2"}]}], ",", "#2"}], "]"}], "&"}], "[", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}], RowBox[{"Length", "[", "m", "]"}]}], ",", RowBox[{"1", "+", RowBox[{"Max", "[", "m", "]"}]}]}], "]"}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{3.35696210375764*^9, 3.375489820750226*^9, 3.7607289012965107`*^9}, CellID->2066495603], Cell[BoxData[ RowBox[{ RowBox[{"squarepts", "[", RowBox[{"p_", ",", "d_"}], "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"p", "+", "#"}], "&"}], "/@", RowBox[{"(", RowBox[{"d", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", RowBox[{"-", "1"}]}], "}"}]}], "}"}]}], ")"}]}]}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, InitializationCell->True, CellChangeTimes->{3.760728901296627*^9}, CellID->338576690], Cell[BoxData[ RowBox[{"Manipulate", "[", RowBox[{ RowBox[{"ArrayPlot", "[", RowBox[{ RowBox[{ RowBox[{"Nest", "[", RowBox[{"pad", ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}], "}"}], ",", RowBox[{"zz", "-", "1"}]}], "]"}], "/", RowBox[{"(", " ", "zz", ")"}]}], ",", RowBox[{"Mesh", "->", "mes"}], ",", RowBox[{"MeshStyle", "->", "White"}], ",", RowBox[{"ColorFunctionScaling", "->", "False"}], ",", RowBox[{"ColorFunction", "->", RowBox[{"(", RowBox[{ RowBox[{"Hue", "[", RowBox[{"#", ",", RowBox[{"1", "/", "2"}], ",", "1"}], "]"}], "&"}], ")"}]}], ",", RowBox[{"Epilog", "->", RowBox[{"If", "[", RowBox[{"mes", ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", " ", RowBox[{ RowBox[{"Line", "[", RowBox[{"squarepts", "[", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], "+", RowBox[{"Total", "[", RowBox[{"Range", "[", "zz", "]"}], "]"}]}], ",", RowBox[{"z", "/", "2"}]}], "]"}], "]"}], ",", RowBox[{"Line", "[", RowBox[{"squarepts", "[", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"x", ",", "y"}], "}"}], "+", RowBox[{"Total", "[", RowBox[{"Range", "[", "zz", "]"}], "]"}]}], ",", RowBox[{"z", "/", "2"}]}], "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{ RowBox[{"-", RowBox[{"Total", "[", RowBox[{"Range", "[", "z", "]"}], "]"}]}], "+", RowBox[{"z", "/", "2"}]}], ",", RowBox[{ RowBox[{ RowBox[{"-", "z"}], "/", "2"}], "+", RowBox[{"Total", "[", RowBox[{"Range", "[", "z", "]"}], "]"}]}], ",", "z"}], "}"}], ",", RowBox[{"{", RowBox[{"y", ",", RowBox[{ RowBox[{"-", RowBox[{"Total", "[", RowBox[{"Range", "[", "z", "]"}], "]"}]}], "+", RowBox[{"z", "/", "2"}]}], ",", RowBox[{ RowBox[{ RowBox[{"-", "z"}], "/", "2"}], "+", RowBox[{"Total", "[", RowBox[{"Range", "[", "z", "]"}], "]"}]}], ",", "z"}], "}"}]}], "]"}], ",", RowBox[{"{", RowBox[{"z", ",", "zz", ",", "1", ",", RowBox[{"-", "1"}]}], "}"}]}], "]"}], ",", RowBox[{"{", "}"}]}], "]"}]}], ",", RowBox[{"PlotLabel", "->", RowBox[{"Grid", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"2", " ", "*", RowBox[{"Total", "[", RowBox[{"Range", "[", "zz", "]"}], "]"}]}], ",", "\"\\"", ",", RowBox[{"Row", "[", RowBox[{"Riffle", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{"zz", ",", RowBox[{"{", RowBox[{"zz", "+", "1"}], "}"}]}], "]"}], ",", "\"\< + \>\""}], "]"}], "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"2", " ", "*", RowBox[{"Total", "[", RowBox[{"Range", "[", "zz", "]"}], "]"}]}], ",", "\"\\"", ",", RowBox[{"Row", "[", RowBox[{"Riffle", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{ RowBox[{"Reverse", "[", RowBox[{"Range", "[", "zz", "]"}], "]"}], ",", RowBox[{"Range", "[", "zz", "]"}]}], "]"}], ",", "\"\< + \>\""}], "]"}], "]"}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"4", RowBox[{"(", RowBox[{"Total", "[", RowBox[{ RowBox[{"Range", "[", "zz", "]"}], "^", "3"}], "]"}], ")"}]}], ",", "\"\\"", ",", RowBox[{"Grid", "[", RowBox[{"Table", "[", RowBox[{ RowBox[{"Riffle", "[", RowBox[{ RowBox[{ RowBox[{"Range", "[", "zz", "]"}], "^", "3"}], ",", "\"\<+\>\""}], "]"}], ",", RowBox[{"{", "4", "}"}]}], "]"}], "]"}]}], "}"}]}], "}"}], ",", RowBox[{"BaseStyle", "->", "\"\\""}]}], "]"}]}]}], "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"zz", ",", "2", ",", "\"\\""}], "}"}], ",", "1", ",", "6", ",", "1", ",", RowBox[{"Appearance", "->", "\"\\""}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"mes", ",", "True", ",", "\"\\""}], "}"}], ",", RowBox[{"{", RowBox[{"False", ",", "True"}], "}"}]}], "}"}], ",", " ", RowBox[{"SaveDefinitions", "->", "True"}]}], "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{ 3.35757176568782*^9, {3.36923182557301*^9, 3.36923183298958*^9}, 3.36937940170145*^9, 3.36938067565753*^9, {3.3709048062174873`*^9, 3.37090486206066*^9}, {3.370904911439968*^9, 3.3709049527896214`*^9}, {3.370905050520063*^9, 3.370905064109676*^9}, {3.370905139117625*^9, 3.3709051851882877`*^9}, {3.3709052571019697`*^9, 3.370905340097289*^9}, {3.370905400266094*^9, 3.3709054191982927`*^9}, {3.370906693272941*^9, 3.370906697473196*^9}, 3.3709068103867493`*^9, { 3.3710695573150883`*^9, 3.371069583248221*^9}, 3.371077599945698*^9, 3.371592579615781*^9, {3.371592631662272*^9, 3.371592637166875*^9}, {3.371983942422117*^9, 3.371983967630344*^9}, {3.372116851379757*^9, 3.3721168579192963`*^9}, {3.372907841771763*^9, 3.372907843684291*^9}, 3.372967399259552*^9, {3.373862712980719*^9, 3.3738627653028793`*^9}, {3.373862802213633*^9, 3.373862827318376*^9}, {3.375489831361558*^9, 3.375489834635807*^9}, {3.3857534433086977`*^9, 3.3857534566278496`*^9}, {3.3859848555758295`*^9, 3.3859848605444837`*^9}, 3.760728901287643*^9}, CellID->1496021318], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`mes$$ = True, $CellContext`zz$$ = 2, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`zz$$], 2, "step"}, 1, 6, 1}, {{ Hold[$CellContext`mes$$], True, "mesh"}, {False, True}}}, Typeset`size$$ = {360., {228., 232.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = False, $CellContext`zz$1227$$ = 0, $CellContext`mes$1228$$ = False}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`mes$$ = True, $CellContext`zz$$ = 2}, "ControllerVariables" :> { Hold[$CellContext`zz$$, $CellContext`zz$1227$$, 0], Hold[$CellContext`mes$$, $CellContext`mes$1228$$, False]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> ArrayPlot[ Nest[$CellContext`pad, {{1, 1}, {1, 1}}, $CellContext`zz$$ - 1]/$CellContext`zz$$, Mesh -> $CellContext`mes$$, MeshStyle -> White, ColorFunctionScaling -> False, ColorFunction -> (Hue[#, 1/2, 1]& ), Epilog -> If[$CellContext`mes$$, Table[ Table[{ Line[ $CellContext`squarepts[{$CellContext`x, $CellContext`y} + Total[ Range[$CellContext`zz$$]], $CellContext`z/2]], Line[ $CellContext`squarepts[{$CellContext`x, $CellContext`y} + Total[ Range[$CellContext`zz$$]], $CellContext`z/ 2]]}, {$CellContext`x, -Total[ Range[$CellContext`z]] + $CellContext`z/ 2, (-$CellContext`z)/2 + Total[ Range[$CellContext`z]], $CellContext`z}, \ {$CellContext`y, -Total[ Range[$CellContext`z]] + $CellContext`z/ 2, (-$CellContext`z)/2 + Total[ Range[$CellContext`z]], $CellContext`z}], \ {$CellContext`z, $CellContext`zz$$, 1, -1}], {}], PlotLabel -> Grid[{{2 Total[ Range[$CellContext`zz$$]], "side", Row[ Riffle[ Table[$CellContext`zz$$, {$CellContext`zz$$ + 1}], " + "]]}, {2 Total[ Range[$CellContext`zz$$]], "side", Row[ Riffle[ Join[ Reverse[ Range[$CellContext`zz$$]], Range[$CellContext`zz$$]], " + "]]}, { 4 Total[Range[$CellContext`zz$$]^3], "area", Grid[ Table[ Riffle[Range[$CellContext`zz$$]^3, "+"], {4}]]}}, BaseStyle -> "Menu"]], "Specifications" :> {{{$CellContext`zz$$, 2, "step"}, 1, 6, 1, Appearance -> "Labeled"}, {{$CellContext`mes$$, True, "mesh"}, { False, True}}}, "Options" :> {}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{405., {284., 290.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, Initialization:>({$CellContext`pad[ Pattern[$CellContext`m, Blank[]]] := (PadRight[ PadLeft[$CellContext`m, # + #2, #2], # + 2 #2, #2]& )[{1, 1} Length[$CellContext`m], 1 + Max[$CellContext`m]], $CellContext`squarepts[ Pattern[$CellContext`p, Blank[]], Pattern[$CellContext`d, Blank[]]] := Map[$CellContext`p + #& , $CellContext`d {{-1, -1}, {-1, 1}, { 1, 1}, {1, -1}, {-1, -1}}]}; Typeset`initDone$$ = True), SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{3.35696210375764*^9, 3.38598497349544*^9, 3.7607289012879057`*^9}, CellID->340142867] }, {4}]]