module Main where
import Graphics.UI.GLUT
arccot x unity =
arccot' x unity 0 start 1 1
where start = unity `div` x
arccot' x unity sum xpower n sign
| xpower `div` n == 0 = sum
| otherwise =
arccot' x unity (sum + sign*term) (xpower `div` (x*x)) (n+2) (-sign)
where term = xpower `div` n
machin_pi digits = pi' `div` (10 ^ 10)
where unity = 10 ^ (digits+10)
pi' = 4 * (4 * arccot 5 unity - arccot 239 unity)
digs :: (Integral a) => a -> [a]
digs 0 = []
digs x = digs (x `div` 10) ++ [x `mod` 10]
circle :: GLfloat -> GLfloat -> [(GLfloat, GLfloat, GLfloat)]
circle x y = [ (x + sin (2*pi*k/a), y + cos (2*pi*k/a), 0) | k <- [1..a] ]
where a = 10
line :: GLfloat -> GLfloat -> [(GLfloat, GLfloat, GLfloat)]
line a b = [(cos(a*(pi/10)), sin(a*(pi/10)), 0),(cos(b*(pi/10)), sin(b*(pi/10)), 0)]
pairs [] = []
pairs xs = zip xs (tail xs)
vertices :: (GLfloat, GLfloat) -> (GLfloat, GLfloat, GLfloat)
vertices (a,b) = (a, b, 0)
main :: IO ()
main = do
(_progName, _args) <- getArgsAndInitialize
_window <- createWindow "P"
displayCallback $= display
mainLoop
display :: DisplayCallback
display = do
clear [ ColorBuffer ]
renderPrimitive Points $
mapM_ vertex3f $ circle 0 0
renderPrimitive Lines $
mapM_ (vertex3f) ( map vertices ( pairs $ digs $ machin_pi 100))
flush
where
vertex3f (x, y, z) = vertex $ Vertex3 x y (z :: GLfloat)
Собсна проблема в том, что digs у меня Integral -> [Integral], а мне для vertices нужны GLfloat-ы. Как быть?