iomikron

Prime Nebula - 3D_MathematicaCode

Feb 6th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. (*///////////////////////////////////////////////////////////////////*)
  2. (* Prime Nebula 3D - iomikron.tumblr.com *)
  3. (*///////////////////////////////////////////////////////////////////*)
  4. (* this is a list of primes *)
  5. primes = Table[Prime[i], {i, 5, 3000}];
  6.  
  7. (* this is the initial point*)
  8. p3 = {0, 0, 0};
  9.  
  10. (* list for the points'coordinates storage *)
  11. mList = {};
  12.  
  13. (* list for the points' colours *)
  14. cList = {};
  15.  
  16. (* lis for the main transition steps *)
  17. possibleSteps = {{0, 0, 1}, {0, 0, -1}, {1, 0, 0}, {-1, 0, 0}, {0, 1,
  18. 0}, {0, -1, 0}};
  19.  
  20. length = Length[primes];
  21. (* main loop *)
  22. Do[
  23. pos = 0;
  24. counter = primes[[iterator]];
  25. y = Mod[counter, 7];
  26. (* add the transition step to the current position *)
  27. p3 = p3 + possibleSteps[[y]];
  28. (* check if the current position is overwritten *)
  29. If[Length[Union[mList, {p3}]] == Length[mList],
  30. (* TRUE - store the point in mList *)
  31. pos =
  32. Flatten[Position[mList, p3]][[1]];
  33. (* TRUE - store the colour of the point in cList*)
  34. cList =
  35. ReplacePart[cList,
  36. pos -> 0.01 + cList[[pos]]
  37. ],
  38. (* FALSE - set a new element in clist *)
  39. cList = Append[cList, 0];
  40. (* FALSE - set a the new point in the mList *)
  41. mList = Append[mList, p3];
  42. ],
  43. {iterator, 1, length}
  44. ];
  45.  
  46. (* setup the list of points with size and colour *)
  47. max = Max[cList];
  48. min = Min[cList];
  49. slope = 0.017/(max - min);
  50. PointList3d =
  51. Table[{PointSize[slope*(cList[[i]] - max) + 0.018],
  52. Blend[{Darker[Red, .7], Lighter[Yellow, .5], Lighter[Yellow, .6],
  53. Lighter[Yellow, .7], Lighter[Yellow, .8], White}, cList[[i]] ],
  54. Point[mList[[i]] ]},
  55. {i, Length[mList]}];
  56.  
  57. (* Plot the set of points *)
  58. Graphics3D[PointList3d,
  59. AspectRatio -> 1, Background -> Black, Axes -> False,
  60. AxesOrigin -> {0, 0, 0}, AxesStyle -> GrayLevel[0.3],
  61. Boxed -> False, RotationAction -> "Clip", SphericalRegion -> True,
  62. ViewVector -> {570 Cos[0], 570 Sin[0], 20}, ImageSize -> {500, 500}]
Advertisement
Add Comment
Please, Sign In to add comment