Created
November 16, 2015 23:28
-
-
Save ChristopherKing42/e3474f89d85993e3b357 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Applicative (liftA2) | |
import Data.Foldable | |
import Data.Tuple.Homogenous | |
import Graphics.Gloss.Interface.Pure.Game | |
import Debug.Trace | |
main = play | |
(InWindow "Deriv II" (500,500) (100,100)) | |
black | |
120 | |
((0, pure 0, pure $ pure 0) :: (Float, Tuple2 Float, Tuple9 (Tuple2 Float))) | |
(\w@(time,point,history) -> traceShow w $ fold $ do | |
divisor <- Tuple2(time,time*time) | |
(coeff,clr) <- coefficients | |
let deriv = fmap (/divisor) (foldr (liftA2 (+)) (pure 0) $ do | |
hist <- history | |
co <- coeff | |
return $ fmap (co*) hist) | |
return $ color clr $ Line [untuple2 point, untuple2 $ (+) <$> point <*> deriv] | |
) | |
(\e w@(t,p,h) -> case e of | |
EventMotion p' -> (t,Tuple2 p',h) | |
_ -> w | |
) | |
(\t (_,p,h) -> (t, p, cons p h)) | |
coefficients = tuple2 | |
(negate <$> (tuple9 (-761/280) (8) (-14) (56/3) (-35/2) (56/5) (-14/3) (8/7) (-1/8) ), green) | |
( (tuple9 (29531/5040) (-962/35) (621/10) (-4006/45) (691/8) (-282/5) (2143/90) (206/35) (363/560) ), red ) | |
cons x (Tuple9 (x0,x1,x2,x3,x4,x5,x6,x7,x8)) = tuple9 x x0 x1 x2 x3 x4 x5 x6 x7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment