packages feed

context-free-art 0.3.0.0 → 0.3.0.1

raw patch · 7 files changed

+119/−10 lines, 7 filesdep +context-free-artdep +directorydep −safenew-component:exe:examplesPVP ok

version bump matches the API change (PVP)

Dependencies added: context-free-art, directory

Dependencies removed: safe

API changes (from Hackage documentation)

Files

Art/ContextFree/Definite/Render.hs view
@@ -29,10 +29,10 @@ -- pos, path poly :: State -> [Vec] -> Res poly pos pts =-  let newPts = pos : pts-      (x, y) = pos-      (_, b) = foldl nextRes (pos, (x, y, x, y)) newPts-  in  (b, S.path ! A.d (toValue $ toPath newPts))+  let (x, y) = pos+      --calculate bounds+      (_, b) = foldl nextRes (pos, (x, y, x, y)) pts+  in  (b, S.path ! A.d (toValue $ toPath $ pos : pts))     where       nextRes ((x, y), b) (dx, dy)         = let (i, j) = (x + dx, y + dy)
Art/ContextFree/Util.hs view
@@ -10,4 +10,4 @@ tupLst (a, b) = [a, b]  toPath :: [Vec] -> T.Text-toPath pts = T.intercalate " l" (T.unwords . tupLst . both showt <$> pts) <> "Z"+toPath pts = "M" <> T.intercalate "l" (T.unwords . tupLst . both showt <$> pts) <> "Z"
context-free-art.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/  name:                context-free-art-version:             0.3.0.0+version:             0.3.0.1 synopsis:            Generate art from context-free grammars description:     .@@ -45,13 +45,13 @@     >     > armN :: Int -> Symbol     > armN 0 = move $ Circle 1-    > armN n = move $ NonTerminal $+    > armN n = move $ Branch $     >   Circle 1 :| [Mod [Rotate 10] $ armN (n - 1)]     >     > arm :: Symbol     > arm = armN 20     >-    > spiral = NonTerminal $+    > spiral = Branch $     >   Circle 1 :| [arm, Mod [Rotate 120] arm, Mod [Rotate 240] arm]     .     The latter produces this graphic:@@ -68,6 +68,21 @@ category:            Graphics extra-source-files:  CHANGELOG.md +executable examples+  main-is:          Main.hs+  hs-source-dirs:   examples+  other-modules:    Sierpinski.Triangle+                    Sierpinski.Carpet+                    , Spiral+  build-depends:    base >= 4.12 && < 5+                    , blaze-svg >= 0.3.6+                    , context-free-art+                    , blaze-markup+                    , text >= 1.2+                    , directory >= 1.3+  ghc-options:      -Wall -fwarn-incomplete-patterns+  default-language: Haskell2010+ test-suite tests   type:             exitcode-stdio-1.0   main-is:          Tests.hs@@ -86,7 +101,6 @@                     , text-show >= 3.8                     , text >= 1.2                     , HUnit >= 1.6-                    , safe   ghc-options:      -Wall -fwarn-incomplete-patterns   default-language: Haskell2010 @@ -107,5 +121,4 @@                     , bifunctors >= 5.5                     , text-show >= 3.8                     , text >= 1.2-                    , safe   default-language: Haskell2010
+ examples/Main.hs view
@@ -0,0 +1,32 @@+module Main where++import Art.ContextFree.Definite+import qualified Data.Text.Lazy.IO as T+import System.Directory+import Text.Blaze.Svg.Renderer.Text+import Spiral+import Sierpinski.Triangle+import Sierpinski.Carpet++baseDir :: String+baseDir = "res"++imagePath :: String -> String+imagePath name = baseDir <> "/" <> name <> ".svg"++renderTmp :: String -> Symbol -> IO ()+renderTmp name symbol = do+  let path = imagePath name+  putStrLn $ "Writing " <> path+  createDirectoryIfMissing True baseDir+  T.writeFile path $ renderSvg $ render symbol++images :: [(String, Symbol)]+images =+  [ ("spiral", spiral)+  , ("sierpinski-triangle", sierpinskiTriangle)+  , ("sierpinski-carpet", sierpinskiCarpet)+  ]++main :: IO ()+main = mapM_ (uncurry renderTmp) images
+ examples/Sierpinski/Carpet.hs view
@@ -0,0 +1,25 @@+module Sierpinski.Carpet ( sierpinskiCarpet ) where++import Art.ContextFree.Definite+import Data.List.NonEmpty++third :: Float+third = 1.0 / 3++square :: Symbol+square = Poly [(0, 1), (1, 0), (0, -1)]++layer :: Int -> Symbol+layer 0 = Branch $ square+          :| [Mod [Move (third, third), Scale third, Color "#fff"] square]+layer n+  = let a = layer (n - 1)+        row = Branch $ a :| [Mod [Move (1, 0)] a, Mod [Move (2, 0)] a]+    in  Mod [Scale third] $ Branch $ row :|+      [ Mod [Move (0, 2)] row+      , Mod [Move (0, 1)] a+      , Mod [Move (2, 1)] a+      ]++sierpinskiCarpet :: Symbol+sierpinskiCarpet = layer 3
+ examples/Sierpinski/Triangle.hs view
@@ -0,0 +1,18 @@+module Sierpinski.Triangle ( sierpinskiTriangle ) where++import Art.ContextFree.Definite+import Data.List.NonEmpty++h :: Float+h = sqrt (1 - 0.5 ** 2.0)++layer :: Int -> Symbol+layer 0 = Poly [(0.5, -h), (0.5, h)]+layer n+  = let a = layer (n - 1)+        b = Mod [Move (0.5, -h)] a+        c = Mod [Move (1, 0)] a+    in  Mod [Scale 0.5] $ Branch $ a :| [b, c]++sierpinskiTriangle :: Symbol+sierpinskiTriangle = layer 5
+ examples/Spiral.hs view
@@ -0,0 +1,21 @@+module Spiral ( spiral ) where++import Art.ContextFree.Definite+import Data.List.NonEmpty++move :: Symbol -> Symbol+move = Mod [Move (0, -1.8), Scale 0.8]++armN :: Int -> Float -> Symbol+armN 0 _   = move $ Circle 1+armN n rot = move $ Branch $ Circle 1 :| [Mod [Rotate rot] $ armN (n - 1) rot]++arm :: Symbol+arm = armN 11 (-10)++spiral :: Symbol+spiral = Branch $ Circle 1 :|+  [ arm+  , Mod [Rotate 120] arm+  , Mod [Rotate 240] arm+  ]