2
$\begingroup$

I am trying to align (colored) Cuboids within a cube, but the automatically coordinate generation "Row-2.)" is currently buggy. Can somebody help me please (the variable bound should be the start and define the cube-Length)!

1.) bound = 2;
2.) cb = IntegerDigits[Range[#], 10, 3] &[bound]
3.) Graphics3D[{Yellow, Cuboid[{0, 0, 0}], Blue, Table[Cuboid[cb[[i]]], {i, 1, 2^bound - 1, 1}]}, Boxed -> False]

By the way, how can I (automatically) fill each iteration with a different color ?

For example:

Cube-Iteration-1: Yellow (1 Cube)

Cube-Iteration-2: Blue (8 Cubes)

Cube-Iteration-3: Pink (27 Cubes)

...

enter image description here

$\endgroup$
4
$\begingroup$
cd = ColorData[3, "ColorList"]; 
cubes[iter_] := Graphics3D[ Table[{cd[[Mod[Max[i, j, k], Length@cd, 1]]], Cuboid[{i, j, k}]}, 
                                 {i, iter}, {j, iter}, {k, iter}], 
                            Boxed -> False, Axes -> False, Lighting -> {{"Ambient", White}}]

cubes[25]

Mathematica graphics

Alternatively:

cubes[i_] := Graphics3D[{ColorData[3, "ColorList"][[Max @@ #]], Cuboid@#} & /@  Tuples[Range@i, 3], 
                       Boxed -> False, Axes -> False, Lighting -> {{"Ambient", White}}]
$\endgroup$
5
$\begingroup$
m = {{{0}}};
m = Fold[
   ArrayPad[#, {{0, 1}, {0, 1}, {0, 1}}, #2] &,
   m,
   Range[9]
   ];

Graphics3D@Raster3D[m, ColorFunction -> (Blend["Rainbow", #/10.] &)]

enter image description here

$\endgroup$
  • $\begingroup$ Hey! No Cuboids! :) $\endgroup$ – Dr. belisarius Feb 12 '15 at 18:36
  • $\begingroup$ @belisarius I can see at least 3 :) $\endgroup$ – Kuba Feb 12 '15 at 18:42
4
$\begingroup$
Graphics3D[Table[{Hue[RandomReal[]], Cuboid[{i, j, k}]}, {i, 3}, {j, 3}, {k, 3}]]

enter image description here

Or if you wish to specify colors:

mycolors = {
   {{Red, Green, Blue}, {Yellow, Orange, Black}, {Purple, Pink, Green}},
   {{White, Blue, Yellow}, {Red, Black, Red}, {Pink, Pink, Black}},
   {{Yellow, Green, Yellow}, {Purple, Orange, White}, {Green, Pink, Green}}
   };
 Graphics3D[
 Table[{mycolors[[i, j, k]], Cuboid[{i, j, k}]},
  {i, 3}, {j, 3}, {k, 3}]]

enter image description here

Include Boxed->False if you want to delete the box.

If you want to define "stages" of colors:

mynewcolors = Table[
  Which[Max[i, j, k] == 1, Blue, 
        Max[i, j, k] == 2, Green, 
        Max[i, j, k] == 3, Yellow], 
{i, 3}, {j, 3}, {k, 3}]

enter image description here

And it looks cooler if you make the cuboids semi-transparent:

mynewcolors = Table[
   Which[Max[i, j, k] == 1, Purple, 
    Max[i, j, k] == 2, Red, 
    Max[i, j, k] == 3, Green, 
    Max[i, j, k] == 4, Yellow], 
   {i, 4}, {j, 4}, {k, 4}];
   Graphics3D[
       Table[{Opacity[0.5], mynewcolors[[i, j, k]], Cuboid[{i, j, k}]},
       {i, 4}, {j, 4}, {k, 4}], Boxed -> False]

enter image description here

$\endgroup$
4
$\begingroup$

A concise refactor of David's code:

Graphics3D[{
  Opacity[0.5], 
  Array[
    {Switch[Max[##], 1, Purple, 2, Red, 3, Green, 4, Yellow], Cuboid[{##}]} &,
    {4, 4, 4}
  ]
}]

enter image description here

$\endgroup$
  • $\begingroup$ Yes. Much cleaner. $\endgroup$ – David G. Stork Feb 12 '15 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.