Skip to content
Generate art from context-free grammars
Haskell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Art/ContextFree
examples
.gitignore
CHANGELOG.md
LICENSE
README.md
Setup.hs
Tests.hs
context-free-art.cabal

README.md

Context free art

Create art via context free grammar production rules. Current backends: SVG.

Context free grammar primer

Context free grammars consist of a set of terminal symbols, a set of non-terminal symbols, and production rules that map non-terminals to other symbols.

With a context-free grammar, we can generate strings of terminals that conform to the specified language.

Our language will describe graphics.

How to use

import Art.ContextFree.Definite
import Data.List.NonEmpty

move = Mod [Move (0, -1.8), Scale 0.8]

armN :: Int -> Symbol
armN 0 = move $ Circle 1
armN n = move $ Branch $
  Circle 1 :| [Mod [Rotate 10] $ armN (n - 1)]

arm :: Symbol
arm = armN 20

spiral = Branch $
  Circle 1 :| [arm, Mod [Rotate 120] arm, Mod [Rotate 240] arm]

The latter produces this graphic:

spiral.svg

Examples

The code for these can be found in the exmaples/ folder

circles.svg sierpinski-triangle.svg sierpinski-carpet.svg

You can’t perform that action at this time.