--Olympic Rings --Programming Competition Entry --Erik Mackie (s0816378) --To Run: type command "display olympicRings" into GHCI -------------------------------------------------------------------------------------------------------------------- import LSystem split :: Command -> [Command] split (p :#: Sit) = split p split (Sit :#: p) = split p split (p :#: q) = split p ++ split q split p = [p] join :: [Command] -> Command join [] = Sit join (x:[]) = x :#: Sit join (x:xs) = x :#: join xs copy :: Int -> Command -> Command copy x c = join (multiply x (split c)) where multiply 0 c = [] multiply x c = c ++ multiply (x-1) c circle :: Distance -> Command circle x = copy 360 (Go x :#: Turn 1) twocircles :: Distance -> Command twocircles x = GrabPen blue :#: circle x :#: Branch (GrabPen black :#: circle (-x) ) threecircles :: Distance -> Command threecircles x = twocircles x :#: Branch (Turn 90 :#: GrabPen yellow :#: circle x) where yellow = Colour 1 1 0 fivecircles :: Distance -> Command fivecircles x = threecircles x :#: Branch (GrabPen Inkless :#: Turn (-90) :#: Go ((360*x)/pi) :#: GrabPen green :#: circle (-x) :#: Turn (-90) :#: GrabPen red :#: circle (x)) olympicRings :: Command olympicRings = fivecircles 1