6.hs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. {-# LANGUAGE OverloadedStrings #-}
  2. import Data.List
  3. import Text.LaTeX
  4. import Text.LaTeX.Base.Class
  5. import Text.LaTeX.Base.Syntax
  6. import Text.LaTeX.Packages.Graphicx
  7. import Text.LaTeX.Packages.Geometry
  8. import Util
  9. import Vec
  10. main :: IO ()
  11. main = printdoc doc
  12. doc :: Monad m => LaTeXT_ m
  13. doc = do
  14. mapM_ rendere $ polymap (vadd (0.0, 0.0, 1.8)) $ polyrotate (cubes 1.5) (0.6, 0.9, 0.32)
  15. rendere :: LaTeXC l => (Vec3, Vec3) -> l
  16. rendere (a, b) =
  17. if d > 0.001 then textblock' (vw $ fst c) (vw $ snd c) $ rotatebox' ((-t - (snd c) / 2) * 180 / pi) $ fontsize (vw $ d * 0.072) (vw 0) "falling again into her own footprints"
  18. else ""
  19. where
  20. c = vadd a' $ vdiv (vsub b' a') 2
  21. d = vdist a' b'
  22. t = atan2 (snd $ vsub b' a') (fst $ vsub b' a')
  23. a' = vadd (0.5, sqrt 2 / 2) $ vmul (vproject a) 1
  24. b' = vadd (0.5, sqrt 2 / 2) $ vmul (vproject b) 1
  25. polymap :: (Vec3 -> Vec3) -> [(Vec3, Vec3)] -> [(Vec3, Vec3)]
  26. polymap f = fmap (\(a, b) -> (f a, f b))
  27. polyrotate :: [(Vec3, Vec3)] -> Vec3 -> [(Vec3, Vec3)]
  28. polyrotate vs t = polymap (flip v3rotate t) vs
  29. cubes :: Double -> [(Vec3, Vec3)]
  30. cubes r = connect dist $ vcubes r
  31. where
  32. connect dist xs = [(x, y) | (x:ys) <- tails xs, y <- ys, vdist x y < dist]
  33. dist = r * 0.257
  34. vcubes :: Double -> [Vec3]
  35. vcubes r = fmap (flip vmul r) vs
  36. where
  37. vs = [(x, y, z) | x <- a, y <- a, z <- b]
  38. a = [-1, -3/4 .. 1]
  39. b = [-1, -3/4 .. 3/2]
  40. phi :: Double
  41. phi = (1 + sqrt 5) / 2