Created
April 25, 2013 15:06
-
-
Save konn/5460420 to your computer and use it in GitHub Desktop.
Twindragon
This file contains hidden or 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
| {-# LANGUAGE FlexibleContexts, MultiParamTypeClasses #-} | |
| {-# LANGUAGE NoMonomorphismRestriction, TupleSections #-} | |
| module Main where | |
| import Data.Complex | |
| import Data.List | |
| import Diagrams.Animation | |
| import Diagrams.Backend.Cairo.CmdLine | |
| import Diagrams.Prelude | |
| main :: IO () | |
| main = do | |
| let motion = transformed |>> blured :: Animation Cairo R2 | |
| animMain $ motion <> pure (animRect' 30 motion # fc white) | |
| dragon :: Complex Double -> Int -> [Complex Double] | |
| dragon alpha n = map sum $ subsequences [ recip (alpha^^i) | i <- [1..n] ] | |
| plot eps points = | |
| position [ (origin .+^ r2 (realPart z/eps, imagPart z/eps), dot c) | (z, c) <- points ] | |
| where | |
| dot c = circle 1 # lcA c # fcA c | |
| picture = plot 0.007 $ map (,opaque black) $ dragon (negate 1 :+ 1) 10 | |
| transformed = tr <$> interval 0 1 <*> picture | |
| where | |
| tr t = rotateBy (3/8 * fromRational t + (1 - fromRational t)) . scale (fromRational t*1.41421356 + 1 - fromRational t) | |
| blured = blr <$> backwards (interval 0 0.25) | |
| where | |
| pic = dragon (negate 1 :+ 1) 10 | |
| blr t = plot 0.007 (map (,opaque black) pic) <> plot 0.007 (map ((,black `withOpacity` (t*4)).(+1)) pic) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment