Advertisement
Matthen

Cube Spin

Jan 13th, 2014
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. AddCube[cubes_] := Module[{chosen, chosendir},
  2. chosen = RandomChoice[cubes];
  3. chosendir =
  4. RandomChoice[{-1,
  5. 1}] RandomChoice[{{0, 0, 1}, {0, 1, 0}, {1, 0, 0}}];
  6. Union[Join[cubes, {chosen + chosendir}]]
  7. ];
  8. cs = "DarkRainbow";
  9. face1[p_, \[Theta]_] :=
  10. Map[(p + RotationMatrix[\[Theta], {1, 0, 0}].#) &, {{0, 0, 0}, {1,
  11. 0, 0}, {1, 1, 0}, {0, 1, 0}}];
  12. face2[p_, \[Theta]_] :=
  13. Map[(p + RotationMatrix[\[Theta], {0, 1, 0}].#) &, {{0, 0, 0}, {0,
  14. 0, 1}, {0, 1, 1}, {0, 1, 0}}];
  15. face3[p_, \[Theta]_] :=
  16. Map[(p + RotationMatrix[\[Theta], {0, 0, 1}].#) &, {{0, 0, 0}, {1,
  17. 0, 0}, {1, 0, 1}, {0, 0, 1}}];
  18. cuboid[cube_, \[Theta]_] :=
  19. Module[{f1 = face1[cube, \[Theta]], f2 = face2[cube, \[Theta]],
  20. f3 = face3[cube, \[Theta]]},
  21. {
  22. {Glow@ColorData[cs][1/3], Polygon[{f1}]},
  23. {Glow@ColorData[cs][2/3], Polygon[{f2}]},
  24. {Glow@ColorData[cs][3/3], Polygon[{f3}]}
  25. }
  26. ];
  27. frame[\[Theta]_] :=
  28. Graphics3D[
  29. {Black, EdgeForm[],
  30. Table[
  31. cuboid[cube, \[Theta]]
  32. , {cube, cubes}]
  33. }
  34. , Lighting -> "Neutral", ViewPoint -> -1000 {1.2, 1.2, 1},
  35. Boxed -> False, PlotRange -> All, ImageSize -> {300, 300}];
  36. cubes = Nest[AddCube, {{0, 0, 0}}, 200];
  37. Manipulate[frame[t],{t,0,2 Pi}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement