Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Informatics 1 - Functional Programming
- -- Tutorial 7
- --
- -- Week 9 - Due: 19/20 Nov.
- import LSystem
- import Test.QuickCheck
- -- Exercise 1
- -- 1a. split
- split :: Command -> [Command]
- split (Go x) = [Go x]
- split (Turn x) = [Turn x]
- split Sit = []
- split (ys :#: xs) = split ys ++ split xs
- -- 1b. join
- join :: [Command] -> Command
- join [x] = x :#: Sit
- join (x:xs) = x :#: (join xs)
- -- 1c equivalent
- equivalent :: Command -> Command -> Bool
- equivalent a b = (split a) == (split b)
- -- 1d. testing join and split
- prop_split_join :: Command -> Bool
- prop_split_join c = equivalent c (join (split c))
- prop_split :: Command -> Bool
- prop_split c = f (split c)
- f :: [Command] -> Bool
- f [] = True
- f (Go distance : xs) = f xs
- f (Turn angle : xs) = f xs
- f (Sit : xs) = False
- f ((x :#: y) : xs) = False
- -- Exercise 2
- -- 2a. copy
- copy :: Int -> Command -> Command
- copy 0 c = c
- copy n c = c :#: copy (n-1) c
- -- 2b. pentagon
- pentagon :: Distance -> Command
- pentagon x = copy 5 (Go x :#: Turn 72)
- -- 2c. polygon
- polygon :: Distance -> Int -> Command
- polygon distance sides = copy sides (Go distance :#: Turn (360.0/(fromIntegral sides)))
- pas :: Distance -> Angle -> Command
- pas distance angle = Go distance :#: Turn angle
- -- Exercise 3
- -- spiral
- spiral :: Distance -> Int -> Distance -> Angle -> Command
- spiral startDistance 0 increment angle = (pas startDistance angle)
- spiral startDistance n increment angle = (pas startDistance angle) :#: (spiral (startDistance + increment) (n-1) increment angle)
- -- Exercise 4
- -- optimise
- optimise :: Command -> Command
- optimise = undefined
- -- L-Systems
- -- 5. arrowhead
- arrowhead :: Int -> Command
- arrowhead = undefined
- -- 6. snowflake
- snowflake :: Int -> Command
- snowflake = undefined
- -- 7. hilbert
- hilbert :: Int -> Command
- hilbert = undefined
- main :: IO ()
- main = display (Go 30 :#: Turn 120 :#: Go 30 :#: Turn 120 :#: Go 30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement