-- -- Copyright (c) 2005 Sean Seefried - http://www.cse.unsw.edu.au/~sseefried -- -- An image that looks just like the 2ser logo. -- 2ser is a radio station in Sydney broadcasting at 107.3 MHz -- module TwoSER where import Pan squareReg :: Frac -> Region squareReg side (Pt x y) = let s = side/2 in x > -s && x < s && y > -s && y < s -- -- Creates a region of circles. The circles are touching -- and layed out in a square pattern. -- -- e.g. *** -- * * -- *** -- n denotes the number of circles to a side. -- -- The top left-hand circle is a postive (True) region. The one next to -- it is a negative region. This pattern continues around the edge. -- twoSERReg :: Int -> Frac -> Region twoSERReg n r = posReg `diffR` negReg where s = (fromIntegral (n-1))*r -- (-s,-s) is the position of the centre of the top -- left circle posReg = foldr unionR emptyR posRegs `unionR` squareReg (2*s) negReg = foldr unionR emptyR negRegs (posRegs, negRegs) = alternateCircles centres centreVals = [-s, -s+2*r..s] centres = [ (Pt x y) | x <- centreVals, y <- centreVals] alternateCircles :: [Point] -> ([Region], [Region]) alternateCircles = alternateCircles' True True n alternateCircles' _ _ _ [] = ([], []) alternateCircles' lastRowBool posNeg 0 pts = alternateCircles' (not lastRowBool) (not lastRowBool) n pts alternateCircles' lastRowBool posNeg n (pt:pts) = let (posRegs, negRegs) = alternateCircles' lastRowBool (not posNeg) (n-1) pts newReg = circleRegAt r pt in if posNeg then (newReg:posRegs, negRegs) else (posRegs, newReg:negRegs) circleReg :: Frac -> Region circleReg r (Pt x y) = (x*x + y*y < r*r) -- -- Puts the circleReg at a particular point -- circleRegAt :: Frac -> Point -> Region circleRegAt r (Pt dx dy) = translate (Vec dx dy) (circleReg r) twoSER :: Int -> Frac -> ImageC twoSER n r = colourReg (twoSERReg n r) white blue effect :: UI DisplayFun effect = do n <- makeISlider "circles" (1,6) 1 imageToDisplayFun $ twoSER n 20 evens :: [a] -> [a] evens = everySnd True odds = everySnd False everySnd :: Bool -> [a] -> [a] everySnd _ [] = [] everySnd True (x:xs) = x:everySnd False xs everySnd False (x:xs) = everySnd True xs