Use Gloss for real-time visualization

This commit is contained in:
Dimitri Lozeve 2017-11-14 00:03:16 +00:00
parent 30be811103
commit fac591fb51
2 changed files with 34 additions and 3 deletions

View file

@ -8,6 +8,8 @@ import Linear.V3
import System.Random
import Control.Monad (replicateM)
import Graphics.Gloss hiding (Point)
--------------------------------------------------------------------------------
-- Random body generation
@ -76,8 +78,36 @@ csvFromInit :: Int -- ^ The number of time steps to keep
-> String -- ^ CSV data
csvFromInit n dt theta b = concat $ map (uncurry csvFromBodies) (take n $ steps dt theta b)
--------------------------------------------------------------------------------
-- Gloss
--------------------------------------------------------------------------------
width, height, offset :: Int
width = 1000
height = 750
offset = 100
window :: Display
window = InWindow "Orbit" (width, height) (offset, offset)
displayBody :: Body -> Picture
displayBody b = translate (realToFrac x) (realToFrac y) $ circle (realToFrac (_bodyRadius b))
where P (V3 x y _) = _bodyPosition b
displayBodies :: [Body] -> Picture
displayBodies = color white . Pictures . map displayBody
drawing :: Picture
drawing = color white $ circle 80
main :: IO ()
main = do
bodies <- replicateM 100 randomBody
putStrLn $ csvFromInit 10000 (60*20) 0.5 bodies
bodies <- replicateM 300 randomBody
simulate
window
black
25
bodies
displayBodies
(\_ dt bs -> updateAll (realToFrac dt*1e6) 0.5 bs)

View file

@ -31,6 +31,7 @@ executable orbit-exe
, orbit
, linear
, random
, gloss
default-language: Haskell2010
test-suite orbit-test