-- 2008 Programming Competition, entry for Flavius Popescu (0839222) -- ##################### Spiralomania ######################### -- -- This draws a "picture" of the Haskell programming language using lines and spirals only. -- To see it, evaluate the function "runme" in ghci, no parameters neeed (quotes for clarity only) import LSystem import Test.QuickCheck runme = display \$ snail -- helper functions split (Go d) = [Go d] split (Turn a) = [Turn a] split (Sit) = [] split (x :#: y) = split x ++ split y join (c:[]) = c join (c:cs) = c :#: join cs prop_join_split c = split( join (split c)) == split c copy k c = join (concat [ split c | i <- [1..k] ]) copy' k c = join \$ replicate k c -- several types of spirals spiral side 0 step angle = Sit spiral side n step angle = Branch ( Turn 90 :#: Go (side * 5)) :#: Go side :#: Turn angle :#: spiral (side + step) (n-1) step angle spiral' side 0 step angle = Sit spiral' side n step angle = Go side :#: Turn angle :#: spiral' (side + step) (n-1) step angle spiral'' side 0 step angle = Sit spiral'' side n step angle = Branch (Turn (-90) :#: Go (side*5)) :#: Go side :#: Turn angle :#: spiral'' (side + step) (n-1) step angle -- the snail (could use some improvement in function use, in a later version) snail :: Command snail = spiral 0.1 1030 0.2 2 :#: spiral' 10 400 0.1 0.05 :#: spiral' 20 300 0.1 0.35 :#: Branch (spiral' 0.1 60 2.4 (-2) :#: spiral 0.1 100 0.5 20) :#: spiral'' 0.5 45 2.4 1.5 :#: Branch (spiral' 0.1 60 2.4 (-2) :#: spiral 0.1 100 0.5 20) :#: Branch (GrabPen Inkless :#: Turn 75 :#: Go 1700 :#: GrabPen black :#: Branch ( Turn (-70) :#: solid :#: Turn 90 :#: Go 600 :#: Turn 90 :#: Go 1300 :#: Turn 90 :#: Go 600) :#: Turn 110 :#: Turn (-80) :#: GrabPen Inkless :#: Go 200 :#: Turn 80 :#: GrabPen black :#: Go 1000 :#: Turn (80) :#: GrabPen Inkless :#: Go 200 :#: GrabPen black :#: Turn 190 :#: Go 600 :#: Turn 90 :#: Go 1300 :#: Turn 90 :#: Go 600 :#: Turn 90 :#: solid :#: Turn 45 :#: GrabPen Inkless :#: Go 3500 :#: GrabPen black :#: Turn 135 :#: Branch (Go 2300) :#: Turn (-90) :#: spiral' 0.1 60 1.5 2.2 ) :#: spiral'' 3 36 3 0.7 :#: spiral' 0.2 55 3 1.1 :#: spiral' 0.2 53 3 (-2) :#: GrabPen Inkless :#: Turn 45 :#: Go 13000 :#: Turn 63 :#: Go 1400 :#: Turn 180 :#: GrabPen black :#: litL :#: litA :#: litZ :#: litY :#: litSpc :#: litA :#: litN :#: litD :#: litSpc :#: litC :#: litO :#: litO :#: litL :#: Turn 97 :#: GrabPen Inkless :#: Go 9000 :#: GrabPen black :#: Sit -- letters litDone = Turn (-90) :#: GrabPen Inkless :#: Turn (-90) :#: Go 100 :#: Turn 90 :#: Go 1300 :#: Turn 90 :#: Go 100 :#: Turn (-90) :#: Turn 90 :#: GrabPen black litL :: Command litL = Branch ( Go 1400) :#: Branch (Turn (-90) :#: Go 1300) :#: litDone litA = Branch ( Go 1400 :#: Turn (-90) :#: Go 1000 :#: Turn (-90) :#: Go 600 :#: Branch (Turn (-90) :#: Go 1000) :#: Go 800) :#: litDone litZ = Branch ( GrabPen Inkless :#: Go 1300 :#: Turn (-90) :#: GrabPen black :#: Go 1000 :#: Turn (-125) :#: Go 1560 :#: Turn 125 :#: Go 1000) :#: litDone litY = Branch ( GrabPen Inkless :#: Go 1300 :#: Turn (-135) :#: GrabPen black :#: Go 600 :#: Branch ( Turn 90 :#: Go 600) :#: Turn (-45) :#: Go 1000 ) :#: litDone litSpc = GrabPen Inkless :#: Turn (-90) :#: Go 1400 :#: Turn 90 :#: GrabPen black litN = Branch ( Go 1300 :#: Turn (-145) :#: Go 1550 :#: Turn 145 :#: Go 1300 ) :#: litDone litD = Branch ( Go 1300 :#: Turn (-125) :#: Go 1000 :#: Turn (-105) :#: Go 1010) :#: litDone litC = Branch ( Go 1300 :#: Turn (-90) :#: Go 1000) :#: Branch (Turn (-90) :#: Go 1000) :#: litDone litO = Branch ( Go 1300 :#: Turn (-90) :#: Go 1000 :#: Turn (-90) :#: Go 1300 :#: Turn (-90) :#: Go 1000) :#: litDone -- fills up a rectangle; can only be used with its fixed filling area, improvements in a later version solid :: Command solid = copy' 1300 (Go 1 :#: Branch (Turn 90 :#: Go 600))