Advertisement
Guest User

Untitled

a guest
Dec 31st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import System.Exit
  2. import Graphics.UI.GLUT
  3. import Control.Monad
  4. import Graphics.Rendering.OpenGL
  5. import Data.List
  6. import Control.Concurrent
  7. import System.Random
  8. import Data.IORef
  9.  
  10. text = "ursula"
  11. s = 0.01
  12. r = sqrt (3/4*s^2) :: GLdouble
  13. sq = floor (1/(2*r))
  14. initial = [(0,0),(-1,0),(1,0),(-1,-1),(0,-1),(-1,1),(0,1),(-2,0),(2,0),(-1,-2),(1,-2),(-1,2),(1,2)]
  15.  
  16. main = initialWindowSize $= Size 987 987 >>
  17.     initialWindowPosition $= Position 0 0 >>
  18.     createWindow text >>
  19.     newIORef initial >>= \ior ->
  20.     keyboardMouseCallback $= Just (\_ _ _ _ -> exitWith ExitSuccess) >>
  21.     idleCallback $= Just (anime ior) >>
  22.     displayCallback $= zaebashitSnezhinki ior >>
  23.     mainLoop
  24.        
  25. zaebashitSnezhinki ior =
  26.     readIORef ior >>= \soti ->
  27.     clearColor $= Color4 1 1 1 1 >>
  28.     clear [ColorBuffer] >>
  29.     currentColor $= Color4 0 0 0 0 >>
  30.     narisovatSoti soti >>
  31.     flush
  32.    
  33. anime ior =
  34.     randomRIO (1,9::Int) >>= \r ->
  35.     modifyIORef ior (shag r) >>
  36.     threadDelay 144888 >>
  37.     postRedisplay Nothing
  38.  
  39. narisovatSexugolnik (x,y) = renderPrimitive TriangleFan (mapM_ vertex [Vertex2 (x+s*cos t) (y+s*sin t) | t <- take 6 [pi/6,pi/2..]])
  40.  
  41. narisovatSoti = mapM_ (narisovatSexugolnik . popravit)
  42. ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  43. popravit (x,y) = (x',y') where
  44.     x' = 2*r*fromIntegral x + if odd y then r else 0
  45.    y' = 3/2*s*fromIntegral y
  46.    
  47. sosedi (x,y)  
  48.     | odd y = [(x-1,y),(x+1,y),(x,y-1),(x+1,y-1),(x,y+1),(x+1,y+1)]
  49.     | True = [(x-1,y),(x+1,y),(x-1,y-1),(x,y-1),(x-1,y+1),(x,y+1)]
  50.  
  51. shag r soti = [xy | xy <- soti', let dlina = length (sosedi xy `intersect` soti), odd dlina && dlina<=r] where
  52.    soti' = map head $ group $ sort $ soti >>= \sota -> sota:sosedi sota
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement