Upgrade to a simulation
This commit is contained in:
parent
57cd223bd0
commit
6ee7aba4af
17
Main.hs
17
Main.hs
@ -4,12 +4,21 @@
|
||||
module Main (main) where
|
||||
|
||||
import Graphics.Gloss
|
||||
import Graphics.Gloss.Geometry.Angle
|
||||
|
||||
data PolarCoord = PolarCoord { radius :: Float, angle :: Float }
|
||||
|
||||
render :: PolarCoord -> Picture
|
||||
render state = pictures [ circleSolid 10, translatePolar state $ circleSolid 10 ]
|
||||
|
||||
step :: a -> b -> PolarCoord -> PolarCoord
|
||||
step _ _ state = state { angle = normalizeAngle $ angle state + pi / 50 }
|
||||
|
||||
translatePolar :: PolarCoord -> Picture -> Picture
|
||||
translatePolar q = rotate (radToDeg $ angle q) . translate (radius q) 0
|
||||
|
||||
window :: Display
|
||||
window = InWindow "Foo" (200, 200) (100, 100)
|
||||
|
||||
frame :: Float -> Picture
|
||||
frame t = rotate (100 * t) $ rectangleSolid 80 80
|
||||
|
||||
main :: IO ()
|
||||
main = animate window white frame
|
||||
main = simulate window white 100 (PolarCoord 80 0) render step
|
||||
|
Loading…
x
Reference in New Issue
Block a user