From daeff1c461f96984b60dfc571f774ef0bc662956 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Fri, 1 Jan 2021 00:00:38 +0000 Subject: [PATCH] Implement rendering --- Main.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index dbc1571..01623ba 100644 --- a/Main.hs +++ b/Main.hs @@ -3,6 +3,9 @@ module Main where +import Graphics.Gloss +import Graphics.Gloss.Geometry.Angle + data State = State { theta :: Float , pTheta :: Float , phi :: Float @@ -21,5 +24,13 @@ particleColor = black rodColor = greyN 0.5 framesPerSecond = 100 -main :: IO () -main = putStrLn "Hello, Haskell!" +render state = doublePendulum (theta state) (phi state) +doublePendulum theta phi = (translatePolar rodLength theta $ pendulum phi) <> pendulum theta +translatePolar radius angle = translate (radius * sin angle) (negate $ radius * cos angle) +pendulum angle = rotateRadians angle $ rod <> (translate 0 (negate rodLength) $ particle) +rod = color rodColor $ line [ (0, 0), (0, negate rodLength) ] +particle = color particleColor $ circleSolid particleRadius +rotateRadians = rotate . radToDeg . negate + +window = InWindow "Double Pendulum" (800, 800) (100, 100) +main = display window white (render initialState)