Implement rendering
This commit is contained in:
parent
113ca6cdc4
commit
daeff1c461
15
Main.hs
15
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user