Subversion Repositories colinrmitchell.com

Compare Revisions

Ignore whitespace Rev 647 → Rev 648

/Haskell/Gravity/src/Main.hs
23,6 → 23,8
getArgs >>= (procArgs (defaultUniverse, defaultUniverseState))
 
putStrLn $ show us
 
stVar <- newMVar bodies
vVar <- newMVar (((-1.0, -1.0), (1.0, 1.0)) :: ((GLdouble, GLdouble), (GLdouble, GLdouble)))
wVar <- newMVar (Size 300 300)
29,7 → 31,7
displayCallback $= do
incState stVar us
display wVar vVar stVar
display wVar vVar stVar us
reshapeCallback $= Just (reshape wVar vVar stVar)
mainLoop
76,7 → 78,7
(\n -> do
ns <- fmap (map fromIntegral) $ randoms' 5
let body = Body
((ns !! 0) / 50, (ns !! 1) / 50)
((ns !! 0) / 5, (ns !! 1) / 5)
((ns !! 2) / 1000, (ns !! 3) / 1000)
(1 + (abs (ns !! 4)) / 50)
putStrLn $ show body
102,7 → 104,12
let us' = us { collisionType = read arg2 }
procArgs (bs, us') args'
 
"-v" -> do
let us' = us { displayInfo = True }
procArgs (bs, us') args
"-f" -> do
let (arg2:args') = args
h <- openFile arg2 ReadMode
133,8 → 140,9
MVar Size ->
MVar ((GLdouble, GLdouble), (GLdouble, GLdouble)) ->
MVar [Body] ->
UniverseState ->
DisplayCallback
display wVar vVar stVar = do
display wVar vVar stVar us = do
clear [ColorBuffer]
 
resizeView wVar vVar stVar False
159,16 → 167,20
wh <- fmap (\(Size _ y) -> y) $ readMVar wVar
h <- fontHeight Fixed9By15
mapM
(\(i, body) -> do
windowPos $ Vertex2 0 (wh - (1 + i) * (floor h))
case displayInfo $ us of
True ->
mapM
(\(i, body) -> do
windowPos $ Vertex2 0 (wh - (1 + i) * (floor h))
renderString Fixed9By15
$ ("Pos: " ++ (printFloatTuple $ bodyCoord body))
renderString Fixed9By15
$ (" Vel: " ++ (printFloatTuple $ bodyVelocity body))
)
$ zip [0,1..] bodies
renderString Fixed9By15
$ ("Pos: " ++ (printFloatTuple $ bodyCoord body))
renderString Fixed9By15
$ (" Vel: " ++ (printFloatTuple $ bodyVelocity body))
)
$ zip [0,1..] bodies
False ->
return [()]
swapBuffers
 
/Haskell/Gravity/src/Universe.hs
6,7 → 6,8
{
timeStep :: Float,
gravitationalConstant :: Float,
collisionType :: CollisionType
collisionType :: CollisionType,
displayInfo :: Bool
} deriving (Show, Read, Eq)
 
data CollisionType = Repel | Explode | Combine | Coalesce
13,7 → 14,7
deriving (Show, Read, Eq)
 
defaultUniverseState =
UniverseState 0.05 0.01 Repel
UniverseState 0.05 0.01 Repel False
 
defaultUniverse :: [Body]
defaultUniverse =