Skip to content

Instantly share code, notes, and snippets.

@sleexyz
Created August 15, 2016 04:03
Show Gist options
  • Save sleexyz/21d077b231383661a1c2a6bfcb6b64fd to your computer and use it in GitHub Desktop.
Save sleexyz/21d077b231383661a1c2a6bfcb6b64fd to your computer and use it in GitHub Desktop.
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module DiagramsTidal where
import Sound.Tidal.Pattern hiding (square)
import Sound.Tidal.Time
import Sound.Tidal.Utils
import Diagrams hiding (arc, cat)
import Data.Monoid
import Diagrams.Backend.SVG.CmdLine
import Data.Colour.Names
import Data.Colour
infixl 8 &
(&) :: a -> (a -> b) -> b
x & f = f x
infixl 5 <&>
(<&>) :: (Functor f) => f a -> (a -> b) -> f b
x <&> f = f <$> x
arc2TransformLin :: Arc -> Diagram B -> Diagram B
arc2TransformLin (s, e) = translate (r2 (fromRational s, 0)) . scaleX (fromRational $ e - s)
runPattern :: Pattern (Diagram B) -> Diagram B
runPattern (Pattern a) = mconcat ((\(arc,_, x) -> arc2TransformLin arc x) <$> a (0, 1))
bjorklundSquare :: Int -> Diagram B
bjorklundSquare len = runPattern
$ stack ( do
i <- [1..len]
sq' <- return $ (return $ sq
& (scaleY (1 / (fromIntegral len)))
& translate (r2 (0, (fromIntegral i - 1) / fromIntegral len))
)
return $ e i len sq'
)
where
circ = circle 0.5
sq = square 1
& fcA (black `withOpacity` 1.0)
& lw none
main = mainWith $ vcat . map alignL
-- $ [1..50]
$ [313]
<&> bjorklundSquare
@sleexyz
Copy link
Author

sleexyz commented Aug 15, 2016

n = 1..k from bottom row to top
k = 200

200:
bjorklund-200

n = 1..k
k = 1..100

bjorklund-1-100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment