From 7bdbf4861afca11db80797c7fe277ba0cd20aa5f Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 1 Jan 2021 00:00:40 +0000 Subject: [PATCH] Parameterise things a little --- Main.hs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Main.hs b/Main.hs index 3f279dc..4cbb39e 100644 --- a/Main.hs +++ b/Main.hs @@ -8,11 +8,26 @@ import Graphics.Gloss.Geometry.Angle data PolarCoord = PolarCoord { radius :: Float, angle :: Float } +majorMass :: Float +majorMass = 10 + +minorMass :: Float +minorMass = 4 + +framesPerSecond :: Int +framesPerSecond = 120 + +angularVelocity :: Float +angularVelocity = pi + render :: PolarCoord -> Picture -render state = pictures [ circleSolid 10, translatePolar state $ circleSolid 10 ] +render state = pictures [ circleSolid majorMass + , translatePolar state $ circleSolid minorMass ] step :: a -> b -> PolarCoord -> PolarCoord -step _ _ state = state { angle = normalizeAngle $ angle state + pi / 50 } +step _ _ state = let radiansPerFrame = angularVelocity / fromIntegral framesPerSecond + nextAngle = normalizeAngle $ angle state + radiansPerFrame + in state { angle = nextAngle } translatePolar :: PolarCoord -> Picture -> Picture translatePolar q = rotate (radToDeg $ angle q) . translate (radius q) 0 @@ -21,4 +36,4 @@ window :: Display window = InWindow "Foo" (200, 200) (100, 100) main :: IO () -main = simulate window white 100 (PolarCoord 80 0) render step +main = simulate window white framesPerSecond (PolarCoord 80 0) render step