Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (34 sloc) 1.23 KB
import Core exposing (..)
import Path exposing (..)
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Color exposing (..)
import List
import Dict
import Signal exposing (..)
import String
import Window
import Debug
type alias Position = Path.Position
sierpinskiTri : LSystem
sierpinskiTri =
{ axiom = [ 'A' ],
rules = Dict.fromList [
('A', String.toList "+B-A-B+"),
('B', String.toList "-A+B+A-")
] }
draw startPos state =
let angle = degrees 60
(_, _, segs, canvasArea) =
state |> List.foldl (\sym (pos, rotation, acc, canvasArea) ->
if | sym == 'A' || sym == 'B' ->
let endPos = calcEndPos pos rotation 10
newSeg = segment pos endPos |> traced (solid black)
newAcc = newSeg::acc
newCanvasArea = updateCanvasArea canvasArea endPos
in (endPos, rotation, newAcc, newCanvasArea)
| sym == '+' -> (pos, rotation+angle, acc, canvasArea)
| sym == '-' -> (pos, rotation-angle, acc, canvasArea)
) (startPos, 0, [], defaultCanvasArea)
in (segs, canvasArea)
main = (display draw) <~ Window.dimensions ~ (states sierpinskiTri)
You can’t perform that action at this time.