-- Put your name and matriculation number here --Matthew Carr 0569217 import LSystem -- 1. join :: [Command] -> Command join coms = foldr (:#) Sit coms -- 2. split :: Command -> [Command] split (coms :# com) = split coms ++ split com split com = [com] -- 3. copy :: Int -> Command -> Command copy n com = join (replicate n com) -- 4. hexagon :: Distance -> Command hexagon l = copy 6 (Go l :# Turn 60) -- 5. polygon :: Distance -> Int -> Command polygon l n = copy n (Go l :# Turn (360/ (fromIntegral n))) -- 6. spiral :: Distance -> Int -> Distance -> Angle -> Command spiral l n step ang | n == 0 = Sit | n > 0 = (Go l :# Turn ang) :# spiral (l - step) (n-1) step ang -- 7. optimise :: Command -> Command optimise com = deSit (optList (split (optList (split (optList (split com)) )) ) ) deSit :: Command -> Command deSit (coms :# Sit) = coms deSit coms = coms optList :: [Command] -> Command optList (x:xs) | x == Sit = optList xs | x == Turn 0 = optList xs | x == Go 0 = optList xs | xs == [] = x optList (Turn x :(Turn y : xs)) = Turn (x+y) :# optList xs optList (Go x :(Go y : xs)) = Go (x+y) :# optList xs optList (Go x : xs) = Go x :# optList xs optList (Turn x : xs) = Turn x :# optList xs optList [x] = x optList [] = Sit -- 8. -- +ve angle turns turtle anticlockwise. therefore n is +ve and p is -ve arrowhead :: Int -> Command arrowhead x = f x where f 0 = GrabPen red :# Go 10 f (x + 1) = g x :# p :# f x :# p :# g x g 0 = GrabPen blue :# Go 10 g (x + 1) = f x :# n :# g x :# n :# f x n = Turn 60 p = Turn (-60) -- 9. branch :: Int -> Command branch x = g x where g 0 = GrabPen green :# Go 10 g (x + 1) = f x :# n :# Branch ( Branch (g x) :# p :# g x) :# p :# f x :# Branch (p :# f x :# g x) :# n :# g x f 0 = GrabPen brown :# Go 10 f (x + 1) = f x :# f x n = Turn 22.5 p = Turn (-22.5) -- 10. hilbert :: Int -> Command hilbert x = l x where l 0 = GrabPen green :# Go 10 l (x + 1) = p :# r x :# f x :# n :# l x :# f x :# l x :# n :# f x :# r x :# p r 0 = GrabPen blue :# Go 10 r (x + 1) = n :# l x :# f x :# p :# r x :# f x :# r x :# p :# f x :# l x :# n f x = GrabPen red :# Go 10 n = Turn 90 p = Turn (-90) --Peano Gosper peanoG :: Int -> Command peanoG x = f x where f 0 = GrabPen (Colour 0.9 0 0) :# Go 10 f (x + 1) = f x :# p :# g x :# p :# p :# g x :# n :# f x :# n :# n :# f x :# f x :# n :# g x :# p g 0 = GrabPen (Colour 0.9 0.9 0) :# Go 10 g (x + 1) = n :# f x :# p :# g x :# g x :# p :# p :# g x :# p :# f x :# n :# n :# f x :# n :# g x n = Turn 60 p = Turn (-60) --32 Segment (needs small scale when displaying) thirty2Seg :: Int -> Command thirty2Seg x = (f x :# f x :# f x :# f x) where f 0 = GrabPen blue :# Go 10 f (x + 1) = n :# f x :# p :# f x :# n :# f x :# n :# f x :# p :# f x :# p :# f x :# f x :# n :# f x :# p :# f x :# p :# f x :# f x :# p :# f x :# n :# f x :# n :# f x :# f x :# p :# f x :# f x :# n :# f x :# f x :# p :# f x :# p :# f x :# n :# f x :# f x :# n :# f x :# n :# f x :# p :# f x :# f x :# n :# f x :# n :# f x :# p :# f x :# p :# f x :# n :# f x :# p n = Turn 90 p = Turn (-90) {- Competition Submission: "Title as necessary" Matthew Carr -0569217 Alan Anderson -0570660 - (sort code no 23-34-00 Acc. no D/2850256 - only small withdrawals please) -} llam :: Float -> Int -> Int -> Command llam steplen topp bot = top steplen topp :# bottom steplen bot line :: Float -> Int -> Command line step n | n == 0 = Sit | otherwise = (Go step :# Branch (Turn 180 :#peanoC 3 intcol) :# GrabPen black :# Branch (peanoC 3 intcol :# GrabPen black):# line step (n-1)) where intcol = Colour ( 1 / (0.0001+(fromIntegral(mod (n+11) 15)))) (1 / (0.0001+(fromIntegral (mod (n + 6) 15)))) (1 / (0.0001+(fromIntegral (mod (n + 1) 15)))) top :: Float -> Int -> Command top step n = Turn (-150) :# line step n bottom :: Float -> Int -> Command bottom step n = line step n :# GrabPen Inkless :# Go (-1*step*(fromIntegral n)) :# GrabPen black :# Turn (-60) :# line step n llama :: Int -> Command llama x = Branch (f x) where f 0 = GrabPen red :# Go 5 f (x + 1) = Branch (p :# h x) :# Branch (n :# g x) :# h x :# g x g 0 = GrabPen green :# Go 5 g (x + 1) = Branch (p :# f x) :# Branch (n :# h x) :# f x :# h x h 0 = GrabPen blue :# Go 5 h (x + 1) = Branch (p :# g x) :# Branch (n :# f x) :# g x :# f x n = Turn 30 p = Turn (-30) grey, yellow, cyan, magenta,brown :: Pen grey = Colour 0.9 0.9 0.9 yellow = Colour 1 1 0 cyan = Colour 0 1 1 magenta = Colour 1 0 1 brown = Colour 0.5 0.25 0 comp :: Command comp = Branch (move :# peanoG 5) :# llam 50 12 8 where move = Turn 90 :# GrabPen Inkless :# Go 350 :# Turn (-90) peanoC :: Int -> Pen -> Command peanoC x col = f x where f 0 = GrabPen col :# Go 2 f (x + 1) = f x :# p :# g x :# p :# p :# g x :# n :# f x :# n :# n :# f x :# f x :# n :# g x :# p g 0 = GrabPen col :# Go 2 g (x + 1) = n :# f x :# p :# g x :# g x :# p :# p :# g x :# p :# f x :# n :# n :# f x :# n :# g x n = Turn 60 p = Turn (-60)