From 6ee7aba4af7692c803e144c71ae783f6ffb47434 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 1 Jan 2021 00:00:40 +0000 Subject: [PATCH] Upgrade to a simulation --- Main.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Main.hs b/Main.hs index 0fba1ea..3f279dc 100644 --- a/Main.hs +++ b/Main.hs @@ -4,12 +4,21 @@ module Main (main) where 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 = InWindow "Foo" (200, 200) (100, 100) -frame :: Float -> Picture -frame t = rotate (100 * t) $ rectangleSolid 80 80 - main :: IO () -main = animate window white frame +main = simulate window white 100 (PolarCoord 80 0) render step