From 8e0cafeeba94abaa45a9868931d8a7c547bfa406 Mon Sep 17 00:00:00 2001 From: "joe.thornber" Date: Fri, 25 May 2007 05:27:32 +0200 Subject: [Spiral] blend in the scale factor so it doesn't have any effect on the smallest windows darcs-hash:20070525032732-db939-16aa2510a8dba52f8a7fdd466b78e3a9a0fba0e1.gz --- Spiral.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Spiral.hs') diff --git a/Spiral.hs b/Spiral.hs index 1f6547d..c17f2cd 100644 --- a/Spiral.hs +++ b/Spiral.hs @@ -24,20 +24,27 @@ mkRatios _ = [] data Direction = East | South | West | North deriving (Enum) +blend :: Rational -> [Rational] -> [Rational] +blend scale ratios = zipWith (+) ratios scaleFactors + where + len = length ratios + step = (scale - (1 % 1)) / (fromIntegral len) + scaleFactors = map (* step) . reverse . take len $ [0..] + spiral :: Rational -> Layout spiral scale = Layout { doLayout = fibLayout, modifyLayout = \m -> fmap resize $ fromMessage m } where fibLayout sc ws = return $ zip ws rects - where ratios = map (* scale) . reverse . take (length ws) . mkRatios $ fibs + where ratios = blend scale . reverse . take (length ws - 1) . mkRatios $ tail fibs rects = divideRects (zip ratios (cycle [East .. North])) sc resize Expand = spiral $ (21 % 20) * scale resize Shrink = spiral $ (20 % 21) * scale +-- This will produce one more rectangle than there are splits details divideRects :: [(Rational, Direction)] -> Rectangle -> [Rectangle] -divideRects [] _ = [] -divideRects [_] r = [r] +divideRects [] r = [r] divideRects ((r,d):xs) rect = case divideRect r d rect of (r1, r2) -> r1 : (divideRects xs r2) -- cgit v1.2.3