Guest User

Crossword on torus

a guest
Sep 6th, 2014
330
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ClearAll[f];
  2. f@{{1, 1, _}, {1, _, _}, {_, _, _}} = 0;
  3. f@{{_, 1, 1}, {_, _, 1}, {_, _, _}} = 0;
  4. f@{{_, _, _}, {_, _, 1}, {_, 1, 1}} = 0;
  5. f@{{_, _, _}, {1, _, _}, {1, 1, _}} = 0;
  6. f@{_, {_, x_, _}, _} := If[Random[] < 0.1, 1, x];
  7.  
  8. del = # //. {x___, 0, 1, 1, 0, z___} :> {x, 0, 0, 0, 0, z} &;
  9.  
  10. ca = Unitize@SelectComponents[#, Large] &@
  11. MorphologicalComponents[#, CornerNeighbors -> False] &@
  12. ArrayPad[#, -1] &@del@Transpose@del@ArrayPad[#, 1] &@
  13. CellularAutomaton[{f[#] &, {}, {1, 1}}, #, {{200}}][[1]] &;
  14.  
  15. res = Nest[ca, ConstantArray[0, {30, 30}], 4];
  16. labels = Position[#, {_, {0, 1, 1}, _} | {{_, 0, _}, {_, 1, _}, {_,
  17. 1, _}}, {2}] &@Partition[#, {3, 3}, 1] &@
  18. ArrayPad[res, 1, Padding -> "Periodic"];
  19. n = 20;
  20. texture =
  21. ImageResize[#, Scaled[5]] &@
  22. Rasterize@
  23. ArrayPlot[1 - res, Mesh -> All, Frame -> False, MeshStyle -> Black,
  24. Epilog ->
  25. MapIndexed[
  26. Text[Style[#2[[1]], 9],
  27. n {#[[2]] - 0.95, Length@res - #[[1]] + 0.95}, {-1, 1}] &,
  28. labels], PixelConstrained -> n]
  29.  
  30. r = 1.5;
  31. ParametricPlot3D[{Cos[t], Sin[t], Sin[# u]/#} #^2/(r - Cos[# u]) &[
  32. Sqrt[r^2 - 1]], {t, 0, 2 \[Pi]}, {u, 0, 2 \[Pi]/Sqrt[r^2 - 1]},
  33. PlotPoints -> 100, Boxed -> False, Axes -> False,
  34. Lighting -> "Neutral", PlotStyle -> Texture[texture],
  35. TextureCoordinateScaling -> False,
  36. TextureCoordinateFunction -> ({#4 + 2, #5 Sqrt[r^2 - 1] - 0.5}/
  37. 2/\[Pi] &), Mesh -> None]
RAW Paste Data