Guest User

Untitled

a guest
Jul 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. module Main where
  2.  
  3. import Graphics.Gloss
  4. import Data.List
  5.  
  6. main :: IO ()
  7. main = display (InWindow "Recaman Sequence" (500, 500) (0, 0)) white draw
  8.  
  9. draw :: Picture
  10. draw = rotate (-35) $ pictures $ snd $ mapAccumL (addarc) [] (map (\n -> fromIntegral n :: Float) (recaman 65))
  11. where addarc acc n
  12. | acc == [] = (acc ++ [n], blank)
  13. | otherwise = (acc ++ [n], translate (last acc - (last acc - n) / 2) 0 $ rotarc $ arcbetween n (last acc))
  14. where arcbetween a b = arc (-180) 0 ((b - a)/2)
  15. rotarc a
  16. | even $ length acc = rotate 180 a
  17. | odd $ length acc = a
  18.  
  19. recaman :: Int -> [Int]
  20. recaman l = foldl (next) [] [0..l]
  21. where next acc n
  22. | n == 0 = acc ++ [n]
  23. | last acc - n > 0 && not (last acc - n `elem` acc) = acc ++ [last acc - n]
  24. | otherwise = acc ++ [last acc + n]
Add Comment
Please, Sign In to add comment