40 lines
1.1 KiB
Haskell
40 lines
1.1 KiB
Haskell
-- SPDX-License-Identifier: ISC
|
|
-- Copyright (c) 2020 Camden Dixie O'Brien
|
|
|
|
module Main (main) where
|
|
|
|
import Graphics.Gloss
|
|
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 majorMass
|
|
, translatePolar state $ circleSolid minorMass ]
|
|
|
|
step :: a -> b -> PolarCoord -> PolarCoord
|
|
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
|
|
|
|
window :: Display
|
|
window = InWindow "Foo" (200, 200) (100, 100)
|
|
|
|
main :: IO ()
|
|
main = simulate window white framesPerSecond (PolarCoord 80 0) render step
|