Parameterise things a little

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

21
Main.hs
View File

@ -8,11 +8,26 @@ import Graphics.Gloss.Geometry.Angle
data PolarCoord = PolarCoord { radius :: Float, angle :: Float } 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 :: 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 :: 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 :: PolarCoord -> Picture -> Picture
translatePolar q = rotate (radToDeg $ angle q) . translate (radius q) 0 translatePolar q = rotate (radToDeg $ angle q) . translate (radius q) 0
@ -21,4 +36,4 @@ window :: Display
window = InWindow "Foo" (200, 200) (100, 100) window = InWindow "Foo" (200, 200) (100, 100)
main :: IO () main :: IO ()
main = simulate window white 100 (PolarCoord 80 0) render step main = simulate window white framesPerSecond (PolarCoord 80 0) render step