wraparound-0.0.2: wrap-around-example.hs
import Graphics.Gloss.Interface.Pure.Simulate
import GHC.Float
import Data.WrapAround
dispmode = InWindow "WrapAround module test" (800, 600) (0, 0)
main = simulate dispmode (dim green) 10 model dispmodel stepfunc
data Model = Model { particles :: [(WP, (Double, Double))]
, wmap :: WM }
deriving (Show)
model = let wmap' = wm 800 600 in
let wrap (a, b) = (wp wmap' a, b) in
Model { particles = map wrap [ ((60, 30), (10, 0))
, ((110, 140), (0, 18))
, ((90, 50), (-8, 14))
]
, wmap = wmap'
}
appPair f (x, y) = (f x, f y)
downgrade a = appPair double2Float a
dispmodel m = let s = [ let (x, y) = downgrade (coords (wmap m) p) in
Polygon [ (x, y)
, (x + 10, y)
, (x + 10, y + 10)
, (x, y + 10)
]
| (p, _) <- particles m
] in
Translate
(-400) (-300)
(Pictures [ (Color black
(Polygon [ (800, 600)
, (0, 600)
, (0, 0)
, (800, 0)
]))
, (Color green
(Pictures s))
])
stepfunc _ _ m = m { particles = [ (add' (wmap m) p v, v)
| (p, v) <- particles m
]
}