-- Work by: 0674211 Greg Matthews and 0451339 Thomas Griffiths import LSystem --1. join join :: [Command] -> Command join xs = foldr1 (:#) xs --2. split split :: Command -> [Command] split (x :# y) = (split x) ++ (split y) split x = [x] --3. copy copy :: Int -> Command -> Command copy y x = join (replicate y x) -- hexagon hexagon :: Distance -> Command hexagon y = copy 6 (Go y :# Turn 60.0) -- pentagon pentagon :: Distance -> Command pentagon y = copy 5 (Go y :# Turn 72.0) --5. polygon polygon :: Distance -> Int -> Command polygon y x = copy x (Go y :# Turn ((fromIntegral 360) / (fromIntegral x))) --6. spiral spiral :: Distance -> Int -> Distance -> Angle -> Command spiral w x y z = join [ Go (w - (y*(fromIntegral(n)))) :# Turn z | n <- [0..x], w > ( y*(fromIntegral (n)))] --7. optimise optimiser :: Command -> [Command] optimiser (Sit) = [] optimiser (Go 0) = [] optimiser (Turn 0) = [] optimiser (Turn x) = [Turn x] optimiser (Go x) = [Go x] optimiser (Turn x :# Turn y) = [Turn (x+y)] optimiser (Go x :# Go y) = [Go (x+y)] optimiser (w :# x :# y :# z) = optimiser (w :# x) ++ optimiser (y :# z) optimiser (x :# y) = optimiser x ++ optimiser y optimise' :: Command -> Command optimise' x = join (optimiser (join (optimiser x))) checkOptimise :: Command -> Bool checkOptimise x = (optimise' x) == x optimise :: Command -> Command optimise x | checkOptimise x = x | not (checkOptimise x) = optimise (optimise' x) --8. arrowhead arrowhead :: Int -> Command arrowhead x = f x where f 0 = Go 10 f (x + 1) = g x :# n :# f x :# n :# g x g 0 = Go 10 g (x + 1) = f x :# p :# g x :# p :# f x n = Turn 60 p = Turn (-60) --9. snowflake snowflake :: Int -> Command snowflake x = optimise (f x :# p :# p :# f x :# p :# p :# f x :# p :# p) where f 0 = Go 10 f (x + 1) = f x :# n :# f x :# p :# p :# f x :# n :# f x n = Turn 60 p = Turn (-60) --10. peanoGosper :: Int -> Command peanoGosper x = f x where f 0 = Go 10 f (x + 1) = f x :# n :# g x :# n :# n :# g x :# p :# f x :# p :# p :# f x :# f x :# p :# g x :# n g 0 = Go 10 g (x + 1) = p :# f x :# n :# g x :# g x :# n :# n :# g x :# n :# f x :# p :# p :# f x :# p :# g x n = Turn 60 p = Turn (-60) -- Picture Competition - By Greg Matthews 0674211 sigma :: Command sigma = Turn 270:# Go 85 :# Turn 270 :# Go 15 :# Turn 270 :# Go 10 :# Turn 270 :# Go 5 :# Turn 90 :# Go 55 :# Turn 135 :# Go 25 :# Turn 270 :# Go 25 :# Turn 135 :# Go 55 :# Turn 90 :# Go 5 :# Turn 270 :# Go 10 :# Turn 270 :# Go 15 :# Turn 270 :# Go 85 :# Turn 270 :# Go 10 :# Turn 315 :# Go 25 :# Turn 90 :# Go 25 :# Turn 315 :# Go 10 sigman :: Command sigman = Turn 90 :# Go 30 :# Turn 90 :# Go 10 :# Turn 90 :# Go 30 :# Turn 270 :# Go 90 :# Turn 270 :# Go 10 :# Turn 270 :# Go 75 :# Turn 180 :# Go 160 :# Turn 270 :# Go 50 :# Turn 180 :# Go 50 :# Turn 270 :# Go 15 :# Turn 270 :# Go 25 :# Turn 270 :# Go 85 :# Turn 180 :# Go 85 :# Turn 270 :# Go 25 :# Turn 270 :# Go 175 :# Turn 180 :# Go 65 :# Turn 270 :# Go 10 :# Turn 180 :# Go 70 :# Turn 180 :# Go 60:# Turn 90 :# Go 10 :# Turn 270 :# Go 10 :# Turn 270 :# Go 90 :# Turn 270 :# Go 70 :# Turn 280 :# Go 160 :# Turn 260 :# Go 38 :# Turn 180 :# Go 38 :# Turn 100 :# Go 160 :# Turn 80 :# Go 70 :# Turn 80 :# Go 160 :# Turn 100 :# Go 38 :# Turn 180 :# Go 38 :# Turn 260 :# Go 160 :# Turn 280 :# Go 30 :# Turn 90 :# Go 10 :# Turn 90 :# Go 30 :# Turn 270 :# Go 10 :# Turn 315 :# Go 25 :# Turn 90 :# Go 25 :# Turn 315 :# Go 10 :# Turn 270 :# Go 70 :# Turn 270 :# Go 15 :# Turn 270 :# Go 10 :# Turn 270 :# Go 5 :# Turn 90 :# Go 45 :# Turn 135 :# Go 25 :# Turn 270 :# Go 25 :# Turn 135 :# Go 45 :# Turn 90 :# Go 5 :# Turn 270 :# Go 10 :# Turn 270 :# Go 15 :# Turn 270 :# Go 40