# Concise way to draw this pyramid

I wrote the following to draw a pyramid, this approach uses functions TranslationTransform and Tuples, is there a way to do the same thing more concise? Maybe Table, Nest, ArrayPad is useful.

cubes = {
{c1 = Cuboid[]},
TranslationTransform[{##, -1}][c1] & @@@ Tuples[{-1, 1}/2, 2],
TranslationTransform[{##, -2}][c1] & @@@ Tuples[{-1, 0, 1}, 2],
TranslationTransform[{##, -3}][c1] & @@@ Tuples[{-3, -1, 1, 3}/2, 2],
TranslationTransform[{##, -4}][c1] & @@@ Tuples[{-2, -1, 0, 1, 2}, 2]
};
Graphics3D[cubes]


Thank you all.

• @DavidRicherby All right. May 31 '19 at 2:22

n = 5;
Graphics3D[Table[Cuboid[{#[[1]], #[[2]], -i}] & /@ Tuples[Range[-i/2, i/2], 2],
{i, 0, n - 1}]]


A more concise version (thanks: Vitaliy Kaurov):

Graphics3D[Table[Cuboid[{#, #2, -i}] & @@@ Tuples[Range[-i/2, i/2], 2], {i, 0, n - 1}]]

• NIce +1 ! For code-golf i'd pack this as Graphics3D[Table[Cuboid[{#1,#2,-i}]&@@@Tuples[Range[-i,i]/2,2], {i,0,4}]] ;-) I deleted my answer, it was essentially the same. May 30 '19 at 10:21
• Thank you @Vitaliy. Updated with you suggestion.
– kglr
May 30 '19 at 11:02

Inspired by @kglr, now I got another simpler way

Graphics3D[Table[Cuboid[{x,y,-z}],{z,0,4},{y,-z/2,z/2},{x,-z/2,z/2}]]


or

Graphics3D[Table[{Cuboid[{x-z/2,y-z/2,-z}]},{z,5},{y,z},{x,z}]]


Not concise

n = 7;

Standardize[GraphEmbedding@GridGraph@#, Mean, 1&] & /@ Array[{#,#}&, n] //
Cuboid /@ Join@@MapIndexed[Append[#1, - First@#2 +.5]&, #, {2}] & // Graphics3D


but fun to play with:

 n = 20;

Standardize[ #(CycleGraph@#~GraphEmbedding~"CircularEmbedding"), Mean, 1&] & /@ Array[#&, n] //
Ball /@ Join@@MapIndexed[Append[#1, - 1.5 First@#2 +.5]&, #, {2}] & // Graphics3D