Skip to content

Instantly share code, notes, and snippets.

@konn
Created April 25, 2013 15:06
Show Gist options
  • Select an option

  • Save konn/5460420 to your computer and use it in GitHub Desktop.

Select an option

Save konn/5460420 to your computer and use it in GitHub Desktop.
Twindragon
{-# 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