Use Gloss for real-time visualization
This commit is contained in:
parent
30be811103
commit
fac591fb51
2 changed files with 34 additions and 3 deletions
36
app/Main.hs
36
app/Main.hs
|
@ -8,6 +8,8 @@ import Linear.V3
|
||||||
import System.Random
|
import System.Random
|
||||||
import Control.Monad (replicateM)
|
import Control.Monad (replicateM)
|
||||||
|
|
||||||
|
import Graphics.Gloss hiding (Point)
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Random body generation
|
-- Random body generation
|
||||||
|
@ -76,8 +78,36 @@ csvFromInit :: Int -- ^ The number of time steps to keep
|
||||||
-> String -- ^ CSV data
|
-> String -- ^ CSV data
|
||||||
csvFromInit n dt theta b = concat $ map (uncurry csvFromBodies) (take n $ steps dt theta b)
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
bodies <- replicateM 100 randomBody
|
bodies <- replicateM 300 randomBody
|
||||||
putStrLn $ csvFromInit 10000 (60*20) 0.5 bodies
|
simulate
|
||||||
|
window
|
||||||
|
black
|
||||||
|
25
|
||||||
|
bodies
|
||||||
|
displayBodies
|
||||||
|
(\_ dt bs -> updateAll (realToFrac dt*1e6) 0.5 bs)
|
||||||
|
|
|
@ -31,6 +31,7 @@ executable orbit-exe
|
||||||
, orbit
|
, orbit
|
||||||
, linear
|
, linear
|
||||||
, random
|
, random
|
||||||
|
, gloss
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
test-suite orbit-test
|
test-suite orbit-test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue