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 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue