Upgrade to a simulation

This commit is contained in:
Camden Dixie O'Brien 2021-01-01 00:00:40 +00:00
parent 57cd223bd0
commit 6ee7aba4af

17
Main.hs
View File

@ -4,12 +4,21 @@
module Main (main) where module Main (main) where
import Graphics.Gloss import Graphics.Gloss
import Graphics.Gloss.Geometry.Angle
data PolarCoord = PolarCoord { radius :: Float, angle :: Float }
render :: PolarCoord -> Picture
render state = pictures [ circleSolid 10, translatePolar state $ circleSolid 10 ]
step :: a -> b -> PolarCoord -> PolarCoord
step _ _ state = state { angle = normalizeAngle $ angle state + pi / 50 }
translatePolar :: PolarCoord -> Picture -> Picture
translatePolar q = rotate (radToDeg $ angle q) . translate (radius q) 0
window :: Display window :: Display
window = InWindow "Foo" (200, 200) (100, 100) window = InWindow "Foo" (200, 200) (100, 100)
frame :: Float -> Picture
frame t = rotate (100 * t) $ rectangleSolid 80 80
main :: IO () main :: IO ()
main = animate window white frame main = simulate window white 100 (PolarCoord 80 0) render step